ArithmeticVarsIPOpart2 Nov2023
ArithmeticVarsIPOpart2 Nov2023
Write each program using appropriate variables (number and type) and input methods.
2. Create a Temperature program that will convert last week’s daily temperatures in Toronto,
input by the user in Celsius, to Fahrenheit, and calculate the average weekly temperature in
both units. Display the results (all daily temperatures in both units, and both averages) in a
nicely formatted table (see below). Declare variables (with appropriate names and data types)
to store the temperatures (Celsius and Fahrenheit) for each day of the week, and the weekly
average (in both Celsius and Fahrenheit). Display the weekly averages rounded to 2 decimals.
Sample Output:
Toronto Temperatures (Week of Oct. 29)
Sunday Monday Tuesday Wednesday Thursday Friday Saturday AVERAGE
Celsius 9 10 9 7 14 12 9 10.00
Fahrenheit 48.2 50 48.2 44.6 57.2 53.6 48.2 50.00
3. Create a MakeLabels program that consists of four (4) variables that are used to store the user’s name, student
number, grade, and date of birth, and outputs the information to the screen in the following format:
Pay special attention to format and spacing of the output. You can use the appropriate escape sequences and
escape characters, or use field widths with your print / println statements.
4. Days Alive:
Write a program that calculates the number of days you have been alive and the number of hours of your life
that you have spent sleeping. Assume that you sleep 8 hours each night. To simplify the problem, assume there
are 30 days in each month and 365 days in each year. The output should look something like this:
int x;
x = 3;
int y = x;
x = 5;
y = y + x;
System.out.println(x);
System.out.println(y);
2. What would be the exact output of the following Java fragment code?
System.out.println("Hello" + 42);
System.out.println(1 + "Hello" + 2);
System.out.println("Hello" + 4 + 2);
System.out.println(1 + 2 + "Hello");
System.out.println("Hello"+9*3);
System.out.println("1"+1);