Design and implement a class for Thermometer objects that are capable of reporting their temperature in either Fahrenheit or Celsius. A formula for converting Fahrenheit to Celsius is: C = (5*(F-32)/9)
The class should have one field (attribute) called degreesF, which contains the Fahrenheit temperature, and public methods called getFahrenheit(), which returns the temperature in Fahrenheit, and getCelsius(), which returns the temperature in Celsius. These methods should not print any output. There should also be a public constructor that takes the Fahrenheit temperature as a parameter.
Implement a main() method to test your Thermometer class. The main method should create Thermometer objects, send them getFahrenheit and getCelsius messages, and print the results. Your program should produce something like the following output in the Java console:
The Fahrenheit temperature of thermometer1 is 20.0 degrees. The Celsius temperature of thermometer1 is -6.67 degrees. The Fahrenheit temperature of thermometer2 is 98.6 degrees. The Celsius temperature of thermometer2 is 37.0 degrees.
You can use different values than the ones shown to test your program if you like. Also, don't worry about the exact format of the numbers. It is OK if your output displays a different number of decimal places.
This problem can be solved using only one class, the Thermometer class, which will implement the temperature conversion. It will contain a main() method in which Thermometer instances will be created and used.
* Class Name: Thermometer
* Author: (your name here)
* (Describe the purpose of the class here.
* Use multiple lines, if necessary.)
Step 4. Use the stepwise refinement approach to code and test the Thermometer class. Here's a sequence of appropriate steps, after each of which you should compile and run your program:
Read Section 2.6, From the Java Library, from Chapter 2 of Java, Java, Java, 3E and then incorporate code into your main() method that allows the user to input the values for temperatures. Follow the examples in the book of inputting numbers using the Scanner class. The input values read in main should be passed to the Thermometer constructor.
When your assignment is complete, add some comments to the beginning of the java source code explaining any problems you encountered in completing the assignment and describing any bugs in your solution. Undocumented bugs are worse than documented bugs. If you have undocumented bugs we will assume that you did an inadequate job of testing your code, and you will lose additional points.
Submit your source code file (Thermometer.java) as an email attachment to the appropriate grader depending on your lab section. Use the subject line CIS-180 HW#2 in your email. Your UML class diagram may either be submitted in class (hardcopy), or included as a second email attachment with your source code.
Make sure you send your homework to the proper place. Homework sent to the wrong address may not receive credit!
|L1||Mon. 2PM||Wes Fowlksemail@example.com|
|L2||Wed. 9AM||Neelima Mothefirstname.lastname@example.org|
|L3||Wed. 1PM||Wes Fowlksemail@example.com|
There will be a 10% penalty for assignments received after the due date. Assignments will not be accepted more than one week past the due date.