Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of the textbook. The students will learn how to write a

Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of the textbook. The students will learn how to write a user defined class.

Project Objectives:

Apply UML design on user defined class

Write overloaded constructors of a class

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

Write overloaded methods

Write main method to test the user defined class

Class Diagram:

Student 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.

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 25since (77-32)*5/9 = 25. For another example, if the temperature degree is 77 and scale is C, then the method will return 77.

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.

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

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

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

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.

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

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

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

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.

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

Create a Temperature object by calling default constructor

Print out the temperatures degree in Celsius

Print out the temperatures degree in Fahrenheit

Ask user to enter the scale and degree of the temperature

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

Print out the temperatures degree in Celsius

Print out the temperatures degree in Fahrenheit

Repeat step 1 to 7 for all other three constructorsto create three more temperatures

Test if temperature1 equals temperature2 and print out appropriate message

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

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

Repeat step 9 to 11 for other pairs of temperatures

Note on main function and debugging

Fix one error a time.

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

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

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

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

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

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

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

More Books

Students also viewed these Databases questions

Question

=+ f. instituting laws against driving while intoxicated

Answered: 1 week ago