Starting from:

$25

Assignment #2-part 1 

Assignment #2-part 1 
COMP1006/1406 
Submit your Temperature.java file to Brightspace.
There are 10 possible marks A2-part 1
1 Temperature [10 marks]
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 write/complete. You must
complete the constructors and methods in the provided class (without changing any signatures,
return types, or modifiers).
In this problem you will need to be able to convert temperatures between Celsius, Fahrenheit
and Kelvin. For help, see https://en.wikipedia.org/wiki/Conversion_of_units_of_temperature
A Temperature object holds a single temperature value and displays it in one of the three scales.
Once a scale has been set, it will display the temperature in that scale until changed. The default
scale is Celsius if not specified.
The three scales are represented by Strings (class attributes) in the provided Scale class. 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 three scales and use these everywhere in
the code.
Some examples of using a Temperature object:
Temperature t = new Temperature(10.1);
System.out.println(t.getScale()); // displays "CELSIUS"
System.out.println(t.toString()); // displays "10.1C"
t.setScale(Scale.FAHRENHEIT); // change scale
System.out.println(t.toString()); // displays "50.18F" (notice it converted the value!)
System.out.println(t.getScale()); // displays "FAHREHEIT"
t = new Temperature(12.25, "KELVIN"); // scale input is not from Scale!
System.out.println(t.getScale()); // displays "NONE"
System.out.println(t.toString()); // displays "0.0N"
Note: Temperature values are floating point numbers. If the expected output is "0.1F" and your
output is "0.09999999999998F", that is OK. You are not asked to perform any string formatting
in this class.
Submit your Temperature.java to Brightspace. along with your .java files.
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.
1) You should have no static attributes or methods in your class.
2) Read the specifications in the skeleton file carefully!
(do not use Strings that look like the attributes from Scale)
3) Be sure to use ENCAPSULATION!
4) Remember to fill in the header comment block
COMP1006/1406 - Winter 2022 1

More products