Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the provided Convert. java file, complete the convert(String, String) method. The method takes a String and a char as input and outputs (returns) a

image text in transcribedimage text in transcribed

In the provided Convert. java file, complete the convert(String, String) method. The method takes a String and a char as input and outputs (returns) a double. publicstaticdoubleconvert(Stringtemperature,charscale){} The input [1 String temperature has both a value and scale and will always be in the form "x.yS", where x.y is a decimal number like 10.1,0.0, or 15.3. It always has a number before the decimal point (it might be negative), the decimal point itself and at least one digit to the right of the decimal point. So, 10 and .3 are not valid. The last character in the this String will either be C (for Celsius) or F (for Fahrenheit). Examples of valid input are "10.0C", "-12.29F", and "1010.7C". The second input, scale, is either the char ' C ' or ' F '. The method will take the input temperature and convert it to the specified scale, outputting (returning) the resulting temperature value. Here are some examples. Convert.convert("10.0C",F)Convert.convert("10.2C",C)Convert.convert("-40.0C",50.0F)10.240.0 Note that you are using floating point numbers in this problem. Because of this, if you expect your result to be a number like 50.0 and you actually get something like 50.00000000000000020 or 49.99999999999999999787, don't worry. Remember representational error! However, if you expect 1.0 and you get 1.01 then something went wrong. Our testing will consider two numbers like 1.00000000000000020 and 0.99999999999999999787 as being the same. If your method is called and the output is less than absolute zero then instead of returning the number you computed, you will instead return the appropriate value of absolute zero (depending on the scale you are converting to). An example, of this special case, would be Convert.convert("-500.0F", 'C') 273.15 There is a main() method that can be used as a basic tester for your code. Note that you should add more test cases than the ones provided to ensure your methods are correct. When you submit, we will not be running this file as a program. Instead, we will use another program to call your function. But, your Convert. java file must compile without error to receive marks. public static double convert(String temperature, char scale)\{ I/ converts a temperature (value/scale) to a new scale return 1234567.9; Run | Debug public static void main(String[] args) System. out, println( x : "Testing Convert. convert"); String in ="10.0OC "; char scale = ' F '; double expect =50.0 double out = Convert. convert (in, scale); System.out. println("convert( \+ in + " "\", \+scale+\)); System.out. println("... expect : " + expect); System.out. println("...actual : " + out); in ="10.0C; scale =C; expect =10.0 out = Convert. convert (in, scale ); System. out . println("... expect : " + expect); System. out. println("...actual : " + out)

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

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

Explain methods of metal extraction with examples.

Answered: 1 week ago