Question: Please help me with the Check version of this assignment. Starting point code is down below. Instructions We will create a simple application that prints
Please help me with the Check version of this assignment. Starting point code is down below.
Instructions
We will create a simple application that prints out a table of Celsius and Fahrenheit values.
Download the starting point code:
- Converter.java
- Double.java
- TempTable.java
Notice that all three of these classes are in named packages. You will need to create the appropriate directory structure when you down load them.
Converter.java contains one method: c2f. Double.java contains three methods: format1, format3, and format. TempTable.java contains one method: main.
There are JavaDoc comments for the three classes and for all the methods in these classes. Most of the methods have "dummy implementations" so that they will compile as downloaded. The application method has a brief skeleton of the code.
Minus version
Use these classes to create a table like the one that follows:
Celsius Fahrenheit 0.0 32.000 10.0 50.000 20.0 68.000 30.0 86.000 40.0 104.000 50.0 122.000 60.0 140.000 70.0 158.000 80.0 176.000 90.0 194.000 100.0 212.000
Add a loop to TempTable.main to generate the Celsius values. Pass that into Converter.c2f to convert the value into Fahrenheit. Use Double.format1 to create String representations of the Celsius values and Double.format3 to create String representations of the Fahrenheit values. You can use these strings to generate the output within the loop in TempTable.main.
Notes:
- The Double.format1 method shall format the double value into a string that is 6 characters wide with one digit after the decimal point.
- The Double.format3 method shall format the double parameter value into a string that is 12 characters wide with three digits after the decimal point.
- For the Minus version you can leave the "dummy implementation" in the three-parameter method Double.format.
Hint: The String.format method will be very helpful.
Here is the formula for Celsius to Fahrenheit conversion:
F = 1.8C + 32
For reference sake, here is a Python version of the code:
def main(): print('Celsius Fahrenheit') for i in range(11): print('%6.1f%12.3f' % (i*10, i*90/5+32))
Package up the three Java source code files into a jar file, from which they can be extracted, compiled, and run.
Check version
There are two enhancements for the Check version:
- Make the jar file runnable.
- Complete the Double method. That is, replace the "dummy implementation" within the three parameter Double.format method.
Here are some notes about these enhancements:
Runnable jar Needless to say, when the jar file is run, it should run TempTable.main.
Double.format Complete this method in addition to completing the implementations of format1 and format3. Note: It would be possible to implement the format1 and format3 methods using the three-parameter format method.
Converter.java
package cpts132.packages.temp;
/** * A simple supplier class that converts temperature values. */ public class Converter {
/** * Converts Celsius to Fahrenheit. * @param value The Celsius temperature to be converted * @return The calculated Fahrenheit temperature */ public static double c2f(double value) { return 0; } } Double.java
package cpts132.packages.string;
/** * A class to handle conversion of double values to String representations. */ public class Double {
/** * Creates a String representation of the given double value. * The string representation will have one place following the * decimal point and be right justified within an output string * of six characters. * @param value The double value to be formatted * @return The formatted string */ public static String format1(double value) { return ""; } /** * Creates a String representation of the given double value. * The string representation will have three places following the * decimal point and be right justified within an output string * of twelve characters. * @param value The double value to be formatted * @return The formatted string */ public static String format3(double value) { return ""; } /** * Creates a String representation of the given double value. * @param value The double value to be formatted * @param places The number of places after the decimal point * @param width The length of the output String. The value will be * right justified within the output String. * @return The formatted string */ public static String format(double value, int places, int width) { return ""; } } TempTable.java
package cpts132.packages;
/** * A simple class that uses classes in named packages. */ public class TempTable {
/** * A program that prints out a temperature conversion table * @param args The command-line arguments */ public static void main(String[] args) { // print out headers System.out.println("Celsius Fahrenheit"); // print out values } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
