New to the forum and with a question!!
Just dropping by to say hello. I am taking a Java class this semester and may be needing help as I am a newb when it comes to Java.
My professor gave an assignment to create a banking program and i'm running into trouble. The program is basically to prompt the user to enter an option to either deposit, withdraw, view balance or terminate the session. I have to use a switch statement in the while loop. The customer class is where all the calculations take place. Here is what I have so far.
import java.io.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
class Customer
{
//attributes
String customerName;
int customerAcct;
double accountBalance, totalDeposits, totalWithdrawals;
//methods
void processDeposit(double depositAmount)
{
accountBalance += depositAmount;
totalDeposits +=depositAmount;
}
boolean processWithdrawal(double withdrawalAmount)
{
if (withdrawalAmount <= accountBalance)
{
accountBalance -= withdrawalAmount;
totalWithdrawals += withdrawalAmount;
return true;
}
else
{
String errorMessage = "Insufficient Funds!! ";
errorMessage += "Your current balance is " + accountBalance;
JOptionPane.showMessageDialog(null, errorMessage, "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
}
//constructor
Customer()
{
customerName = JOptionPane.showInputDialog("Please enter the Customer's name");
customerAcct = Integer.parseInt(JOptionPane.showInputDialog("Plea se enter the Customer's Account Number"));
accountBalance = Double.parseDouble(JOptionPane.showInputDialog("Pl ease enter the starting balance"));
totalDeposits= 0;
totalWithdrawals=0;
}
}
public class Banking
{
public Banking() {
public static void main(String[] args) {
//Housekeeping
int depCount = 0, withdrawalCount = 0, choices;
double startingBalance = 0, deposit = 0, withdrawal = 0;
boolean validWithdrawal = true;
DecimalFormat twoDigits = new DecimalFormat("0.00");
//Processing
Customer cust = new Customer(); //Instantiate customer object
startingBalance = cust.accountBalance; //populates the starting balance field with accountBalance from customer class
choices = Integer.parseInt(JOptionPane.showInputDialog("Menu :\nEnter 1 - For Deposit\nEnter 2 - For Withdrawal\nEnter3 - For Balance\nEnter 9 - To Terminate\n"));
while (choices != 9)
{
switch(choices)
{
case 1:
deposit = Double.parseDouble(JOptionPane.showInputDialog("Pl ease enter a deposit amount."));
cust.processDeposit(deposit);
break;
case 2:
withdrawal = Double.parseDouble(JOptionPane.showInputDialog("Pl ease enter a withdrawal."));
cust.validWithdrawal(withdrawal);
break;
case 3:
JOptionPane.showMessageDialog("Your remaining balance is:" + cust.accountBalance);
break;
default:
JOptionPane.showMessageDialog(null,output,"not valid choice",JOptionPane.INFORMATION_MESSAGE);
}
}
String output = "Customer Name : " + cust.customerName + "\n";
output += "Customer Account # : " + cust.customerAcct + "\n";
output += "Starting Balance : " + twoDigits.format(startingBalance) + "\n\n";
output += "Total Deposit : " + twoDigits.format(cust.totalDeposits) + "\n";
output += "Total Withdrawal : " + twoDigits.format(cust.totalWithdrawals) + "\n\n";
output += "Closing Balance : " + twoDigits.format(cust.accountBalance) + "\n";
JOptionPane.showMessageDialog(null, output, "Transaction Summary", JOptionPane.INFORMATION_MESSAGE);
//System.exit(0);
}
}
}
It still seems to not work.....any help would be appreciated. Thanks!