The objectives of this question are
(a) The following images show some items sold in Cold StorageTM Online Supermarket.
Suppose you are tasked to identify the variables needed to store data about each item. Note that
Write Java declaration statements to declare the variables. You are required to follow Java naming convention.
(b) A program shown in Figure 1 calculates which quarter of the year a month falls in and the percentage of year for that month. For example, month 4 falls in the second quarter and is 33.3% of a year, and month 9 falls in the third quarter and is 75.0% of a year. The month value is entered at the command line argument.
1. public class 1b
2. {
3. public static void main(String[] args)
4. {
5. int month;
6. int quarter;
7. double percentage;
8. month = (int) args[0];
9. quarter = (int) month/3.0 + 1;
10. percentage = (month/12)100;
11. System.out.printf("Quarter of year for month %1d",
12 month, " is %1d", quarter);
13. System.out.printf("Percentage of year for month %1f%%",
14. Percentage);
15. }
16. }
(i) This program does not compile successfully. Compile your program, correcting one error at a time until there is no more compilation error. Identifying only the compilation errors in the program, complete the table:
Line number
Compilation error
Explanation of error
Corrected statement (write the whole statement)
(ii) The program will encounter runtime and logic error. Modify the program to correct the errors so that
Your Name Your Student Number
Quarter of year for month 4 is 2
Percentage of year for month 33.3%
Submit your program listing together with screenshot showing one run of your program.
(c) Refer to table 1 which lists the insurance premium for adults based on the occupation class (class 1-3 – refer to table 2) and the choice of coverage (standard or deluxe) See image.
Write a program that prompts and gets
A sample run is shown below with user inputs are underlined:
Enter the choice of coverage (S - standard, D - deluxe): d
Enter the class of occupation (1-3): 1
Enter number of children to insure: 0
Total premium for Deluxe coverage for 1 class 1 adult only is $169.06
Your program output depends on the choice of coverage, the occupation class and the number of children to insured with the adult. Use printf to produce output in one of the following format:
Total premium for Standard coverage for 1 class 2 adult only is $120.91
or
Total premium for Standard coverage for 1 class 2 adult and 1 child is $147.66
or
Total premium for Deluxe coverage for 1 class 1 adult and 3 children is $310.30
Submit your program listing together with screenshot showing THREE runs of your program for a varying output. You should include your name and student number in the output.