Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with last part of code!

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with last part of code!

    //My question is how can I make the program repeat until the user enters the number 4 to exit?


     
     
    /**
     * Write an application for a furniture company; the program determines the price of a  
    table. Ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany. The output is  
    the name of the wood chosen as well as the price of the table. Pine table cost $100,  
    oak tables cost $225, and mahogany table cost $310. Also ask the user to specify a  
    (1) large table or a (2) small table. Add $35 to the price of any large table and add  
    nothing to the price for a small table. Display the output. Your program must repeat  
    until the user chooses to exit.
     */
    import java.util.Scanner;
    public class Wood {
     public static void main(String[] args) {
    Scanner input = new Scanner (System.in);
     System.out.println ("Table Prices");
       System.out.println ("Choose 1 for Pine");
        System.out.println ("Choose 2 for Oak");
         System.out.println ("Choose 3 for Mahogany");
          System.out.println ("Choose 4 to Exit");
          int userNumber = input.nextInt();
     
          System.out.println ("Enter 5: Small table or Enter 6: Large table");
            int tableNumber = input.nextInt();
     
            if ( userNumber == 1  && tableNumber == 5) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Pine");
              System.out.println ("Size: Small");
              System.out.println ("Price: $100");
            }
     
            if ( userNumber == 1  && tableNumber == 6) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Pine");
              System.out.println ("Size: Large");
              System.out.println ("Price: $135");
            }
     
            if ( userNumber == 2  && tableNumber == 5) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Oak");
              System.out.println ("Size: Small");
              System.out.println ("Price: $225");
            }
     
             if ( userNumber == 2  && tableNumber == 6) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Oak");
              System.out.println ("Size: Large");
              System.out.println ("Price: $260");
            }
     
              if ( userNumber == 3  && tableNumber == 5) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Mahogany");
              System.out.println ("Size: Small");
              System.out.println ("Price: $310");
            }
     
               if ( userNumber == 2  && tableNumber == 6) {
              System.out.println ("You selected the following table:");
              System.out.println ("Wood: Mahogany");
              System.out.println ("Size: Large");
              System.out.println ("Price: $345");
            }
     
     
     
     
     
     
     
     
     
     
     
     
     }
     
    }


  2. #2
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: Help with last part of code!

    HI,

    You just use the do..while loop is enough.
    do{
    //your menus
    //getting inputs
    //Display statements
    }while(condition);

    Thanks,

  3. The Following User Says Thank You to Ganeprog For This Useful Post:

    GregBrannon (February 19th, 2014)

Similar Threads

  1. Need help on decoding what this part of the code does
    By aude922000 in forum Java Theory & Questions
    Replies: 3
    Last Post: December 13th, 2013, 07:07 AM
  2. What is wrong in My code. Going to Else part..Can you please suggest me.
    By Umasri in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 4th, 2013, 09:53 AM
  3. Replies: 9
    Last Post: October 4th, 2013, 09:53 AM
  4. What does this part of the code mean?
    By jean28 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 23rd, 2012, 11:47 PM
  5. What does this short part of a code do?
    By Kranti1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 28th, 2012, 11:31 AM