Answered step by step
Verified Expert Solution
Link Copied!

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?

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

Different types of Grading?

Answered: 1 week ago

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Describe the concept of corporate social responsibility.

Answered: 1 week ago

Question

Explore the concept of business ethics.

Answered: 1 week ago

Question

Discuss human resource management issues for small businesses.

Answered: 1 week ago