Hey this is my first time posting on here. Brand new to Java and i can't get it to complile correctly. The point of this program is to do banking for the user whom is using the program. We were giving code to fix and correct. These are the things that must be in the program...
Must List:
1. break the program up into method
2. do error detection and correction - try..catch
3. use a switch statement instead of if() statements
4. prevent user from withdrawing more money that he has
5. Must work correctly
6. Must use a do.. while or a while() loop
7. Must run in a GUI environment, i.e., can't use System.out.println() statements on final version.
8. Must make the prompts easier for the user to continue
import javax.swing.*; import javax.swing.JOptionPane; public class MiniLab5 { static double balance = 0; static double newBalance = 0; static double adjustment = 0; String response; String moreBankingBusiness; public static void main (String[] args) { public static void runIt() { moreBankingBusiness = JOptionPane.showInputDialog ( "Do you want to do some banking?" ); moreBankingBusiness = moreBankingBusiness.toUpperCase(); openingMessage(); } // runIt public static int openingMessage() { String openingMessage = ""; openingMessage = "***WELCOME TO SMILEY NATIONAL BANK*** \n\n" // change my Message to + "Atm may charge a surcharge fee \n \n"; JTextArea outputArea = new JTextArea(5,10); // create an Instance of a JTextArea - in this case the variable name is outputArea outputArea.setText ( openingMessage ); // put the Text String into the outputArea JOptionPane.showMessageDialog ( null, outputArea, // Display the Message "Smiley National Bank", // Create a suitable Title for the Window JOptionPane.INFORMATION_MESSAGE ); while (moreBankingBusiness.equals ("YES")) { int response; response = JOptionPane.showInputDialog ( "What would you like to do? (1=Deposit, 2=Withdraw, 3=Get Balance)"); if (response == null) { JOptionPane.showMessageDialog (null, "You clicked on the Cancel button"); System.exit (0); } // if else if (response.equals("")) { JOptionPane.showMessageDialog (null, "You must make an entry in the InputBox"); System.exit (0); } // else if else if (Integer.parseInt(response) < 1 | Integer.parseInt(response) > 3) { JOptionPane.showMessageDialog (null, response + " - is not a valid student type"); System.exit (0); } // else if }// openingMessage //1 is a Deposit if (Integer.parseInt(response) == 1) { adjustment = Double.parseDouble (JOptionPane.showInputDialog( "Enter the Deposit Amount" )); newBalance = balance + adjustment; JOptionPane.showMessageDialog (null, "*** SMILEY NATIONAL BANK ***\n\n" + "Old Balance is: " + balance + "\n" + "Adjustment is: +" + adjustment + "\n" + "New Balance is: " + newBalance + "\n"); } // if //2 is a Withdrawal if (Integer.parseInt(response) == 2) { adjustment = Double.parseDouble (JOptionPane.showInputDialog( "Enter the Withdrawal Amount" )); newBalance = balance - adjustment; JOptionPane.showMessageDialog (null, "*** SMILEY NATIONAL BANK ***\n\n" + "Old Balance is: " + balance + "\n" + "Adjustment is: -" + adjustment + "\n" + "New Balance is: " + newBalance + "\n"); } // if // 3 is a balance inquiry if (Integer.parseInt(response) == 3) { JOptionPane.showMessageDialog (null, "*** SMILEY NATIONAL BANK ***\n\n" + "Your Current Balance Balance is: " + balance ); }// if balance = newBalance; moreBankingBusiness = JOptionPane.showInputDialog ( "Do you have more banking business?" ); moreBankingBusiness = moreBankingBusiness.toUpperCase(); } // end of while JOptionPane.showMessageDialog(null, "Thanks for banking with us!"); System.exit (0); } // end of main } // end of class
Any Help is greatly appriciated.
P.S. I realize it doesn't compile....my code should indicate im a noob.