Using while loop in Java?
Hi,
I am new to the Java language and I'm still clueless on some stuff. I guess I'll be around this website for some time.
I'm writing my very first program in Java.
I did a while loop with some if statements within. My loop has four different options. Every option does something different, and option 4 is designed to end the program.
The problem is that I don't know how to make the loop repeat itself until I decide to end it (by choosing option #4)?
Since I put 4 different while(s) loops, and so the programs shuts itself after I input four different options. (independently of what options I punch in)
This is my code.
import java.util.Scanner; //Needed for Scanner class
public class proyectoquefunciona
{
public static void main(String[] args)
{
String cname, caddress, cemail;
int option1, option2, option3, option4;
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to THE STORE");
System.out.println("Please Select One of Following");
System.out.println(" 1. Enter customer information \n 2. Price Lookup \n 3. Display Total Bill \n 4. Quit");
option1 = keyboard.nextInt();
{
while (option1 != 0)
{
if (option1 ==1)
{ System.out.println("Good job you're in part (1)");}
if (option1 ==2)
{System.out.println("Good job you're in part 1.2");}
if (option1 ==3)
{System.out.println("Good job you're in part 1.3"); }
if (option1==4)
{System.exit(0);}
break;
}}
System.out.println("Please Select One of Following");
System.out.println(" 1. Enter customer information \n 2. Price Lookup \n 3. Display Total Bill \n 4. Quit");
option2 = keyboard.nextInt();
{
while (option2 !=1 || option2 != 2 || option2 !=3 || option2 !=4)
{ if (option2 ==1)
{
System.out.println("Good job you're in part (2)");}
if (option2 ==2)
{System.out.println("Good job you're in part 2.2"); }
if (option2 ==3)
{System.out.println("Good job you're in part "); }
if (option2==4)
{System.exit(0);}
break; }}
System.out.println("Please Select One of Following");
System.out.println(" 1. Enter customer information \n 2. Price Lookup \n 3. Display Total Bill \n 4. Quit");
option3 = keyboard.nextInt();
{
while (option3 !=1 || option3 != 2 || option3 !=3 || option3 !=4)
{ if (option3 ==1)
{
System.out.println("Good job you're in part (33)");}
if (option3 ==2)
{System.out.println("Good job you're in part 33.2"); }
if (option3 ==3)
{System.out.println("Good job you're in part 33.3"); }
if (option3==4)
{System.exit(0);}
break; }}
System.out.println("Please Select One of Following");
System.out.println(" 1. Enter customer information \n 2. Price Lookup \n 3. Display Total Bill \n 4. Quit");
option4 = keyboard.nextInt();
{
while (option4 !=1 || option4 != 2 || option4 !=3 || option4 !=4)
{ if (option2 ==1)
{
System.out.println("Good job you're in part (44)");}
if (option4 ==2)
{System.out.println("Good job you're in part 44.2"); }
if (option4 ==3)
{System.out.println("Good job you're in part 44.3"); }
if (option4==4)
{System.exit(0);}
break; }}
}
}