In: Computer Science
Create a complete java program called Week_Report. The program
must include two array structures, a string array called DaysOfWeek
and a double array called Temp_Values. Store in the DaysOfWeek
array the following values (Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday, Sunday). Store in the Temp_Values array the
following (23.5, 34.0, 20.9, 45.7, 29.3, 34.5, 32.5). Using a for
loop structure output the values for the two arrays.
Day of the Week Temperature Values
Monday 23.5
Tuesday 34.0
Wednesday 20.9
Thursday 45.7
Friday 29.3
Saturday 34.5
Sunday 32.5
Names for the main program and the array structures are provided in the question.
JAVA Language to be used
Step 1 : Save the following code in Week_Report.java
public class Week_Report {
public static void main(String[] args) {
String[] DaysOfWeek = {"Monday",
"Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday",
"Sunday"};
double[] Temp_Values = {23.5, 34.0,
20.9, 45.7, 29.3, 34.5, 32.5};
System.out.println("Day of the Week
Temperature values");
// Use for loop and print values.
Array index starts from 0 and ends at n-1
for(int i = 0; i <
DaysOfWeek.length; i++) {
// Leave a blank
space between the 2 values and print
System.out.println(DaysOfWeek[i] + " " + Temp_Values[i]);
}
}
}
Step 2 : Build the project and run the program.
Following is my sample output