1. What would be the value of discountRate after the following statements are ex
ID: 3762419 • Letter: 1
Question
1. What would be the value of discountRate after the following statements are executed?
double discountRate;
char custType = 'B';
switch (custType)
{
case 'A': discountRate = 0.08;
break;
case 'B': discountRate = 0.06;
case 'C': discountRate = 0.04;
default: discountRate = 0.0;
}
A) 0.08
B) 0.06
C) 0.04
D) 0.02.
2. What does the following code do?
Scanner keyboard = new Scanner(System.in);
String filename;
System.out.print("Enter the filename: ");
filename = keyboard.readString();
PrintWriter outFile = new PrintWriter(filename);
A) It writes to a file named filename.
B) It allows the user to enter the name of the file that data will to be written to.
C) It establishes a connection with a file named filename.
D) Nothing. The code contains a syntax error.
Explanation / Answer
1. What would be the value of discountRate after the following statements are executed?
double discountRate;
char custType = 'B';
switch (custType)
{
case 'A': discountRate = 0.08;
break;
case 'B': discountRate = 0.06;
case 'C': discountRate = 0.04;
default: discountRate = 0.0;
}
A) 0.08
B) 0.06
C) 0.04
D) 0.02.
Answer: The discountrate after the above statement is 0.06 i.e B
2. What does the following code do?
Scanner keyboard = new Scanner(System.in);
String filename;
System.out.print("Enter the filename: ");
filename = keyboard.readString();
PrintWriter outFile = new PrintWriter(filename);
A) It writes to a file named filename.
B) It allows the user to enter the name of the file that data will to be written to.
C) It establishes a connection with a file named filename.
D) Nothing. The code contains a syntax error.
Answer:The output of the above code is it writes to a file named filename i.e A
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.