create account

6.8 (Part 1) Temperature Class - Java by kakradetome

View this thread on: hive.blogpeakd.comecency.com
· @kakradetome ·
$0.70
6.8 (Part 1) Temperature Class - Java
https://www.youtube.com/watch?v=rLFYIq3iID8

Starting out with Java: From control structures through objects
Chapter 6
Programming Challenges

8. Temperature class 

Write a Temperature class that will hold a temperature in Fahrenheit, and provide methods to get the temperature in Fahrenheit, Celsius, and Kelvin. The class should have the following field: 

•  ftemp–A double that holds a Fahrenheit temperature.

The class should have the following methods: 

•  Constructor–The constructor accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. 
•  setFahrenheit – The setFahrenheit method accepts a Fahrenheit temperature (as a double) and stores it in the ftemp field. 
•  getFahrenheit – Returns the value of the ftemp field, as a Fahrenheit temperature (no conversion required). 
•  getCelsius – Returns the value of the ftemp field converted to Celsius. 
•  getKelvin – Returns the value of the ftemp field converted to Kelvin.

Use the following formula to convert the Fahrenheit temperature to Celsius: Celsius = (5/9) x (Fahrenheit - 32) 

Use the following formula to convert the Fahrenheit temperature to Kelvin:  Kelvin = ((5/9) x (Fahrenheit - 32)) + 273 

Demonstrate the Temperature class by writing a separate program that asks the user for a Fahrenheit temperature. The program should create an instance of the Temperature class, with the value entered by the user passed to the constructor. The program should then call the object’s methods to display the temperature in Celsius and Kelvin.

Gaddis, Tony (2015-05-29). Starting Out with Java: From Control Structures through Objects (Page 398 and 399). Pearson Education. Kindle Edition.

Happy Steeming Everyone! :)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 24 others
properties (23)
authorkakradetome
permlink6-8-part-1-temperature-class-java
categoryprogramming
json_metadata{"tags":["programming","coding","java","temperature-class","tony-gaddis"],"image":["https://img.youtube.com/vi/rLFYIq3iID8/0.jpg"],"links":["https://www.youtube.com/watch?v=rLFYIq3iID8"],"app":"steemit/0.1","format":"markdown"}
created2017-01-08 18:29:42
last_update2017-01-08 18:29:42
depth0
children0
last_payout2017-02-08 18:59:18
cashout_time1969-12-31 23:59:59
total_payout_value0.539 HBD
curator_payout_value0.156 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,713
author_reputation31,794,084,266,065
root_title"6.8 (Part 1) Temperature Class - Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id2,196,092
net_rshares8,431,846,555,112
author_curate_reward""
vote details (88)