import java.util.Scanner;
import java.io.*;
//This is program 3.
public class TroutBank {
public static void main(String[] args) throws IOException {
String clientname;
double initial;
double deposit;
double withdrawl;
double inquiry;
double keepcount = 0.0;
int choice;
String quit;
Scanner keyboard = new Scanner(System.in);
//Get the client's name.
System.out.println("Please enter your name");
clientname = keyboard.nextLine();
PrintWriter pw = new PrintWriter("" + clientname + ".txt");
File file = new File(clientname + ".txt");
Scanner inputFile = new Scanner(clientname);
//exising client
if (file.exists()) {
inquiry = inputFile.nextDouble();
System.out.println("Welcome back, " + clientname + ".");
System.out.println("Your current balance is $" + inquiry + ".");
do {
System.out.println("1 - Deposit");
System.out.println("2 - Withdrawal");
System.out.println("3 - Balance Inquiry");
System.out.println("4 - Quit");
System.out.println("Please enter the number for the type of transaction you would like to make");
choice = keyboard.nextInt();
if (choice == 1) {
System.out.println("Please enter the amount you would like to deposit. Do not use $ or commas.");
deposit = keyboard.nextDouble();
inquiry = inquiry + deposit;
System.out.println("Transaction complete.");
} else if (choice == 2) {
System.out.println("Please enter the amount you would like to withdrawal. Do not use $ or commas.");
withdrawl = keyboard.nextDouble();
if (withdrawl > inquiry) {
System.out.println("Error. Withdrawal is greater than current balance.");
} else {
inquiry = inquiry - withdrawl;
System.out.println("Transaction complete.");
}
} else if (choice == 3) {
System.out.println("Your current balance is $" + inquiry + ".");
} else if (choice == 4) {
System.out.println("Thank you for banking with Trout Bank. We appreciate your business.");
} else {
System.out.println("Error. Please pick one of the numbers shown above.");
}
} while (choice > 0 && choice < 4);
} //not existing
else {
System.out.println("Welcome to Trout Bank. We would love to make a new account for you.");
System.out.println("Please enter the amount of your initial deposit. Do not use $ or commas.");
inquiry = keyboard.nextDouble();
pw.println(inquiry);
System.out.println("Your initial balance is $" + inquiry + ".");
do {
System.out.println("1 - Deposit");
System.out.println("2 - Withdrawal");
System.out.println("3 - Balance Inquiry");
System.out.println("4 - Quit");
System.out.println("Please enter the number for the type of transaction you would like to make");
choice = keyboard.nextInt();
if (choice == 1) {
System.out.println("Please enter the amount you would like to deposit. Do not use $ or commas.");
deposit = keyboard.nextDouble();
inquiry = inquiry + deposit;
System.out.println("Transaction complete.");
} else if (choice == 2) {
System.out.println("Please enter the amount you would like to withdrawal. Do not use $ or commas.");
withdrawl = keyboard.nextDouble();
if (withdrawl > inquiry) {
System.out.println("Error. Withdrawal is greater than current balance.");
} else {
inquiry = inquiry - withdrawl;
System.out.println("Transaction complete.");
}
} else if (choice == 3) {
System.out.println("Your current balance is $" + inquiry + ".");
} else if (choice == 4) {
System.out.println("Thank you for banking with Trout Bank. We appreciate your business.");
} else {
System.out.println("Error. Please pick one of the numbers shown above.");
}
} while (choice > 0 && choice < 4);
}
//Write the inquiry to the file.
pw.println(inquiry);
//close the file
inputFile.close();
pw.close();
}
}