Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In a new package, write a program that converts between temperatures in different units, Kelvin, Fahrenheit, and Celsius. The package should contain these three classes:

image text in transcribed

image text in transcribed

In a new package, write a program that converts between temperatures in different units, Kelvin, Fahrenheit, and Celsius. The package should contain these three classes: oop-student-hw2-two Degrees enumeration Temperature - kelvin : double aget/ set - celsius : double get/ set - fahrenheit: double eget/set KELVIN CELSIUS FAHRENHEIT + Temperature(double) + Temperature(double, Degrees) + toString() Converter + main(String[]): void Figure 8: Package diagram - the underlining on main means it is declared static Temperature.java has three private attributes, a double for each of the units of temperature. Write getters and setters for each; each setter should automatically set all three attributes to the appropri- ate values. For reference, these equations show you how to convert between Fahrenheit, Celsius, and Kelvin: K=C-273.15 C= 3x (F 32) F = 1.8 x C +32 The first constructor assumes that the given temperature is in degrees Celsius, and sets all three values accordingly. The second constructor takes an additional argument for the unit, which is one of the three instances of this enumeration: public enum Degrees { KELVIN, CELSIUS, FAHRENHEIT In addition, add a toString method that displays the temperature in the format "13.37 C", with the degrees Celsius shown to two decimal places. Finally, write the main class, Converter.java. This class contains a very simple program that prompts the user for the current temperature, then for a pair of units - either "K", "C", or "F". If the input temperature cannot be parsed as a double, or either unit is invalid, print an error message and prompt again for correct input. After processing the input, print the converted temperature then exit. Example output: Temperature Conversion Calculator Enter the temperature> 98.6 Enter the temperature unit [K/C/F] > F Enter the desired unit [K/C/F]> C Current Temperature: 37.0 Degrees Celsius

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 Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

Students also viewed these Databases questions