nit_head
Aug 19th, 2005, 12:05 PM
ok i have an exam soon and like this was a question on last year exam (yes i'm a totally newbie to java and programmin, totally use less) plzzzz help :cry:
11.
A temperature-recording device measures the temperature in the morning, at midday and in the afternoon, on each day of a single week. The table shown below could represent the data recorded by this device.
Mon Tues Wed Thrs Fri Sat Sun AM 1.5 -1.2 -2.0 -1.6 0.7 0.2 1.0 Midday 8.2 2.5 -1.0 3.4 5.6 5.7 8.5 PM 7.5 3.0 0.0 4.0 5.0 5.2 8.0
One software component of the device is a class called TemperatureRecorder. The incomplete Java code for this class is given below
public class TemperatureRecorder
{
public static final int NUM_OF_READINGS = 3;
public static final int DAYS_IN_WEEK = 7;
private double[][] temperatures;
public TemperatureRecorder()
{
The code for the body of this method is not provided
}
public void setTemperature(int day, int reading,
double theTemperature)
{
The code for the body of this method is not provided
}
public double averageForDay(int day)
{
The code for the body of this method is not provided
}
public int numOfColdDays()
{
The code for the body of this method is not provided
}
}
In answering this question you will be required to provide the Java code for the incomplete methods of the class TemperatureRecorder.
14
171CS/11 15a) Provide the Java code for the constructor method of the class
TemperatureRecorder.
(3 marks)
b) Provide the code for the method setTemperature. This method accepts integer values representing the day of the week (1 to 7) and the time of day when the temperature was recorded: 1 for the morning, 2 for midday and 3 for the afternoon. The value of the recorded temperature is also provided as a parameter. The method assigns the value of the recorded temperature to the appropriate location in the array temperatures.
No error checking is performed on the values entered.
(4 marks)
c) Provide the Java code for the method averageForDay. This method calculates the average temperature for the day specified by the value of the parameter day (1 to 7).
(8 marks)
d) Provide the Java code for the method numOfColdDays. This method calculates the number of days that can be classified as cold. A cold day is defined as one for which the sum of its three recorded temperatures is less than 5.0.
11.
A temperature-recording device measures the temperature in the morning, at midday and in the afternoon, on each day of a single week. The table shown below could represent the data recorded by this device.
Mon Tues Wed Thrs Fri Sat Sun AM 1.5 -1.2 -2.0 -1.6 0.7 0.2 1.0 Midday 8.2 2.5 -1.0 3.4 5.6 5.7 8.5 PM 7.5 3.0 0.0 4.0 5.0 5.2 8.0
One software component of the device is a class called TemperatureRecorder. The incomplete Java code for this class is given below
public class TemperatureRecorder
{
public static final int NUM_OF_READINGS = 3;
public static final int DAYS_IN_WEEK = 7;
private double[][] temperatures;
public TemperatureRecorder()
{
The code for the body of this method is not provided
}
public void setTemperature(int day, int reading,
double theTemperature)
{
The code for the body of this method is not provided
}
public double averageForDay(int day)
{
The code for the body of this method is not provided
}
public int numOfColdDays()
{
The code for the body of this method is not provided
}
}
In answering this question you will be required to provide the Java code for the incomplete methods of the class TemperatureRecorder.
14
171CS/11 15a) Provide the Java code for the constructor method of the class
TemperatureRecorder.
(3 marks)
b) Provide the code for the method setTemperature. This method accepts integer values representing the day of the week (1 to 7) and the time of day when the temperature was recorded: 1 for the morning, 2 for midday and 3 for the afternoon. The value of the recorded temperature is also provided as a parameter. The method assigns the value of the recorded temperature to the appropriate location in the array temperatures.
No error checking is performed on the values entered.
(4 marks)
c) Provide the Java code for the method averageForDay. This method calculates the average temperature for the day specified by the value of the parameter day (1 to 7).
(8 marks)
d) Provide the Java code for the method numOfColdDays. This method calculates the number of days that can be classified as cold. A cold day is defined as one for which the sum of its three recorded temperatures is less than 5.0.