Outcome
Requirements
public double fahrenheitToOther (double value, char scale)
public double celsiusToOther (double value, char scale)
public double kelvinToOther (double value, char scale)
(double value, char scale)
Each of these takes two parameters, a double value and a target scale. The scale values will be one of these characters: ‘F’, ‘C’, ‘K’, ‘R’. For example, fahrenheitToOther assumes that the given value is in Fahrenheit and converts that value to the new scale and returns the converted value.
For example, the method below shows celsiusToOther in use.An original value and a new scale are passed to it.As the name of the method celsiusToOther implies, the original value is of scale Celsius.The celsiusToOther method must contain the code to convert the given value to the given scale.
public double doConversion (double originalValue, char originalScale, char newScale)
{
double newValue = 0.0;
if (OriginalScale == CELSIUS)
newValue = celsiusToOther(originalValue, newScale);
return newValue;
}
Do not change the signatures of any of the methods. You are required to use the char type to assess the problem. Use defined constants where needed.
Conversion factors for translating between the different scales are readily available on various sites on the internet. Use defined constants whenever possible stylistically.
3: Add console input
Modify the main program in TemperatureConversion.java to allow for user input of single conversions.Loop and until a user indicates that he/she is finished. Your program should prompt for a value, starting scale, and target scale then perform the conversion and output the result.
4: Add File input
Prompt for the name of a file that contains a series of conversions and perform those conversions. The file should be a text file with the following format:
There is one set of conversion data per line of the file.
Each line of the file contains an original value, an original scale, and the target scale, for example,
23 F C
18.5 K R
You will use the text file temptest.txt, which I created in notepad.The file is in canvas.Note that in case of an error in the file a zero is displayed for the conversion along with a message. A complete run of the program output is at the end of this document. You may want to test your program with no error data and then test it with the error data to make sure you meet the specifications.
Your program should handle errors with a console message and return 0.0 when any conversion is not possible. For example, if a user enters ‘V’ instead of ‘C’, aconsoleerror message is displayed and the conversion method returns 0.0
Sample Program Run
Here is the sample run of a program that and file input.User input is in green.
Enter a number to choose one of the following options:
1
You selected 1
Enter temperature:25.5
Enter scale (F, C, K, R):
c
Enter scale to convert to (F, C, K, R):
f
25.50 Cis77.90 F
Would you like to doanother conversion? (y/n):
y
Enter temperature:100
Enter scale (F, C, K, R):
c
Enter scale to convert to (F, C, K, R):
k
100.00 Cis373.15 K
Would you like to doanother conversion? (y/n):
n
Enter a number to choose one of the following options:
2
You selected 2
Enter name of inputfile
temptest.txt
60.00 Fis288.71 K
70.00 Fis529.67 R
30.00 Fis-1.11 C
50.50 Cis122.90 F
60.50 Cis333.65 K
70.50 Cis618.57 R
20.00 Kis-423.67 F
30.00 Kis-243.15 C
40.00 Kis72.00 R
20.50 Ris480.17 F
30.50 Ris-256.21 C
40.50 Ris22.50 K
error invalid original scale specifiedD
0.00 Dis0.00 F
0.00 Cis32.00 F
error invalid original scale specifiedA
25.30 Ais0.00 K
error invalid conversion scale specifiedA
27.00 Fis0.00 A
54.00 Fis12.22 C
20.00 Kis-253.15 C
End of file processing.
Enter a number to choose one of the following options:
3
You selected 3
Goodbye
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more