Question: Lab 1 Convert Celsius into Fahrenheit Math in Java: Open NetBeans. Create a new Project in NetBeans IDE If you prefer, here are written instructions

Lab 1 Convert Celsius into Fahrenheit

Math in Java:

Open NetBeans.

Create a new Project in NetBeans IDE

If you prefer, here are written instructions for creating this program:

Create a new Java Project:

File->New Project.

Select "Java with Ant" in the category list.

Select "Java Application" in the project list. Click "Next".

Enter a project name into the Project name field, for example, "Lab 1 - Conversion".

Enter the main class name into the Create Main Class field, for example, CelsiusToFahrenheit.

Click "Finish".

A Java editor for CelsiusToFahrenheit.java will open.

In the main method, write the following:

Declare an integer named celsius. Assign it a value 20.0.

Do you see any error after assigning a double to integer variable celsius?

Use type casting to fix the error.

Declare a double variable as fahrenheit.

Use the following formula to convert Celsius to Fahrenheit.

fahrenheit = (9 / 5) * celsius + 32

Print temperature in both units.

Save using Ctrl-s. This automatically compiles CelsiusToFahrenheit.java.

Click the "Run" button in the toolbar (a green arrow).

It runs the program and the console will open and display the following:

Temperature in celsius: 20

After conversion

Temperature in Fahrenheit: 52.0

However, the correct result should be:

Temperature in celsius: 20

After conversion

Temperature in Fahrenheit: 68.0

You can try to fix the answer by making a small change in the formula.

Hint: 9/5 has int value 1 because the numerator and denominator are both of type int, integer division is done and the fractional part is discarded. We want floating-point division, which does not discard the part after the decimal point.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!