Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.A Java class can contain which of the following? a) Only Methods b)Only Data c

ID: 3747351 • Letter: 1

Question

1.A Java class can contain which of the following?

a) Only Methods b)Only Data c)Objects d)Methods and Data e)All of the above

I chose e as an aswer. but I got 1/2 pts (partial). What is correct answer?

2.Write a Java switch statement that checks a variable of type String called myString, and increments (adds one to) an int variable named numberStates if the variable has the value “Colorado” or “Utah”, and increments an int variable named numberCities if the variable has the value “Denver” or “Fort Collins”, and prints “Not recognized” if the string is anything else. Assume all variables are previously declared.

switch(myString){

case 'Colorado' : numberStates++;

break;

case 'Utah' : numberStates++;

break;

case 'Denver' : numberCities++;

break;

case 'Fort Collins' : numberCities++;

break;

default : System.out.println("Not recognived")

} I got 4/5 pts for this. What is wrong here?

Explanation / Answer

Answer 1: Answer is D class can contain the methods and data

Answer 2: here the mistake is case labels in '' so as these are strings we need put them in " "

switch(myString){

case "Colorado" : numberStates++;

break;

case "Utah" : numberStates++;

break;

case "Denver" : numberCities++;

break;

case "Fort Collins" : numberCities++;

break;

default : System.out.println("Not recognived");

}