Basic java program

Basic java program

Defining Classes in Java

1. Define a class named Fahrenheit that stores a single temperature (as in integer value).
The class should contain the following: (20 pts.)

An alternator constructor that is passed a temperature

A copy constructor

A single getter method

A toString method that returns a string of the form “76 degrees Fahrenheit”.

Method belowFreezing that returns true if the temperature is 32 or less.

a static method names convertToCelsius that is passed, as an integer value,

a temperature in Fahrenheit, and returns the equivalent temperature (as an

integer value) in Celsius.

Using Composition in Java

2. Define (create) a class named HighLowTemperature that stores both the high and low
temperatures on a given date as Fahrenheit type objects from question1. The class should
contain the following: (20 pts.)

An alternator constructor that is passed a given date (as a string, e.g., “2-16-18”,

and the high and low temperatures for that date (as objects oftype Fahrenheit).

An appropriate toString method.

Getter methods getDate, getHighTemp and getLowTemp

A getTempDifference that returns the difference between the high and low

temperatures.

A reachedFreezing method that returns true if the temperature was below

freezing at any time that day