Question: 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?

A. int[] numbers = {1, 2, 3, 4, 5}; 
B. int[] numbers; numbers = new int[10]; 
C. int[] numbers = new int[10]; 
D. int[5] numbers = {1,2 ,3, 4, 5};

3.

What is the purpose of a constructor?

A. Constructors can be very useful for setting initial values for certain private instance and static class variables
B. Constructors can be very useful for defining methods
C. Constructors can be very useful for controlling access to private instance variables and static class variables throughout the life of the instance
D. Constructors can be very useful for handling all of the java code required in a program.

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?

A. Employee e1 = new Employee(30000);
B. Employee e2 = new Employee(500, 52);
C. Employee e4 = new Employee("Joe Smith");
D. Employee e3 = new Employee();

5.

Java provides file operations in which of the following?

A. java.io.PrinterWriter.*
B. java.util.*
C. java.io.*
D.

java.io.util*

6.

Which of the following are steps in Task Centered GUI Design?

A. Finalize
B. Design
C Iterate
Analyze
Evaluate
Initialize

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!