Is this what should be done next after the user's first input is read:
compare user's input to the String: "t"
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.
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.
Yes exactly. then if comparison is true then execute the nextstep.
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.
i really don't know how to do that, i have completely lost it
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.
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.
That looks like you need to work out some logic before trying to code it.now my problem is the if and else statements that satisfies this
If you don't understand my answer, don't ignore it, ask a question.
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.
There are tools and techniques for working on program logic.need help with that 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.