Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Consider the following code: Scanner input = new Scanner(System.in); System.out.println(Coffee sizes: small medium large); System.out.print(Please enter your selection: ); String str = input.next(); int
1. Consider the following code:
Scanner input = new Scanner(System.in); System.out.println("Coffee sizes: small medium large"); System.out.print("Please enter your selection: "); String str = input.next(); int cost = 0; switch (str) { case "small": cost += 25; break; case "medium": cost += 50; break; case "large": cost += 75; break; default: System.out.println("Invalid selection."); break; }
Which of the following code blocks could replace the switch case in the above code?
A. while (str) { if "small": cost += 25; break; else if "2": else if "medium": cost += 50; break; else if "3": else if "large": cost += 75; break; else: System.out.println("Invalid selection."); break; } |
B. for str == "small" { cost += 25; } for str== "medium" { cost+=50; } for str == "large" { cost+= 75; } System.out.println("Invalid selection."); |
C. if (str.equals("small")) { cost += 25; } else if (str.equals("medium")) { cost +=50; } else if (str.equals( "large")) { cost += 75; } else { System.out.println("Invalid selection."); } |
D. if (str == "small") { cost += 25; } else if (str == "medium") { cost +=50; } else if (str == "large") { cost += 75; } else { System.out.println("Invalid selection."); }
2. Which of the following are valid ways to declare an array?
4. Consider the following class: class Employee { public int salary; public Employee(int annualSalary) { salary = annualSalary; } public Employee(int weeklySalary, int numberOfWeeks) { salary = weeklySalary * numberOfWeeks; } } Which of the following are valid ways to create an instance of this class?
5. Java provides file operations in which of the following?
|
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