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.

Page 2 of 2 FirstFirst 12
Results 26 to 34 of 34

Thread: Ugent pls help

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ugent pls help

    Is this what should be done next after the user's first input is read:
    compare user's input to the String: "t"
    If you don't understand my answer, don't ignore it, ask a question.

  2. #27
    Junior Member
    Join Date
    Mar 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ugent pls help

    Yes exactly. then if comparison is true then execute the nextstep.

  3. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ugent pls help

    Ok. Write the code for those three steps, compile it and test it.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #29
    Junior Member
    Join Date
    Mar 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ugent pls help

    i really don't know how to do that, i have completely lost it

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ugent pls help

    Try this: write an if statement to compare the contents of the String: userInput to the String: "yes" using the equals() method.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #31
    Junior Member
    Join Date
    Mar 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ugent pls help

    this is what i have now

    //
    import java.util.Scanner;
     
    public class courseWork {
    	static int no_starter,  no_mainCourse, no_desert, no_softDrink, no_coffee ;
       public static void main(String[] args) {
     
     
    	   String input,t = null ,f= null;
          Scanner stdio = new Scanner( System.in );
     
          double Total = 0; // Total value of all the orders.
     
          /* Ask the user for the number of each type of course. */
     
          System.out.println("Do you want to order starter? ");
          input = stdio.nextLine();
     
     
     
          if(input.equals( t)){
        	  System.out.print("Enter the number of starter:  ");
          no_starter = stdio.nextInt();
          stdio.nextLine();}
     
     
          System.out.println("Do you want to order main course?");
          input = stdio.nextLine();
    //
    and this is the out put, it skip without asking for the number of starter

    Do you want to order starter?
    t
    Do you want to order main course?

    --- Update ---

    //
     
    import java.util.Scanner;
     
    public class courseWork {
    	static int no_starter,  no_mainCourse, no_desert, no_softDrink, no_coffee ;
       public static void main(String[] args) {
     
     
    	   String input,t="t";
          Scanner stdio = new Scanner( System.in );
     
          double Total = 0; // Total value of all the orders.
     
          /* Ask the user for the number of each type of course. */
     
          System.out.println("Do you want to order starter? ");
          input = stdio.nextLine();
     
     
     
          if(input.equals( t)){
        	  System.out.print("Enter the number of starter:  ");
          no_starter = stdio.nextInt();
          stdio.nextLine();}
     
     
          System.out.println("Do you want to order main course?");
          input = stdio.nextLine();
     
          if(input.equals( t)){
          System.out.print("Enter the number of main course: ");
          no_mainCourse = stdio.nextInt();
          stdio.nextLine();
          }
     
          System.out.println("Do you want to order desert?");
          input = stdio.nextLine();
     
          if(input.equals( t)){
          System.out.print("Enter the number of desert: ");
          no_desert = stdio.nextInt();
          stdio.nextLine();
          }
     
          System.out.println("Do you want to order soft drink?");
          input = stdio.nextLine();
     
          if(input.equals( t)){
          System.out.print("Enter the number of soft drink: ");
          no_softDrink = stdio.nextInt();
          stdio.nextLine();
          }
     
          System.out.println("Do you want to order coffee? ");
          input = stdio.nextLine();
          if(input.equals( t)){
     
          System.out.print("Enter the number of coffee: ");
          no_coffee = stdio.nextInt();
          stdio.nextLine();
          }
          /* Add up the prices of the ordered courses. */
     
     
          double p_starter=(3*no_starter), p_mainCourse=(6*no_mainCourse), p_desert=(4*no_desert) , p_softDrink=(1.5*no_softDrink), p_coffee=(2*no_coffee);
     
           if(no_starter >= 1 && no_mainCourse >=1 || no_softDrink>=1){
        	  Total = p_starter + p_mainCourse;
          }
     
          else if(no_starter >= 1 && no_mainCourse >=1 && no_coffee >=1){
        	  Total = p_starter + p_mainCourse + p_coffee;
          }
     
          else if(no_starter >=1 && no_mainCourse >=1 && no_desert >=1 || no_softDrink >=1 || no_coffee >=1)
          {
        	  Total =  p_starter + p_mainCourse + p_desert;
          }
          else if(no_desert >= 1 && no_mainCourse >=1 || no_coffee>=1){
        	  Total = p_mainCourse + p_desert;
          }
          else if(no_mainCourse >= 1 && no_softDrink >= 1 && no_softDrink >= 1){
        	  Total =  p_mainCourse + p_softDrink + p_softDrink;
          }
     
          else if(no_softDrink >=1 && no_coffee >=1)
          {
        	  Total=   p_softDrink +  p_coffee;
          }
          else if(no_softDrink >=1 && no_coffee >=1 && no_desert >=1)
          {
        	  Total=   p_softDrink +  p_coffee + p_desert;
          }
          else if(no_softDrink >=1 && no_coffee >=1 && no_mainCourse >=1)
          {
        	  Total=   p_softDrink +  p_coffee + p_mainCourse;
          }
     
          else if(no_softDrink >=1 && no_coffee >=1 && no_starter >=1)
          {
        	  Total=   p_softDrink +  p_coffee + p_starter;
          }
     
          else{
        	  System.out.println("nothing has been ordered");
        	  Total = 0;
          }
     
          /* Report the result back to the user. */
     
          System.out.println("You have oedered " + no_starter + " Starter " + no_mainCourse + " main course " + no_desert + " desert " + no_softDrink + " soft drink" + no_coffee + " coffee ");
          System.out.println();
          System.out.print("The total ");
          System.out.print(Total);  // Formatted output!
          System.out.println();
     
       }  // end main()
     
    }  // end class
    //

    output

    Do you want to order starter?
    t
    Enter the number of starter: 1
    Do you want to order main course?
    t
    Enter the number of main course: 2
    Do you want to order desert?
    t
    Enter the number of desert: 1
    Do you want to order soft drink?
    t
    Enter the number of soft drink: 1
    Do you want to order coffee?
    t
    Enter the number of coffee: 1
    You have oedered 1 Starter 2 main course 1 desert 1 soft drink1 coffee

    The total 15.0

    now my problem is the if and else statements that satisfies this
    where customers order a main course – to provide, free of charge:
    • a soft drink if they also order a starter;
    • coffee if they also order a dessert;
    • both a soft drink and a coffee if all 3 courses are ordered.

  7. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ugent pls help

    now my problem is the if and else statements that satisfies this
    That looks like you need to work out some logic before trying to code it.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #33
    Junior Member
    Join Date
    Mar 2013
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ugent pls help

    String t="t"; is just so it reads that input as t, what do i expect i really dont understand, then the }s i have removed all of them and put them at the end,they still act same, now is only the if statements to check the condition.

    --- Update ---

    yeah but i would really need help with that logic, it seems to be my biggest problem here.

  9. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ugent pls help

    need help with that logic,
    There are tools and techniques for working on program logic.
    The one I learned was flowcharts. Using paper and pencil you draw a diagram that describes the logic for the program. Use a pencil so you can erase and rewrite parts the need to be changed as you work through the logic. It's an iterative process requiring many passes to get it right.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Help Pls..
    By shen_punkz21 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2013, 12:41 PM
  2. HI PLS HELP
    By Virat Pandey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 23rd, 2012, 06:12 AM
  3. pls.pls.pls.help with this
    By izzahmed in forum What's Wrong With My Code?
    Replies: 8
    Last Post: October 25th, 2011, 11:30 AM
  4. Pls help me
    By rose_brit3 in forum Loops & Control Statements
    Replies: 3
    Last Post: September 28th, 2010, 09:57 AM
  5. Pls Help
    By randika11 in forum JDBC & Databases
    Replies: 3
    Last Post: July 20th, 2010, 05:52 AM