Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, please The kelvin is the base unit of temperature in the International System of Units (SI), having the unit symbol K. It is named

Java, please

The kelvin is the base unit of temperature in the International System of Units (SI), having the unit symbol K. It is named after the Belfast-born, Glasgow University engineer and physicist William Thomson, 1st Baron Kelvin (18241907). It uses absolute zero as its null point. The Celsius scale, also known as the centigrade scale, is a temperature scale used by the International System of Units (SI). The Celsius scale is based on 0 C for the freezing point of water and 100 C for the boiling point of water at 1 atm pressure. Kelvin temperatures and Celsius temperatures are related. This means that a temperature difference of one degree Celsius and that of one kelvin are exactly the same. On the Fahrenheit scale, the freezing point of water is 32 degrees Fahrenheit (F) and the boiling point is 212 F (at standard atmospheric pressure). There are three conversion methods. toCesius() converts the this temperature to a Celsius value and returns it. toKelvin () converts the this temperature to a Kelvin value and returns it. toFahrenheit() converts the this temperature to a Fahrenheit value and returns it. These conversions do not change the value of the this. There will be a method for each of the arithmetic operations. For divide it will be divide(double), which returns a temperature in the scale of the this. For add it will be add(Temperature), which returns a temperature in the scale of the this. For Subtract it will be subtract(Temperature), which also returns a temperature in the scale of the this. The value of this is not changed in these three methods. There are two boolean methods. Method equals(Temperature) tests the value of the parameter and this and returns true it they are equal., Method greaterThan(Temperature) compares the this with the parameter and returns true if this is greater than the parameter. There should be a read() method and a toString() method in your class. Remember methods add, subtract, and divide and the three conversion methods all return a Temperature. Include at least two constructors: a default constructor and an explicit constructor. You must use a private helper method called set() that takes the parameters of the constructor and tests for appropriate values for each possible scale. The set method is a void method. This private set() method can be used to guarantee temperature values are in the proper range. The add(), subtract(), and divide() methods can call the constructor which calls the set() method. The set method will check the degree value and if it is in the proper range a new Temperature will be made to be returned by the add() method, subtract() method, and divide() method. A switch statement should be used throughout this class when choosing between C, F, and K. Absolute zero for Kelvin is 0, for Fahrenheit -459.67, and for Celsius -273.15. Your program must guarantee this absolute value is not violated. For the equals() method consider changing the this temperature and the parameter temperature to the same scale and then testing the degree value for equality.

This the demo to use for the project

public class TemperatureDemoWithoutArrays { public static final int ARRAY_SIZE = 5; public static void main(String[] args) { int x; Temperature temp1 = new Temperature(100.0, 'C'); Temperature temp2 = new Temperature(122, 'F'); Temperature temp3 = new Temperature(32.0, 'F'); Temperature temp4 = new Temperature(100.0, 'C'); Temperature tempAve = new Temperature(50.0, 'C'); System.out.println(temp2 + " to Celcius is " + temp2.toCelsius()); System.out.println("Temp1 is " + temp1); temp1 = temp1.toKelvin(); System.out.println("Temp1 to Kalvin is " + temp1); if (temp2.equals(tempAve)) { System.out.println("These two temperatures are equal"); } else { System.out.println("These two temperature are not equal"); } System.out.println("tempAve is " + tempAve); System.out.println("temp1 is " + temp1); System.out.println("temp2 is " + temp2); System.out.println("temp3 is " + temp3); System.out.println("temp4 is " + temp4); tempAve = tempAve.add(temp1); tempAve = tempAve.add(temp2); tempAve = tempAve.add(temp3); tempAve = tempAve.add(temp4); tempAve = tempAve.divide(5); System.out.println("The average temperature is " + tempAve); temp2 = new Temperature(150.0, 'k'); temp4 = new Temperature(100.0, 'c'); System.out.print("Subtracting " + temp2 + " from " + temp4 +" gives " ); temp4 = temp4.subtract(temp2); System.out.println(temp4); } }

This is how the output should be

122.0F to Celcius is 50.0C Temp1 is 100.0C Temp1 to Kalvin is 373.15K These two temperatures are equal tempAve is 50.0C temp1 is 373.15K temp2 is 122.0F temp3 is 32.0F temp4 is 100.0C The average temperature is 60.0C Subtracting 150.0K from 100.0C gives 223.14999999999998C 

Thank you

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

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions