top of page

Temperature Class Utility


Arrays and data encapsulation: defining a class that contains encapsulated arrays of data and defining the methods/properties needed to access and mutate the data within the object.

  • Contains an interface for the TempUtil class below: ITempUtilchar mode {get;set;} void setDispUnits(bool b) string printReport()

  • Class: TempUtil- daysOfWeek: string[] - temps: float[,] + mode: char + dispUnits: bool+ TempUtil() + printReport(): string + setMode(char): void + getMode(): string + setDispUnits(bool):string

  • In the constructor:

    • Initialize the daysOfWeek with the days of the week: {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}

    • Initialize the temps with the data in the table below.

    • Initialize mode to lowercase 'f'. Mode will be used to determine whether printReport() prints the data in their default units of measurement (Fahrenheit) vs their converted Celsius value.

    • Initialize dispUnits to 'false'. This will determine whether printReport() displays the current units of measurement.


  • printReport() will return a string organized per the table below. Furthermore, based on the values in 'mode' and 'dispUnits', you will format the output with or without the current unit of measurement next to each value, and based on the 'mode' whether to print the default fahrenheit values or their celsius equivalent.


Days Morning Temp Evening Temp

Monday 45.7 40.2

Tuesday 47.8 31.5

Wednesday 30.2 35.5

Thursday 32.3 38.6

Friday 40.4 40.5

Saturday 43.6 43.2

Sunday 52.0 47.1


 
 
 

Recent Posts

See All

Comments


bottom of page