Question
Need help coding this program. I've spent hours trying to understand how to finish this project but am lost. Please assist if possible and any
Need help coding this program. I've spent hours trying to understand how to finish this project but am lost.
Please assist if possible and any assistance is greatly appreciated.
Thanks
***************************************************************************************************************************************************
1. Based on the code below, answer these questions:
Which line will be executed if the condition in line 3 is true? Processing then will proceed to which line?
Which line will be executed if the condition in line 3 is false? Processing will then proceed to which line? Line 7 Line 10 Depends on Truth Value of Line 5 Line 7 will always be executed whether line is true or false.
Line 8 will only be executed when line is . Line 10 will only be executed when line is .
1 System.out.printf(%nWhat is your age? ); 2 age = input.nextInt(); 3 if(age >= 21) 4 legalAge = true; 5 else 6 legalAge = false; 7 if(legalAge) 8 System.out.printf(%nYou can order alcoholic beverages!%n); 9 else 10 System.out.printf(%nYou CANNOT order alcoholic beverages!%n);
2. Re-code the IF-ELSE structure in lines 7-10 above so the else statement is now the if statement. HINT: The condition tested should be reversed.
3. Use printf() with format specifiers as needed. Code on this page the following:
a. Code an if statement that prints You are employee of the month! when attendance is greater than or equal to 20. Assume attendance is already declared.
b. Write an if-else statement that assigns a 20000.00 scholarship for a gpa of 4.0 or above; a 10000.00 scholarship for a gpa of 3.75 or above; and, a 5000.00 scholarship for a gpa of 3.5 or above. Assume gpa and scholarship are already declared. Use braces to scope the code properly.
c. Code a while loop that keeps printing You are a scholar! as long as the user enters a gpa of 3.75 or greater. Assume the loop-control variable, gpa, is already declared along with input for the Scanner class. Prompt for the gpa prior to entering the loop.
d. Code a conditional operator (ternary operator) that prints 2017 when epic2020WarFilm is Y or y, and The Longest Day is another epic war movie filmed in 1962. when it is anything else. Assume epic2020WarFilm has already been declared and initialized.
e. Code a while loop with if-else structures that determine the meaning of each movie rating. i. Declare a loop-control variable initialized to Y to check the rating. ii. Declare a String variable that stores the letter(s) for the rating advisory. iii. Declare a String variable that stores the meaning of the rating. iv. Declare an integer variable that stores the rating choice. v. Code the while where you test the loop-control variable to Y using Character.toUpperCase(). 1) Have the user choose from the prompt:
U.S. MOVIE RATINGS
1. NR 2. G 3. PG 4. PG-13 5. R 6. NC-17
Choose the number for the rating:
2) Based on the rating print XXXXX - Xxxxxxxxxxxxx where the Xs represent the rating and the Xxs represent its meaning. a) NR - Not rated. b) G All ages. c) PG Not suitable for children. d) PG-13 Inappropriate for children under 13. e) R Accompany by parent or adult guardian under 17. f) NC-17 No one 17 and under.
3) Prompt to re-enter the loop or exit.
4) Refer to sample output below. vi. Assume the input variable for the Scanner class is already declared. vii. ****SAMPLE OUTPUT*****
U.S. MOVIE RATINGS
1. NR 2. G 3. PG 4. PG-13 5. R 6. NC-17
Choose the number for the rating: 3
PG Not suitable for children.
Look at another movie rating? Enter 'Y' or 'N': y
U.S. MOVIE RATINGS
1. NR 2. G 3. PG 4. PG-13 5. R 6. NC-17
Choose the number for the rating: 6
NC-17 No one 17 and under.
Look at another movie rating? Enter 'Y' or 'N': n
***************************************************************************************************************************************************Helpful insight on above mentioned coding project below
Code for capturing a single character from the keyboard. The name of the loopcontrol variable doesnt have to be keepGoing. It should be a user-defined identifier that identifies the purpose of the loop or what the variable is controlling. Sometimes the name for this variable can be derived from its prompt. ****************************************************************************************** char keepGoing = Y; //SENTINEL-CONTROL VARIABLE while(Character.toUpperCase(keepGoing) == Y) //UPPERCASING THE LETTER IN answer //SO IT CAN BE TESTED AGAINST THE //UPPERCASE CHARACTER LITERAL Y { : //Ellipses represent preceding code. Cant be coded in .java file. . //PROMPTS TO SEE IF USER WANTS TO CONTINUE System.out.printf("%nDo you want to keep going? Enter \Y\ or \N\: "); keepGoing = input.nextLine().charAt(0); //CAPTURES A SINGLE CHARACTER FROM //THE KEYBOARD }//END while keepGoing = Y
***************************************************************************************************************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started