Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using JAVA Write a class called Temperature that has two instance variables: a temp value (a floating-point number - data type double) and a character

Using JAVA Write a class called Temperature that has two instance variables: a temp value (a floating-point number - data type double) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a constructor that sets each instance variable (assume zero degrees if no temp value is specified and Celsius if no scale is specified), and it should include the following methods: 1. two accessor methods: one to return the degrees Celsius and the other to return the degrees Fahrenheit use the following formulas to write the two methods: DegreesC = 5(degreesF - 32)/9 DegreesF = (9(degreesC)/5) + 32 2. three mutator methods: one to set the value, one to set the scale ( F or C ), and one to set both; 3. a comparison method: it should return -1 if the invoking temperature is less than the argument temperature, 0 if they are equal and 1 if the invoking temperature is greater than the argument one; 4. a toString method: returns a String representing the calling Temperature object. The numeric value of the temperature should be rounded to the nearest tenth of a degree. For example, System.out.println(new Temperature(98.164555, F)); //should print: 98.2 F

Then write a driver program called TempTester that tests all the methods from the Temperature class. Example tests: 0.0 degrees C = 32.0 degrees F, -40.0 degrees C = -40.0 degrees F, and 100.0 degrees C = 212.0 degrees F.

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Be familiar with the integrative servicescape model.

Answered: 1 week ago

Question

Determine the roles of spatial layout and functionality.

Answered: 1 week ago