Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this question and please explain in detail your steps I also included the methods and format the code should be written

image text in transcribed
image text in transcribedI need help with this question and please explain in detail your steps I also included the methods and format the code should be written
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
1 Temperature 15 marks] Complete the provided Temperature class. Add any attributes and helper methods as 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 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. For one of the methods, setTemp (double temp, String scale), the specification is a bit open ended. In this method, you will try to allow any scale input string that resembles the intended input. At the very least, it must work correctly for the three input strings "CELSIUS", "FAHRENHEIT" and "KELVIN". In order to receive full marks for this method it must be able to process more strings correctly. For example, see ***in the examples below. (Don't worry about processing typos of the names. Case and shortened versions should be handled.) Some examples of using a Temperature object: Temperature t new Temperature (10.1); System.out.println(t.getScaleO) // outputs the char C System.out.println(t); 5 8 // outputs 10.1C COMP1406 - Winter 2019 Temperature t-new Temperature (10.1); System.out.println(t.getScale )); / outputs the char C System.out.println(t); // outputs 10.1C COMP1406 Winter 2019 Assignment #2 Due Friday, February 8 at 5:30 pm t.setScale(Scale.FAHRENHEIT); System.out.printin(t); System.out.println(t.getScale) / outputs the char F' t.setTemp (12.25, "Kel"; System.out.println(t); // outputs 50.18F // outputs 12.25K When you set a temperature (without explicitly stating the scale), it is assumed that the input Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code). temperature is in whatever secale the object is currently using. Welcome Guide derined in the Scale enum type. public Temperature(double temp, Scale scale) /* Initializes a new temperature object that is a copy of the * temperature object parameter. That is, it makes a new object that is a copy of the input object. * eparam temp is a non-null temperature object public Temperature(Temperature temp)i /* getter for the scale *sp> * The output of this getter me thod must always be the first letter of one * of the names in the Scales enum class. It must be the upper case letter. 9 Example: t - new Temperature(12.3, Scale.KELVIN): t.getscale() will then output 'K * Greturn the first letter (in upper case) of the string representation of the current scale of this object. 3 54 55 public char getscale) return 'X'; 67 68 69 getter for the temperature 70 71 ereturn the temperature of the object using the current scale 72 73 public double getTemp) 74 return -Double.MAX VALUE 75 76 MacBook Pro 04 20 F6 F5 public double getTemp() return -Double.MAX VALUE /* setter for scale @param scale is the new scale of the temperature and must be a constant from the Scale enum type. The next time you call getTemp), the temperature will be output in this scale. * @return a reference to this object. public Temperature setScale(Scale scale)t return this; I1 do NOT change this return statement. / setter for temperature * eparam temp is the new temperature (in the object's current scale) * @return a reference to this object. public Temperature setTemp(double temp)t return this; // do NOT change this return statement. 9setter for temperature 1 eparam temp is the new temperature 2 eparam scale is the scale of the new temperature. It must be 2 3 a constant from the Scale enum type. 4e greturn a reference to this object. e6 public Temperature setTemp(double temp, Scale scale)t 07 08 109 return this; I/ do NOT change this return statement. 11 setter for temperature MacBook Pro bo 988 8 8 ereturn a rererence to this object. public Temperature setTemp(double temp, Scate scale)t return this: // do NOT change this return statement. /* setter for temperature * @param temp is the new temperature. * @param scale is a string representing one of the three scales *@return a reference to this object. public Temperature setTemp(double temp, String scale)t return this; // do NOT change this return statement. 6 28 29 31 32 * 34 / do not change anything below this 135 136 137 138String representation of a temperature object 139 0verride 148 public string toString) return+ this.getTemp() + this.getscale)i 141 142 143 MacBook Pro 04 bw 110 Fo

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

Define an inflation adjusted rate of return.

Answered: 1 week ago