public class StringConditionals
1: import java.util.Scanner;
3: /**
4: * A simple order-taking app to demonstrate the "if" control
5: *
6: * @author Mark Young
7: * @version 1.1 2014-09-08
8: */
9: public class StringConditionals {
11: /**
12: * Run this program.
13: *
14: * @param args command lines arguments (ignored)
15: */
16: public static void main(String[] args) {
17: // create variables
18: Scanner kbd = new Scanner(System.in);
19: String answer;
20: double amount = 0.00;
22: // welcome customer
23: System.out.print("\n\n"
24: + "Welcome to GreesieBurger!\n"
25: + "-------------------------\n\n");
26:
27: // ask for sandwich order
28: System.out.print("What sandwich would you like? ");
29: answer = kbd.nextLine();
30: System.out.println(answer.toUpperCase() + "!");
31: System.out.println("(" + answer.toLowerCase() + ")");
32: amount += 8.95;
34: // ask if want fries
35: System.out.print("Would you like fries with that? ");
36: answer = kbd.next();
37: kbd.nextLine();
38: if (answer.startsWith("y")) {
39: System.out.println("FRIES!");
40: System.out.println("(fries)");
41: amount += 1.99;
42: }
44: // ask for drink order
45: System.out.print("What can I get you to drink? ");
46: answer = kbd.nextLine();
47: System.out.println(answer.toUpperCase() + "!");
48: System.out.println("(" + answer.toLowerCase() + ")");
49: amount += 0.99;
51: // report back total amount owed
52: System.out.print("\n"
53: + "That'll be $" + amount + ".\n\n");
54: System.out.println("Thank-you for eating at GreesieBurgers!\n");
55: }
56: }