Demonstrate programming fundamentals – decisions, loops, arithmetic

 

Objectives

  1. Demonstrate programming fundamentals –  decisions, loops, arithmetic operations, arrays, use of objects,  constructing and using methods, parameter passing, etc.
  2. Demonstrate console I/0
  3. Demonstrate text file input
  4. Demonstrate ability to follow a program specification

Outcome

  1. Produce a program that converts temperature values between 4 different scales -Fahrenheit, Celsius, Kelvin, Rankine.
  2. A  starting program (TemperatureConversion.java) with required methods to  complete is provided below. No credit is given if this starting file is  not used. and must be used to receive credit 

Requirements

  1. Produce the four methods defined in the provided starting program TemperatureConversion.java:

public double fahrenheitToOther (double value, char scale)

public double celsiusToOther (double value, char scale)

public double kelvinToOther (double value, char scale)

public double rankineToOther (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.

  1. Complete the doConversion method that is  defined in TemperatureConversion.java. Notice that it only allows for  conversion from Celsius. Decisions and calls for the other conversion  methods must be added to use the other three xxxToOther methods.  Remember that to use a class, an object of that class type must be  created.

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 solicit console input 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. 

  • Make sure that your program works for both upper and lower case input.
  • Make  sure that you can recover from user input of an incorrect scale. Your  program should continue and not terminate with incorrect alpha  characters.
  • Check for negative Kelvin and Rankine input  temperatures. Your program should continue and not terminate with the  input of a negative Rankine or Kelvin temperature.
  • Be sure to test at least three of each conversion. See the test data spreadsheet included on canvas.

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.

  1. Use some Error Handling

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’, a console error message is displayed and the conversion method returns 0.0

Sample Program Run

Here is the sample run of a program that uses console input and file input. User input is in green.

 Enter a number to choose one of the following options:

  1. Convert temperatures one at a time.
  2. Convert temperature from a list of value in a .txt file.
  3. End the program

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 C is 77.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 C is 373.15 K

Would you like to doanother conversion? (y/n): 

n

Enter a number to choose one of the following options:

  1. Convert temperatures one at a time.
  2. Convert temperature from a list of value in a .txt file.
  3. End the program

2

 You selected 2

Enter name of inputfile

temptest.txt

60.00 F is 288.71 K

70.00 F is 529.67 R

30.00 F is -1.11 C

50.50 C is 122.90 F

60.50 C is 333.65 K

70.50 C is 618.57 R

20.00 K is -423.67 F

30.00 K is -243.15 C

40.00 K is 72.00 R

20.50 R is 480.17 F

30.50 R is -256.21 C

40.50 R is 22.50 K

error invalid original scale specified D

0.00 D is 0.00 F

0.00 C is 32.00 F

error invalid original scale specified A

25.30 A is 0.00 K

error invalid conversion scale specified A

27.00 F is 0.00 A

54.00 F is 12.22 C

20.00 K is -253.15 C

End of file processing.

Enter a number to choose one of the following options:

  1. Convert temperatures one at a time.
  2. Convert temperature from a list of value in a .txt file.
  3. End the program

3

 You selected 3

Goodbye

University Writings
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.