Name: Anonymous 2013-02-18 14:52
Hey /prog/, I'm new and trying to write a program in java. I ask the user for input and then depending on the number they give me, I do an operation. Then I ask for a new number. 4 is the number to quit. Here's the relevant part of my code. It compiles, but doesn't work correctly.
System.out.println("Press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
while(order!=4)
{
if(order==1)
{
double amount;
System.out.println("How much would you like to deposit?");
amount = scan.nextDouble();
acc1.deposit(amount);
acc1.display();
}
if(order==2)
{
double check;
System.out.println("How much would you like to withdraw?");
check = scan.nextDouble();
acc1.check(check);
acc1.display();
}
if(order==3)
{
acc1.display();
}
while(order!=4)
{
System.out.println("Please press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
}
System.out.println("Press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
}
System.out.println("Thank you for using our services.");
System.out.println("Press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
while(order!=4)
{
if(order==1)
{
double amount;
System.out.println("How much would you like to deposit?");
amount = scan.nextDouble();
acc1.deposit(amount);
acc1.display();
}
if(order==2)
{
double check;
System.out.println("How much would you like to withdraw?");
check = scan.nextDouble();
acc1.check(check);
acc1.display();
}
if(order==3)
{
acc1.display();
}
while(order!=4)
{
System.out.println("Please press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
}
System.out.println("Press 1 to make a deposit, 2 to make a withdrawal, 3 to check your balance, or 4 to quit.");
order = scan.nextInt();
}
System.out.println("Thank you for using our services.");