X942: Using Getters and Setters

For this question, you will be working with the following two classes

A Weather class and a Person class:

  public class Weather
  {
      private boolean isRaining;
      private int tempInF;

      public Weather(boolean rain, int temp)
      {
          this.isRaining = rain;
          this.tempInF = temp;
      }

      public boolean isRaining()
      {
          return isRaining;
      }

      public int getTempInF()
      {
          return tempInF;
      }
  }


  public class Person
  {
      public boolean needsRaincoat;
      public boolean needsShorts;

      public Person()
      {
          needsRaincoat = false;
          needsShorts = false;
      }

      public void setNeedsRaincoat(boolean needsRaincoat)
      {
          this.needsRaincoat = needsRaincoat;
      }

      public void setNeedsShorts(boolean needsShorts)
      {
          this.needsShorts = needsShorts;
      }
  }

Implement the method prepareForDay() that takes in a Weather object and a Person object.

If isRaining is true in the Weather object, set needsRaincoat to true in the Person object.

If the temperature is at least 65 degrees (fahrenheit) in the Weather object, set needsShorts to true in the Person object.

For an added challenge, try to complete this assignment using only 2 lines of code.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.