-
help plzzzz
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.
-
Re: help plzzzz
Have you managed to do anything your self yet? Is there something special you are wondering about?
- ØØ -
-
Re: help plzzzz
noo i just don't understand how i ment to answer the questions, i've tried but i'm getting nowhere :-(
-
Re: help plzzzz
well i worked out that part A is to initialiase the 2d double array but i kinda don't know how to do that can anyone tell me what the code should look like?
-
Re: help plzzzz
Don't you have any school book or anything to look up in? It is bound to be there, under the section "array". This looks like a school assignment to me, so I guess you have a book.
Well, the code to make the 2D array, should probably look like this:
Code:
temperatures = new double[NUM_OF_READINGS][DAYS_IN_WEEK];
Unless I am starting to mix languages again now..:)
- ØØ -
-
Re: help plzzzz
-
Re: help plzzzz
well i'm struggleing with the last part of this question soo far i've dun this
11 d)
{
int coldCount = 0;
double total = 0.0;
for (day = 0; day<DAYS_IN_WEEK;day++)
{
double total=0.0;
for (row = 0; row<NUM_OF_READINGS;row++)
{
total = total + temperature[day-1][row];
if (total < 5.0)
{
coldCount++;
}
return coldCount++;
}
}
}
am i right? if not can someone show me where i was going wrong?