Jump to content

Java help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
mb52

mb52

    Newbie

  • Members
  • Pip
  • 2 posts
I needed some help with this the pseudo code was in python and we need to do it in Java.


Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->1
Enter the number of burgers you want 3
Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->3
Enter the number of sodas you want 2
Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->1
Enter the number of burgers you want 1
Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->2
Enter the number of fries you want 2
Do you want to end your order? (Enter yes or no): yes

The total price is $ 8.1832
Do you want to end program? (Enter no to process a new order): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->2
Enter the number of fries you want 2
Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now ->3
Enter the number of sodas you want 2
Do you want to end your order? (Enter yes or no): yes

The total price is $ 3.9856
Do you want to end program? (Enter no to process a new order): yes

#2
farrell2k

farrell2k

    Learning Programmer

  • Members
  • PipPipPip
  • 60 posts
I won't do the code for you, but I can point you in the right direction.

Use a while loop, prompting if users want to continue. The Scanner class with a system.in stream can be used for console input.

#3
mb52

mb52

    Newbie

  • Members
  • Pip
  • 2 posts
Thank you, would you be able to show me an example of the loop statement?

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
String input;

Boolean again = true;

Scanner scanner = new Scanner(System.in);


while(again){

 ...

 ...

 ...

while( !input.equals("true") || !input.equals("no") ) {

   System.out.println("Do you want to go again?");

   input= scanner.nextLine();

}


again = input.equals("true");

}