In: Computer Science
Lab Directions:
Complete each
of the programs
here. Create a
separate Netbeansproject
for each program using the name I specified. Create a single java
main class for each of the programs using the filename I
specified.
Task
1: (5 points)
Project name:
CtoFConverter
Main
file name:
TempConverter.java
A program that converts an inputted temperature in
C
and provides the equivalent temperature in
F.
Hint: Google is your friend! Given
C,
solve for
F.
Again, check for a valid input value and only respond with
the
F
value if you got it, otherwise output an appropriate error msg to
the user.
Testing: 3 conditions: Bad Input, then test for the known freezing
and boiling points.
EMBED
SCREEN SHOT(S)
OR COPY THE OUTPUT WINDOW
OF NETBEANS HERE SHOWING YOUR PROGRAM TEST RUN(S):
Task
2: (5 points)
Project
name:
FuelCosts
Main
file name: FuelCost.java
Write a program that asks the user to input
Then print how far the car can go with the gas in the tank. Again, check for valid input and exit with an error msg if you do not have it. Testing: here just use some reasonable values that you can inspect the calculations and determine they are correct.
EMBED SCREEN SHOT(S) OR COPY THE OUTPUT WINDOW OF NETBEANS HERE SHOWING YOUR PROGRAM TEST RUN(S):
Submitting your work:
Create a new compressed .zip archive folder. (Don’t give me any other type of archive, it will be returned to you ungraded!) called Lastname_Firstname_Lab_06.zip using your name.
Place
both
of your
Netbeans
project
folders in this archive. (Do
not individually zip the projects!) Place
this word doc file with your screen shots in the archive as well.
(Don’t put this in the individual project folders, put it in the
top level in the archive so I can access it easily.)
(When I
open you archive I should see each of your project folders in it
and this file.)
Submit the one Zip file (with both NetBeans projects and the Word document) for your grade.
1. CODE IN JAVA:
TempConverter.java file:
import java.util.Scanner;
public class TempConverter {
public static void main(String[] args) {
// creating object to the Scanner
class to take input from the user
Scanner sc = new
Scanner(System.in);
// taking temperature in celcius as
input from the user
System.out.print("Enter temperature
in celcius:");
double celcius =
sc.nextDouble();
// converting celcius to
fahrenheit
double fahrenheit = ((celcius * 9)
/ 5) + 32;
// displaying the temperature in
Fahrenheit
System.out.printf("Corresponding
temperature in fahrenheit:%.2f\n", fahrenheit);
}
}
OUTPUT:

2. CODE IN JAVA:
FuelCost.java file:
import java.util.Scanner;
public class FuelCost {
public static void main(String[] args) {
// creating object to the Scanner
class to take input from the user
Scanner sc = new
Scanner(System.in);
// taking input from the user
System.out.print("Enter the number
of gallons of gas currently in the tank:");
double num = sc.nextDouble();
System.out.print("Enter the fuel
efficiency in miles per gallon:");
double efficiency =
sc.nextDouble();
// calculating travel distance of
the car
double distance = num *
efficiency;
// displaying the travel
distance
System.out.println("The car can
travel maximum " + distance + " miles");
}
}
OUTPUT:
