Created
February 11, 2019 20:06
-
-
Save SGTMcClain/5be2cc48e485632264c8d52a1fc51d52 to your computer and use it in GitHub Desktop.
Unity Banking Procedure with I/O
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text; | |
using UnityEngine; | |
public class BankingProcedure_Extra : MonoBehaviour { | |
// setup global variables | |
public double initialDeposit = 5000; | |
public double rateBankA = .04; | |
public double yearsBankA = 3; | |
public double yearsBankB = 4; | |
public double rateBankB = .03; | |
// Use this for initialization | |
void Start () { | |
// setup start scope variables | |
StringBuilder outputString = new StringBuilder(); | |
StreamWriter fileIO = new StreamWriter("Files/BankingOutput.txt"); | |
double finalValue1 = initialDeposit * Math.Pow((1 + rateBankA), yearsBankA); | |
double differenceInValue; | |
// setup string for Bank A | |
string text = "BankA " + yearsBankA + "-year CD of $" + initialDeposit + " at " + rateBankA * 100 + "% rate is worth $" + Math.Round(finalValue1, 2); | |
// output to console | |
Debug.Log(text); | |
// add to string builder and make sure new text goes to next line | |
// (Could also just add to the streamwriter here as another option) | |
outputString.AppendLine(text); | |
// demonstration of declaring a variable close to where it will be used | |
double finalValue2 = initialDeposit * Math.Pow((1 + rateBankB), yearsBankB); | |
// since text was stored in the stringbuilder this can be overwritten with new data here | |
text = "BankB " + yearsBankB + "-year CD of $" + initialDeposit + " at " + rateBankB * 100 + "% rate is worth $" + Math.Round(finalValue2, 2); | |
// add text to stringbuilder | |
outputString.AppendLine(text); | |
// output to console | |
Debug.Log(text); | |
//Find the difference | |
differenceInValue = finalValue2 - finalValue1; | |
if (differenceInValue > 0) | |
{ | |
text = "Bank B's CD exceeds Bank A's CD by $" + Math.Round((differenceInValue), 2); | |
outputString.Append(text); | |
Debug.Log(text); | |
} | |
else if (differenceInValue < 0) | |
{ | |
differenceInValue = finalValue1 - finalValue2; | |
text = "Bank A's CD exceeds Bank B's CD by $" + Math.Round((differenceInValue), 2); | |
outputString.Append(text); | |
Debug.Log(text); | |
} | |
else | |
{ | |
text = "There is no difference between Bank A's and Bank B's CD's"; | |
outputString.Append(text); | |
Debug.Log(text); | |
} | |
// write the entire string from the stringbuilder to the streamwriter | |
fileIO.Write(outputString); | |
// close the streamwriter | |
fileIO.Flush(); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment