Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help answer the code Wlr TnoBve only the methods you are asked to write/complete. You must complete the constructors and methods in the provided

Please help answer the code
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Wlr TnoBve 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 "CELSTUS", "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.getScale)) / outputs the char C System.out printin(t); // outputs 10.1C COMP1406-Winter 2019 Assignment #2 Due Friday, February 8 at 5:30 pm t . setScale (Scale. FAHRENHEIT) ; System.out.println(t); System.out.printin(t.getScale)) t.setTemp (12.25, "Kel"); System.out.printin(t) // outputs 50. 18F I outputs the char F' // outputs 12.25K When you set a temperature (without explicitly stating the scale), it is assumed that the input temperature is in whatever scale the object is currently using. Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code) 2 Weather 30 marks] acBook Pro Window Help 1 package comp1486a2: 4A class to represent temperature (with a value and scale) 6 COMP 1406 Winter 2019 8 Assignment 2 11 public class Temperaturet 12 13 Initializes a temperature object with given value in telsius 14 p> 15 16 object will be initialized with -273.15C. * If the initial temperature is tess than -273.15C then the teeperature 18 19 20 21 . eparas temp is the initial temperature in Celsius public Tenperature(double temp)i 23 24 25 26 27 28 29 Initializes a tesperature object with given value using the specified scale 4pp If the temperature is lower than absolute zero, in the given scate s then set the teeperature to absolute zero (in that scale). *spp Usage: mew Temperature(12.3, Scale.KELVIN) teap is the initial temperature in the scale provided in the second argument. 32 * eparan 34 eparan scale is the scale of initial tesperature and aust be a constant 35 36/ 37 public Temperatureldouble temp, Scale scale defined in the Scale enue type 38 40Initializes a new temperature abject that is a copy of the * tesperature object paraneter. MacBook Pro d Packages Window Help Welcome Guide 41temperature object paraneter. 43 e That is, it makes a new object that is a copy of the input 45 46 / 47 public Temperature(Temperature temp) e eparam temp is a non-null temperature obj 48 50 51 52 * getter for the scale 53 54 *sp> * The output of this getter method must always be the first letter of one * of the names in the Scales enum class. It must be the upper case letter. s spp 56 57 Example: t -new Temperature(12.3, Scale.KELVIN) t.getScale) will then output 'K' 59 60 61 62 63 public char getScale) * greturn the first letter (in upper case) of the string representation of the current scale of this object 64 return 'X' 65 67 1s getter for the temperature 68 r the tesperature of the object using the current scale 70 71 public double getTempO 72 73 74 75 76 s setter for scale return -Double.MAX VALUE; eparan scale is the new scale of the temperature and must be 79 80 81 ereturn a reference to this object. a constant from the Scale enum type. The next time you call getTemp), the teaperature will be output in this scale. MacBook Pro kages Window Help Welcome Guide call gettempt, the temperature will be output * @return a reference to this object. 83 public Temperature setscale(Scale scale)f 84 85 86 87 return this: // do NOT change this return statement. 88 /setter for temperature 89 90 eparam temp is the new temperature (in the object's current scale) 91 ereturn a reference to this object. 92 93 public Temperature setTemp(double temp)t 94 95 96 97 * setter for temperature 98 99 eparam temp is the new temperature 100 eparam scale is the scale of the new temperature. It must be 101 return this: /1 do NOT change this return statement. a constant from the Scale enum type. 182* ereturn a reference to this object. 103 184 105 106 107 public Temperature setTemp(double temp, Scale scale)f return this: / do NOT change this return statement. 188 * setter for temperature 189 118 eparam temp is the new temperature. * Oparan scale is a string representing one of the three scales * Greturn a reference to this object. 112 113 114 public Temperature setTemp(double temp, String scale) 115 116 return this: / do NOT change this return statement. 118 119 120 121 MacBook Pro 104 public Temperature setTemp(double temp, Scate scale) 5return this: 1/ do NOT change this return statement. 106 107 108/s setter for temperature 109 110 * eparam temp is the new temperature. 111 eparam scale is a string representing one of the three.scples. 112 greturn a reference to this object. 113 114 public Temperature setTemp(double temp, String scale)t 115 return thisi /1 do NOT change this return statement. 116 118 119 120 121 122 123 124 125 126 127 128 129 130 /* 131 /* 132 do not change anything below this 133 /* 134 /* 135 136 * String representation of a temperature object 137 0verride 138 public String toString) 139 140 141 142 143 return ""this.getTemp)+ this.getscale): MacBook Pro Wlr TnoBve 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 "CELSTUS", "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.getScale)) / outputs the char C System.out printin(t); // outputs 10.1C COMP1406-Winter 2019 Assignment #2 Due Friday, February 8 at 5:30 pm t . setScale (Scale. FAHRENHEIT) ; System.out.println(t); System.out.printin(t.getScale)) t.setTemp (12.25, "Kel"); System.out.printin(t) // outputs 50. 18F I outputs the char F' // outputs 12.25K When you set a temperature (without explicitly stating the scale), it is assumed that the input temperature is in whatever scale the object is currently using. Note: You should have no static attributes or methods in your class (unless they were supplied in the starter code) 2 Weather 30 marks] acBook Pro Window Help 1 package comp1486a2: 4A class to represent temperature (with a value and scale) 6 COMP 1406 Winter 2019 8 Assignment 2 11 public class Temperaturet 12 13 Initializes a temperature object with given value in telsius 14 p> 15 16 object will be initialized with -273.15C. * If the initial temperature is tess than -273.15C then the teeperature 18 19 20 21 . eparas temp is the initial temperature in Celsius public Tenperature(double temp)i 23 24 25 26 27 28 29 Initializes a tesperature object with given value using the specified scale 4pp If the temperature is lower than absolute zero, in the given scate s then set the teeperature to absolute zero (in that scale). *spp Usage: mew Temperature(12.3, Scale.KELVIN) teap is the initial temperature in the scale provided in the second argument. 32 * eparan 34 eparan scale is the scale of initial tesperature and aust be a constant 35 36/ 37 public Temperatureldouble temp, Scale scale defined in the Scale enue type 38 40Initializes a new temperature abject that is a copy of the * tesperature object paraneter. MacBook Pro d Packages Window Help Welcome Guide 41temperature object paraneter. 43 e That is, it makes a new object that is a copy of the input 45 46 / 47 public Temperature(Temperature temp) e eparam temp is a non-null temperature obj 48 50 51 52 * getter for the scale 53 54 *sp> * The output of this getter method must always be the first letter of one * of the names in the Scales enum class. It must be the upper case letter. s spp 56 57 Example: t -new Temperature(12.3, Scale.KELVIN) t.getScale) will then output 'K' 59 60 61 62 63 public char getScale) * greturn the first letter (in upper case) of the string representation of the current scale of this object 64 return 'X' 65 67 1s getter for the temperature 68 r the tesperature of the object using the current scale 70 71 public double getTempO 72 73 74 75 76 s setter for scale return -Double.MAX VALUE; eparan scale is the new scale of the temperature and must be 79 80 81 ereturn a reference to this object. a constant from the Scale enum type. The next time you call getTemp), the teaperature will be output in this scale. MacBook Pro kages Window Help Welcome Guide call gettempt, the temperature will be output * @return a reference to this object. 83 public Temperature setscale(Scale scale)f 84 85 86 87 return this: // do NOT change this return statement. 88 /setter for temperature 89 90 eparam temp is the new temperature (in the object's current scale) 91 ereturn a reference to this object. 92 93 public Temperature setTemp(double temp)t 94 95 96 97 * setter for temperature 98 99 eparam temp is the new temperature 100 eparam scale is the scale of the new temperature. It must be 101 return this: /1 do NOT change this return statement. a constant from the Scale enum type. 182* ereturn a reference to this object. 103 184 105 106 107 public Temperature setTemp(double temp, Scale scale)f return this: / do NOT change this return statement. 188 * setter for temperature 189 118 eparam temp is the new temperature. * Oparan scale is a string representing one of the three scales * Greturn a reference to this object. 112 113 114 public Temperature setTemp(double temp, String scale) 115 116 return this: / do NOT change this return statement. 118 119 120 121 MacBook Pro 104 public Temperature setTemp(double temp, Scate scale) 5return this: 1/ do NOT change this return statement. 106 107 108/s setter for temperature 109 110 * eparam temp is the new temperature. 111 eparam scale is a string representing one of the three.scples. 112 greturn a reference to this object. 113 114 public Temperature setTemp(double temp, String scale)t 115 return thisi /1 do NOT change this return statement. 116 118 119 120 121 122 123 124 125 126 127 128 129 130 /* 131 /* 132 do not change anything below this 133 /* 134 /* 135 136 * String representation of a temperature object 137 0verride 138 public String toString) 139 140 141 142 143 return ""this.getTemp)+ this.getscale): MacBook Pro

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

Step: 3

blur-text-image

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

=+ (d) Show that \, (He 0) =0 and A*(H) =1.

Answered: 1 week ago

Question

draft a research report or dissertation;

Answered: 1 week ago