Question: Part One Temperature Complete the provided Temperature class. Add any attributes and helper methods as needed but keep in mind that testing will involve only
Part One
Temperature
Complete the provided Temperature class. Add any attributes and helper methods as needed but keep in mind that testing will involve only the methods you are asked to writecomplete You must complete the constructors and methods in the provided class without changing any signatures, return types, or modifiers
A temperature consists of a value magnitude and a scale. For example, if the temperature is circmathrmC then its value is and its scale is Celsius. The valid scales that we will consider for our Temperature objects will be Celsius, Fahrenheit and Kelvin. Once a scale has been set, a Temperature object will always display its temperature in that scale until the scale is changed. The default scale is Celsius if not specified.
In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit and Kelvin. For help, see
The three scales are represented by Strings in the provided scale class static class attributes For this assignment, the purpose of the Scale class is to provide a consistent naming scheme for the different scales. Essentially, we assign fixed names for the scales and use these everywhere in the code so that a simple spelling mistake in your code does not result in failing every test case
Some examples of using a Temperature object:
Temperature t new Temperature;
System.out.printlntgetScale; displays "CELSIUS"
System.out.printlnttoString; displays C with exactly decimal digits
System.out.printlntgetValue; displays with at least decimal digit
tsetScaleScaleFAHRENHEIT; change scale
System.out.printlnttoString; displays Fnotice it converted the value!
System.out.printlntgetScale; displays "FAHRENHEIT"
t new Temperature "KELVIN"; scale input is not from Scale! SEE DOCUMENTATION!
System.out.printlntgetScale; displays "NONE"
System.out.printlnttoString; displays N
Note: You must provide the state instance attributes for the Temperature class. You must decide what state to store for this problem. But, you must only use instance attributes. You should have no static attributes in your class.
Note: Temperature values are floating point numbers. If an object's value is expected to be and your output from getValue is that is OK You are not asked to perform any rounding in the getValue method.
Note: The provided toString method will always display your Temperature objects using three decimal places. Rounding will happen automatically with this method.
Note: A program called SimpleTemperatureProgram is provided with the code shown above that you can use as a starting point for your own testing if you wish.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
