go to previous page   go to home page   go to next page

Answer:

Boolean arrays are automatically initialized to false. So just after constrution no days have valid data.


Getters and Setters

Getters and setters are needed. Here is the program with additions:


public class Month
{
  // instance variables
  private int   month;  // 1 == January
  private int   year;   // year as an int, eg 2017
  private int   daysInMonth;   // number of days in this month
  
  // temperature data
  private int[] temp;    // day 1 in temp[1] 
  private boolean[] valid;
  
  // constructors
  public Month( int month, int year)
  . . .
  
  // Getters and Setters
  public int getTemp( int dayNumber )
  {
  
  }

  public boolean setTemp( int dayNumber, int temp )
  {
  
  }
}


QUESTION 6:

Fill in the methods. Do some error checking. Think about dayNumber being out of range and invalid temperatures.


go to previous page   go to home page   go to next page