public class GradesSuite
2: import java.util.Scanner;
4: /**
5: * A collection of conditionals on a course grade theme
6: *
7: * @author Mark Young (A00000000)
8: */
9: public class GradesSuite {
11: public static void main(String[] args) {
12: Scanner kbd = new Scanner(System.in);
13: int grade;
15: // introduce yourself
16: System.out.println("\n"
17: + "Grades and Conditionals\n"
18: + "-----------------------\n\n"
19: + "This program allows you to run several of the examples "
20: + "from the\n\"if-Control.ppt\" notes.\n\n"
21: + "For each example you are shown the code, "
22: + "then asked (twice or three\ntimes) what grade you got. "
23: + "Give answers to make the output change.\n\n"
24: + "You can try 44 and 55 as your answers (and 99 if it asks "
25: + "a third\ntime). "
26: + "That should show you each possible outcome.\n");
28: // Pause
29: System.out.print("\n...press Enter...");
30: kbd.nextLine();
32: // First example
33: System.out.println("\n"
34: + " if (grade < 50) {\n"
35: + " System.out.println(\"I'm sorry. "
36: + "You failed.\");\n"
37: + " }\n");
38: System.out.print("What grade did you get? ");
39: grade = kbd.nextInt();
40: kbd.nextLine();
41: if (grade < 50) {
42: System.out.println("I'm sorry. You failed.");
43: }
44: System.out.print("What grade did you get? ");
45: grade = kbd.nextInt();
46: kbd.nextLine();
47: if (grade < 50) {
48: System.out.println("I'm sorry. You failed.");
49: }
51: // Pause
52: System.out.print("\n...press Enter...");
53: kbd.nextLine();
55: // Second example
56: System.out.println("\n"
57: + " if (grade < 90) {\n"
58: + " System.out.println(\"You didn't get an A+.\");\n"
59: + " }\n"
60: + " if (grade >= 50) {\n"
61: + " System.out.println(\"You didn't fail.\");\n"
62: + " }\n");
63: System.out.print("What grade did you get? ");
64: grade = kbd.nextInt();
65: kbd.nextLine();
66: if (grade < 90) {
67: System.out.println("You didn't get an A+.");
68: }
69: if (grade >= 50) {
70: System.out.println("You didn't fail.");
71: }
72: System.out.print("What grade did you get? ");
73: grade = kbd.nextInt();
74: kbd.nextLine();
75: if (grade < 90) {
76: System.out.println("You didn't get an A+.");
77: }
78: if (grade >= 50) {
79: System.out.println("You didn't fail.");
80: }
81: System.out.print("What grade did you get? ");
82: grade = kbd.nextInt();
83: kbd.nextLine();
84: if (grade < 90) {
85: System.out.println("You didn't get an A+.");
86: }
87: if (grade >= 50) {
88: System.out.println("You didn't fail.");
89: }
91: // Pause
92: System.out.print("\n...press Enter...");
93: kbd.nextLine();
95: // Third example
96: System.out.println("\n"
97: + " if (grade < 50) {\n"
98: + " System.out.println(\"I'm sorry. You failed.\");\n"
99: + " }\n"
100: + " if (grade > 90) {\n"
101: + " System.out.println"
102: + "(\"That is an excellent grade!\");\n"
103: + " }\n");
104: System.out.print("What grade did you get? ");
105: grade = kbd.nextInt();
106: kbd.nextLine();
107: if (grade < 50) {
108: System.out.println("I'm sorry. You failed.");
109: }
110: if (grade > 90) {
111: System.out.println("That is an excellent grade!");
112: }
113: System.out.print("What grade did you get? ");
114: grade = kbd.nextInt();
115: kbd.nextLine();
116: if (grade < 50) {
117: System.out.println("I'm sorry. You failed.");
118: }
119: if (grade > 90) {
120: System.out.println("That is an excellent grade!");
121: }
122: System.out.print("What grade did you get? ");
123: grade = kbd.nextInt();
124: kbd.nextLine();
125: if (grade < 50) {
126: System.out.println("I'm sorry. You failed.");
127: }
128: if (grade > 90) {
129: System.out.println("That is an excellent grade!");
130: }
132: // Pause
133: System.out.print("\n...press Enter...");
134: kbd.nextLine();
136: // Fourth example
137: System.out.println("\n"
138: + " if (grade < 50) {\n"
139: + " System.out.println(\"I'm sorry. You failed.\");\n"
140: + " }\n"
141: + " if (grade < 50) {\n"
142: + " System.out.println(\"You cannot go on to 1227!\");"
143: + "\n"
144: + " }\n");
145: System.out.print("What grade did you get? ");
146: grade = kbd.nextInt();
147: kbd.nextLine();
148: if (grade < 50) {
149: System.out.println("I'm sorry. You failed.");
150: }
151: if (grade < 50) {
152: System.out.println("You cannot go on to 1227.");
153: }
154: System.out.print("What grade did you get? ");
155: grade = kbd.nextInt();
156: kbd.nextLine();
157: if (grade < 50) {
158: System.out.println("I'm sorry. You failed.");
159: }
160: if (grade < 50) {
161: System.out.println("You cannot go on to 1227.");
162: }
164: // Pause
165: System.out.print("\n...press Enter...");
166: kbd.nextLine();
168: // Fifth example
169: System.out.println("\n"
170: + " if (grade < 50) {\n"
171: + " System.out.println(\"I'm sorry. You failed.\");\n"
172: + " System.out.println(\"You cannot go on to 1227.\");\n"
173: + " }\n");
174: System.out.print("What grade did you get? ");
175: grade = kbd.nextInt();
176: kbd.nextLine();
177: if (grade < 50) {
178: System.out.println("I'm sorry. You failed.");
179: System.out.println("You cannot go on to 1227.");
180: }
181: System.out.print("What grade did you get? ");
182: grade = kbd.nextInt();
183: kbd.nextLine();
184: if (grade < 50) {
185: System.out.println("I'm sorry. You failed.");
186: System.out.println("You cannot go on to 1227.");
187: }
189: // Pause
190: System.out.print("\n...press Enter...");
191: kbd.nextLine();
193: // Sixth example
194: System.out.println("\n"
195: + " if (grade < 50) {\n"
196: + " System.out.println(\"You cannot go on to 1227.\");\n"
197: + " }\n"
198: + " if (grade >= 50) {\n"
199: + " System.out.println"
200: + "(\"You can continue on to 1227!\");\n"
201: + " }\n");
202: System.out.print("What grade did you get? ");
203: grade = kbd.nextInt();
204: kbd.nextLine();
205: if (grade < 50) {
206: System.out.println("You cannot go on to 1227.");
207: }
208: if (grade >= 50) {
209: System.out.println("You can continue on to 1227!");
210: }
211: System.out.print("What grade did you get? ");
212: grade = kbd.nextInt();
213: kbd.nextLine();
214: if (grade < 50) {
215: System.out.println("You cannot go on to 1227.");
216: }
217: if (grade >= 50) {
218: System.out.println("You can continue on to 1227!");
219: }
221: // Pause
222: System.out.print("\n...press Enter...");
223: kbd.nextLine();
225: // Seventh example
226: System.out.println("\n"
227: + " if (grade < 50) {\n"
228: + " System.out.println(\"You cannot go on to 1227.\");\n"
229: + " } else {\n"
230: + " System.out.println"
231: + "(\"You can continue on to 1227!\");\n"
232: + " }\n");
233: System.out.print("What grade did you get? ");
234: grade = kbd.nextInt();
235: kbd.nextLine();
236: if (grade < 50) {
237: System.out.println("You cannot go on to 1227.");
238: } else {
239: System.out.println("You can continue on to 1227!");
240: }
241: System.out.print("What grade did you get? ");
242: grade = kbd.nextInt();
243: kbd.nextLine();
244: if (grade < 50) {
245: System.out.println("You cannot go on to 1227.");
246: } else {
247: System.out.println("You can continue on to 1227!");
248: }
249: }
251: }