Explanation of Solution
Given statements:
//Switch to score
switch (score)
{
//Case
case (score > 90):
//Assign the grade
grade = 'A';
//Break the statement
break;
//Case
case (score > 80):
//Assign the grade
grade = 'b';
//Break the statement
break;
//Case
case (score > 70):
//Assign the grade
grade = 'C';
//Break the statement
break;
//Case
case (score > 60):
//Assign the grade
grade = 'D';
//Break the statement
break;
//Default Case
default:
//Assign the grade
grade = 'F';
}
Error in the given statement:
Error #1:
The case statements itself cannot contain an expression. The “case” must be carried out with an integer or a character. The given code cannot be modified as the “switch” statement because it contains expressions. It can only be converted into “if-else-if” statement that is given below...
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Starting Out with Java: Early Objects (6th Edition)
- def integer_0_or_1(interger): #if value is true return 1 if truth_value: return 1 else: #else return 0 return 0def truth_value(integer): """Convert an integer into a truth value.""" # Convert 0 into False and all other integers, # including 1, into True if integer == 0: truth_value = False else: truth_value = True return truth_value print(truth_value(True))print(truth_value(False)) This question assesses Block 2 Part 4. It assumes an understanding of binary notation and truth tables (Block 1 Part 1). Write a function and_binary(), which takes two integers (each is either 0 or 1) and returns an integer in accordance with the truth table: A B and_binary(A, B) 0 0 0 0 1 0 1 0 0 1 1 1 Before you dive into writing your function, first decompose the problem. Then, write an algorithm. Only after that, implement your solution in Python. Hint: When you have decomposed the…arrow_forwardThe code segment will display PTUKPTUK: int value = 1; value++; switch (value) { case 1: cout << "PTUK"; case 1 + 1: cout << "PTUK" << "PTUK";break; default: cout << "PTUK"; } Select one: O True Falsearrow_forwardMadLib Game bigGame.py Write a program that plays a MadLib game with the user. The program should ask the user to enter the following words: A plural noun (PNOUN1) A person’s first name (FNAME) A noun (NOUN1) A person’s last name (LNAME) A second plural noun (PNOUN2) A place (PLACE1) A third plural noun (PNOUN3) Another place (PLACE2) A fourth plural noun (PNOUN4) A second noun (NOUN2) An adjective (ADJECTIVE1) A second adjective (ADJECTIVE2) A verb (VERB) A third adjective (ADJECTIVE3) After the user has entered these items, the program should display the following story, inserting the user’s input into the appropriate locations: Hello there, sports PNOUN1!This is FNAME, talking to you from the press NOUN1in LNAME Stadium, where 57,000 cheering PNOUN2Have gathered to watch (the) PLACE1 PNOUN3take on (the) PLACE2 PNOUN4.Even though the NOUN2 is shining, it’s a/an ADJECTIVE1cold day with the temperature in the ADJECTIVE2 20s.We’ll be back for the opening VERB -off after a few…arrow_forward
- def print_num_pattern(num1, num2): if num1 <=0: print("0", end="") return print(num1, end="") print_num_pattern(num1 - num2, num2) print(num1, end="") if __name__ == "__main__": num1 = int(input()) num2 = int(input()) print_num_pattern(num1, num2)arrow_forwardWrite a statement that assigns finalValue with the multiplication of userNum1 and userNum2. Ex: If userNum1 is 6 and userNum2 is 2, finalValue is 12. let userNum1 = 6; // Code tested with values: 6 and 4let userNum2 = 2; // Code tested with values: 2 and -2 let finalValue = 0;arrow_forwardLab: switch Note: switch syntax is only applied for service selection. You can use if – else syntax for other comparison. Using switch syntax to write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minutes. Premium service: $25 plus For calls made from 6:00 a.m to 6:00 p.m., the first 75 minutes are free; charges for more than 75 minutes are $0.10 per minute. For, calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for more than 100 minutes are $0.05 per minute. Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code for r or R means regular service; a service…arrow_forward
- Use C Language Airline Reservation System A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You are to write a program to assign seats on each flight of the airline's only plane (capacity: 10 seats). Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "economy" If the person types 1, then your program should assign a seat in the first class section (seats 1-5). If the person types 2, then your program should assign a seat in the economy section (seats 6-10). Your program should then print a boarding pass indicating the person's seat number and whether it is in the first class or economy section of the plane. Use a single-subscripted array to represent the seating chart of the plane. Initialize all the elements of the array to 0 to indicate that all seats are empty. As each seat is assigned, set the corresponding elements of…arrow_forwardSuppose x and y are int variables and symbol is a char variable. Assume the following input data: 4. 38 26 *67 33 24 $ 55 # 34 # & 63 85 What value (if any) is assigned to x, y, and symbol after each of the fol- lowing statements executes? (Use the same input for each statement.) (2, 3, 4) а. cin >> x >> y; cin.ignore (100, '\n'); cin >> symbol; b. cin >> x; cin.ignore (100, '*'); cin >> yi cin.get (symbol); C. cin >> yi cin.ignore (100, '\n'); cin >> x >> symbol; cin.get (symbol); cin.ignore (100, '*'); d. cin >> x; cin.ignore (100, '\n'); cin >> y;arrow_forward20. Random Number Guessing GameWrite a program that generates a random number in the range of 1 through 100, and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” If the user guesses the number, the application should congratulate the user and generate a new random number so the game can start over.Optional Enhancement: Enhance the game so it keeps count of the number of guesses that the user makes. When the user correctly guesses the random number, the program should display the number of guesses. USE RAPTOR PROGRAMarrow_forward
- Population Tracker Learning Objective: Using Python Repetition and Loop Statements Problem Description Write a Python program (Console and GUI) that predicts the approximate size of a population of organisms. The application should use text boxes to allow the user to enter the following information: starting number of organisms, the average daily population increase (as a percentage), and the number of days the organisms will be left to multiply. For example, assume the user enters the following values: Starting number of organisms: 2 Average daily increase: 30% Number of days to multiply: 10 The program should display the following table of dataarrow_forwardRetail price calculator Write a program that asks the user to enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example: • If an item’s wholesale cost is 5.00 and its markup percentage is 100 percent, then the item’s retail price is 10.00.• If an item’s wholesale cost is 5.00 and its markup percentage is 50 percent, then the item’s retail price is 7.50. The program should have a method named calculateRetail that receives the wholesale cost and the markup percentage as arguments and returns the retail price of the item.arrow_forwardtranlate source program in the picture into quadruples tranlate source program in the picture into quadruples tranlate source program in the picture into quadruplesarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT