Hello everyone and thanks in advance for helping me.
I'm a 1st year java student in my first semester of college. Its comming towards the end of the semester and finals are starting up.. well my problem is that my java teacher decided to give us 2 projects to work on both of which im not experienced enough to work on with the time he's given us...
The first project is to fix another programmers code... (How am i suppose to do that i wondered i can barely do my own xD)
It must:
* Be broken into methods
* Have error checking with try and catch
* use a switch statement
* prevent the user from withdraing more money than he has
* use a do while loop or a while() loop
* and must run in a gui environment no systemoutprintln[/LIST]
import javax.swing.JOptionPane;
class MiniLab5
{
public static void main (String[] args)
{
double balance = 0;
double newBalance = 0;
double adjustment = 0;
String response;
String moreBankingBusiness;
moreBankingBusiness = JOptionPane.showInputDialog
( "Do you want to do some banking?" );
moreBankingBusiness = moreBankingBusiness.toUpperCase();
while (moreBankingBusiness.equals ("YES"))
{
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
//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
When he gave us the handout for this paper i thought to myself "What..." so if someone could please help me through this it would be a huge load off my shoulders while i study for finals and do the other project.