View Single Post
  #2 (permalink)  
Old 08-15-2007, 10:13 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,141
hardwired is on a distinguished road
The main method does not go inside any other method or constructor.
It stands by itself as a method inside a class body, viz, the curley braces {}.
Compile errors:
Code:
C:\jexp>javac bankingrx.java bankingrx.java:46: cannot find symbol symbol : method validWithdrawal(double) location: class CustomerRx cust.validWithdrawal(withdrawal); ^ bankingrx.java:49: cannot find symbol symbol : method showMessageDialog(java.lang.String) location: class javax.swing.JOptionPane JOptionPane.showMessageDialog("Your remaining balance is:" + ^ bankingrx.java:53: cannot find symbol symbol : variable output location: class BankingRx JOptionPane.showMessageDialog(null,output,"not valid choice" , ^ 3 errors
Comments in code below show how these were fixed.
I changed the names of the classes so you can run this as–is.
Code:
import java.io.*; import javax.swing.JOptionPane; import java.text.DecimalFormat; public class BankingRx { public BankingRx() {} 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 CustomerRx cust = new CustomerRx(); //Instantiate customer object // populates the starting balance field with // accountBalance from customer class startingBalance = cust.accountBalance; do { choices = Integer.parseInt( JOptionPane.showInputDialog("Menu :\n" + "Enter 1 - For Deposit\n" + "Enter 2 - For Withdrawal\n" + "Enter3 - For Balance\n" + "Enter 9 - To Terminate\n")); 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.")); // CustomerRx class does not have this method. // cust.validWithdrawal(withdrawal); break; case 3: // JOptionPane class does not have a method that takes // these type of arguments. // JOptionPane.showMessageDialog("Your remaining balance is:" + // cust.accountBalance); // Try this JOptionPane.showMessageDialog(null,"Your remaining balance " + "is:" + cust.accountBalance); break; default: // Variable "output" has not been declared. String output = "hello world"; 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); } while (choices != 9); } } class CustomerRx { // member variables in class scope String customerName; int customerAcct; double accountBalance, totalDeposits, totalWithdrawals; //constructor CustomerRx() { 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; } //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; } } }
Reply With Quote