Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS JAVA PROGRAMMING... Objectives: 1. Apply UML design on user defined class 2. Write overloaded constructors of a class 3. Write mutators (i.e. get

THIS IS JAVA PROGRAMMING...

Objectives:

1. Apply UML design on user defined class

2. Write overloaded constructors of a class

3. Write mutators (i.e. get methods) and accessors (i.e. set methods) of a class

4. Write overloaded methods

5. Write main method to test the user defined class

You must implement the Temperature class according to the following class design:

TEMPERATURE

-degree: double

-scale: char

+Temperature()

+Temperature(degree: double)

+Temperature(scale: char)

+Temperature(degree: double, scale: char)

+getDegreeInCelsius(): double

+getDegreeInFahrenheit(): double

+setDegree(degree: double): void

+setDegree(scale: char): void

+setDegree(degree: double, scale: char): void

+equals(obj: Temperature): boolean

+isLessThan(obj: Temperature): boolean

+isGreaterThan(obj: Temperature): boolean

Method Details:

The name of a method explains it usage.

1. getDegreeInCelsius will return the temperatures degree in its equivalent Celsius degree. If the temperatures scale is C, then the return value is temperatures degree. If the temperatures scale is F, the return value is calculated by the following formula: C = (F-32)*5/9. For example, if the temperature degree is 77 and scale is F, then the method will return 25 since (77-32)*5/9 = 25. For another example, if the temperature degree is 77 and scale is C, then the method will return 77.

2. getDegreeInFahrenheit will return the temperatures degree in its equivalent Fahrenheit degree. If the temperatures scale is F, then the return value is temperatures degree. If the temperatures scale is C, the return value is calculated by the following formula: F = 1.8C+32. For example, if the temperature degree is 25 and scale is F, then the method will return 25; For another example, if the temperature degree is 25 and scale is C, then the method will return 77 since 1.8*25+32 = 77.

3. void setDegree(double degree) will reset the temperature to given degree without change the scale of the temperature.

4. void setDegree(char scale) will reset the temperature to given scale without change the degree of the temperature.

5. void setDetree(double degree, char scale) will reset the temperature to given degree of given scale.

6. equals method returns true if this temperature is equal to parameter Temperature; false otherwise. You need to compare tow temperatures under same scale. For example, you either compare whether getDegreeInCelsius return same value for both temperatures, or whether getDegreeInFahrenheit return the same value for both temperatures.

7. isLessThan method return true if this temperature is less than parameter Temperature ; false otherwise. Again, you need to compare two temperatures under same scale.

8. isGreaterThan method returns true if this temperature is greater than parameter Temperature; false otherwise. Again, you need to compare two temperatures under same scale.

Main Method Requirements

1. The main method must create four Temperature objects by using all four constructors.

2. The main method must test all set and get methods by setting the attributes according to users input then displaying the temperature by printing out the result of get methods.

3. The main function must test equals, isLessThan, and isGreaterThan methods by compare two Temperature objects and print out the result.

Sample pseudo code for main function

1. Create a Temperature object by calling default constructor

2. Print out the temperatures degree in Celsius

3. Print out the temperatures degree in Fahrenheit

4. Ask user to enter the scale and degree of the temperature

5. Call set method(s) to set the temperatures degree and scale

6. Print out the temperatures degree in Celsius

7. Print out the temperatures degree in Fahrenheit

8. Repeat step 1 to 7 for all other three constructors to create three more temperatures

9. Test if temperature1 equals temperature2 and print out appropriate message

10. Test if temperature1 is less than temperature2 and print out appropriate message

11. Test if temperature1 is greater than temperature2 and print out appropriate message

12. Repeat step 9 to 11 for other pairs of temperatures

Note on main function and debugging

Fix one error a time.

1. If step 2 output is wrong, then either constructor is wrong or getDegreeInCelsiu function is wrong

2. If step 3 output is wrong, then either constructor is wrong or getDegreeInFahrenheit function is wrong

3. If step 6 output is wrong, then either set method(s) is wrong or getDegreeInCelsiu function is wrong

4. If step 7 output is wrong, then either set method(s) is wrong or getDegreeInFahrenheit function is wrong

5. If step 9 output is wrong, then the equals method has problem

6. If step 10 output is wrong, then the isLessThan method has problem

7. If step 11 output is wrong, then the isGreaterThan method has problem

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions