1. (2pts) What do the following expressions evaluate to in Java given int x = 3, y = 6;
a) x == y / 2
b) x % 2 == 0 || y % 2 != 0
c) x – y < 0 && !(x >= y)
d) x + 6 != y || x / y <= 0
2. (1 pts.) Write statements to prompt for and read the users full name using a Scanner variable.
3. (2 pts.)What does the following statement sequence print? (page 63)
String str = "Harry";
int n = str.length();
String mystery = str.substring(0,1) + str.substring(n-1, n);
System.out.println(mystery);
/*
Question1:
a) XX
b) XXX.XXX
…
*/
Write a Java program called Assignment2.java. The program is to display questions and read user inputs, then calculate and print out the requested value with a proper format.
This program will follow a very simple process. see image.
Task 1 (5 pts): Ask user for 3 exam scores and calculate the average of the 3 exam scores. Use the class NumberFormat from java.text package to format the average with 2 digits.
Task 2 (5 pts): Ask user to enter a name (Grace Jill Hopper) and print the initial of first name, middle and last name (GJH) Check the difference between the next()(Look at the page 60) and nextLine()
Task 3 (5 pts): Ask user to enter total number of seconds and convert the total seconds to the hours, minuets, and seconds. For example, 8124-seconds is converted to 2:15:24 (2 hours, 15 minutes, and 24 seconds)
Use only the Java statements that have been covered in class to date. (Chapters 1 &2) This means you CAN use declaration, assignment, input and output statements. DO NOT use any other statements (if-else, loop, etc.). If in doubt, ask your TA or instructor. Complete each task one by one.
Example Execution:
The following is an example input and output. The input is shown in red. Make your own questions rather than this example.
*** TASK 1: Calculate the average of three exams ***
Please input the first exam: 82
Please input the second exam: 93
Please input the third exam: 78
The average of three exams is: 84.33
*** TASK 2: Find the initials ***
What is your first name? Robin
What is your middle name?: McLaurin
What is your last name?
Williams Your initials are: RMW
*** TASK 3: Convert the seconds to H:M:S ***
Please input the total seconds: 8124
The total time (Hours:Minutes:Seconds) is: 2:15:24
*** END OF Assignment#2 ***