Skip to content

Instantly share code, notes, and snippets.

@dante-byte
Created April 15, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dante-byte/e061d84511a862816a7d5975aa2655da to your computer and use it in GitHub Desktop.
Save dante-byte/e061d84511a862816a7d5975aa2655da to your computer and use it in GitHub Desktop.
package tiy.banking;
public class Bank {
public String bankName;
public double totalMoneyAtTheBank;
public BankAccount[] bankAcctList = new BankAccount[3];
public void addBankAccount(BankAccount bankAcctToAdd, int bankAcctIndex) {
System.out.println("OMG - I'm adding a bank account");
bankAcctList[bankAcctIndex] = bankAcctToAdd;
totalMoneyAtTheBank = totalMoneyAtTheBank + bankAcctToAdd.getBalance();
}
public void printInfo() {
System.out.println("===========================");
System.out.println("Name: " + bankName);
System.out.println("Total money in this bank: " + totalMoneyAtTheBank);
System.out.println("===========================");
}
}
package tiy.banking;
public class BankAccount {
public String name;
public double balance;
public double getBalance() {
return balance;
}
public void printInfo() {
System.out.println("=============================");
System.out.println("Account name: " + name);
System.out.println("Account balance: " + balance);
System.out.println("=============================");
}
public void deposit(double amountToDeposit, boolean justKidding) {
if (justKidding == true ) {
System.out.println("not depositing any money for jokers ");
} else {
balance = balance + amountToDeposit;
}
}
public void withdraw(double amountToWithDraw) {
if (amountToWithDraw > balance) {
System.out.println(" funds not availible");
} else {
System.out.println("but yyou about to be broke " + amountToWithDraw);
System.out.println("but you also the boss, so here you go ");
balance = balance - amountToWithDraw;
}
}
}
package tiy.banking;
import java.util.Scanner;
public class Day9Runner {
static Bank myBank = new Bank();
public static void test() {
BankAccount testBankAccount = new BankAccount();
testBankAccount.printInfo();
double currentBalance = testBankAccount.getBalance();
double lotsOfMoney = 2000.00;
testBankAccount.deposit(lotsOfMoney, false);
currentBalance = testBankAccount.getBalance();
System.out.println("The variable name currenntBalance has this value in: " + currentBalance);
double sadFace = 1278.28;
testBankAccount.withdraw(sadFace);
System.out.println(testBankAccount.getBalance());
Bank testBank = new Bank();
testBank.printInfo();
testBank.addBankAccount(testBankAccount, 0);
testBank.printInfo();
BankAccount anotherTestAccount = new BankAccount();
anotherTestAccount.deposit(100.00, false);
testBank.addBankAccount(anotherTestAccount, 1);
testBank.printInfo();
}
public static void playWithArrays() {
System.out.println("Starting to play with arrays.....");
String[] myTestArray = new String[5];
myTestArray[3] = "something";
myTestArray[0] = "Waldo";
myTestArray[2] = "popyeye";
myTestArray[4] = "whatev";
myTestArray[1] = "penny";
System.out.println("Manuel Array Print");
System.out.println(myTestArray[0]);
System.out.println(myTestArray[1]);
System.out.println(myTestArray[2]);
System.out.println(myTestArray[3]);
System.out.println(myTestArray[4]);
for (int i = 0; i < myTestArray.length; i ++) {
myTestArray[i] = " something " + i;
System.out.println(myTestArray[i]);
if (i > 2) {
break;
}
//System.out.println("here is what the index is at the moment: " + i);
}
}
public static void getUserInputInloop() {
System.out.println("Finally - getting user input");
for (int ifrun = 0; ifrun < 3; ifrun++) {
getUserInput(ifrun);
}
}
public static void getUserInput(int acctNum) {
System.out.println("Getting user input");
Scanner myScanner = new Scanner(System.in);
System.out.println("What is the name of your current account #" + (acctNum+1) + "?");
String currentAccountName = myScanner.nextLine();
BankAccount currentAccount = new BankAccount();
currentAccount.name = currentAccountName;
myBank.addBankAccount(currentAccount, acctNum);
myBank.printInfo();
System.out.println("Thank you - creating " + currentAccountName + " for you");
}
public static void askUserQuestions() {
FileTester.saveAccounts(myBank.bankAcctList);
while (true) {
System.out.println("What account wouuld you like to use?");
for (int acctIndex = 0; acctIndex < myBank.bankAcctList.length;
acctIndex++) {
System.out.println(acctIndex + " - " + myBank.bankAcctList[acctIndex].name);
}
Scanner accountChoiceScanner = new Scanner(System.in);
String accountChoice = accountChoiceScanner.nextLine();
int acctIndex = Integer.parseInt(accountChoice);
BankAccount chosenAccount = myBank.bankAcctList[acctIndex];
System.out.println("You have chosen your " + chosenAccount.name + "account");
while (true) {
System.out.println("What would you like to do?");
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Print Account Information");
System.out.println("4. Print Bank Information");
System.out.println("x. Exit");
Scanner questionScanner = new Scanner(System.in);
String userAnswer = questionScanner.nextLine();
System.out.println("userAnswer = " + userAnswer);
if (userAnswer.equals("1")) {
System.out.println("Deposit money");
System.out.println("How Much?");
String howMuchStr = questionScanner.nextLine();
}
if (userAnswer.equals("2")) {
System.out.println("Withdraw"); }
if (userAnswer.equals("3")) {
System.out.println("Print Account Information"); }
if (userAnswer.equals("4")) {
System.out.println("Print Bank Information");
if (userAnswer.equals("x")) {
System.out.println("Exit"); }
}
}
}
}
public static void main(String[] cmdLineArgs) {
System.out.println("Banking system about to start ...");
//playWithArrays();
getUserInputInloop();
askUserQuestions();
//test();
}
}
package tiy.banking;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
/**
* Created by Donta White on 4/14/2016.
*/
public class FileTester {
public static void main(String[] args) {
System.out.println("file tester handling");
//testWrite();
//testRead();
}
public static void testRead(){
try {
System.out.println("Reading File...");
File testFile =new File("test.txt");
Scanner fileScanner = new Scanner(testFile);
while (fileScanner.hasNext()) {
String currentLine = fileScanner.nextLine();
System.out.println(currentLine);
}
// String firstLine = fileScanner.nextLine();
// String secondLine = fileScanner.nextLine();
// String thirdLine = fileScanner.nextLine();
// System.out.println(firstLine);
// System.out.println(secondLine);
// System.out.println(thirdLine);
} catch (Exception exception){
System.out.println("unable to read file");
}
}
public static void saveAccounts(BankAccount[] acctList) {
try {
File accountFile = new File("account.txt");
FileWriter saveAccounts = new FileWriter(accountFile);
for (int i = 0; i < acctList.length; i++) {
saveAccounts.write(acctList[i].name + "\n");
}
//saveAccounts.write();
saveAccounts.close();
} catch (Exception exception) {
System.out.println("");
}
}
public static void testWrite(){
try {
System.out.println("Trying to write a file");
File testFile = new File("test.txt");
FileWriter testWriter = new FileWriter(testFile);
testWriter.write("bankName=United Bank of Atlanta\n");
testWriter.write("directorName=John Henry\n");
testWriter.close();
}catch(Exception exception){
System.out.println("unable to write file");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment