Java Program Project To write Java programs to perform simple computations To di
ID: 3879583 • Letter: J
Question
Java Program Project
To write Java programs to perform simple computations
To display output to the console
To obtain input from the console using the Scanner class
To use identifiers to name variables, constants, methods, and classes
To use variables to store data
To program with assignment statements and assignment expressions
To use constants to store permanent data
To use the basic syntax of a Java program
To create, compile, and run Java programs
To use Java programming style and document programs properly
To write Pseudocode and Flowchart
To develop Java Programs using NetBeans or Eclipse
Program 1:
*2.17 (Science: wind-chill temperature) How cold is it outside? The temperature alone is not enough to provide the answer. Other factors including wind speed, relative humidity, and sunshine play important roles in determining coldness outside. In 2001, the National Weather Service (NWS) implemented the new wind-chill temperature to measure the coldness using temperature and wind speed.
The formula is
where t a is the outside temperature measured in degrees Fahrenheit and v is the speed measured in miles per hour. t w c is the wind-chill temperature. The formula cannot be used for wind speeds below 2 mph or temperatures below 58 ºF or above 41ºF. Write a program that prompts the user to enter a temperature between 58 ºF and 41ºF and a wind speed greater than or equal to 2 and displays the wind-chill temperature. Use Math.pow(a, b) to compute v 0.16 .
CLASS NAME: Your program class should be called WindChillTemperature
Here is a sample run:
Enter the temperature in Fahrenheit between -58°F and 41°F: 5.3
Enter the wind speed (>=2) in miles per hour: 6
The wind chill index is -5.56707
Program 2:
*2.23 (Cost of driving) Write a program that prompts the user to enter the distance to drive, the fuel efficiency of the car in miles per gallon, and the price per gallon, and displays the cost of the trip.
CLASS NAME: Your program class should be called CostOfDriving
Here is a sample run:
Enter the driving distance: 900.5
Enter miles per gallon: 25.5
Enter price per gallon: 3.55
The cost of driving is $125.36
t 35.740.6215ta -35.750016 + 0.4275tqv016Explanation / Answer
WindChillTemperature.java
import java.util.Scanner;
public class WindChillTemperature {
public static void main(String[] args) {
//Declaring variable
double f;
double temperature,wind_Velocity;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
while(true)
{
//Getting the Temperature from the user.
System.out.print("Enter the temperature in fahrenheit between -58F and 41F:");
temperature=sc.nextFloat();
if(temperature<-58 || temperature>41)
{
System.out.print("** Must be between -58F and 41F **");
continue;
}
else
break;
}
while(true)
{
//Getting the wind velocity from the user.
System.out.print("Enter the wind speed( >=2 ) in miles per hour :");
wind_Velocity=sc.nextInt();
if(wind_Velocity<2)
{
System.out.println("** Must be >=2 **");
continue;
}
else
break;
}
//Calling the method by passing the temperature and wind velocity as parameters.
f=windchill(temperature,wind_Velocity);
//Displaying the Wind chill
System.out.printf("The Wind Chill index is %.4f",f);
}
//Method Implementation which calculates windchill
public static double windchill(double temp,double windV)
{
//Calculating the windchill
double windchill=35.74+(0.6125*temp)-(35.75*Math.pow(windV,0.16))+(0.4275*temp*Math.pow(windV,0.16));
return windchill;
}
}
__________________
Output:
Enter the temperature in fahrenheit between -58F and 41F:5.3
Enter the wind speed( >=2 ) in miles per hour :6
The Wind Chill index is -5.6148
__________________
2)
DrivingCost.java
import java.util.Scanner;
public class DrivingCost {
public static void main(String[] args) {
//Declaring variables
double distanceToDrive,milesPerGallon,pricePerGallon,costOfDriving;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
//Getting the input entered by the user
System.out.print("Enter the driving distance: ");
distanceToDrive=sc.nextDouble();
System.out.print("Enter miles per gallon: ");
milesPerGallon=sc.nextDouble();
System.out.print("Enter price per gallon: ");
pricePerGallon=sc.nextDouble();
//calculating the cost of Driving
costOfDriving=(distanceToDrive/milesPerGallon)*pricePerGallon;
//Displaying the output
System.out.printf("The cost of driving is $: %.2f",costOfDriving);
}
}
_____________________
Output:
Enter the driving distance: 900.5
Enter miles per gallon: 25.5
Enter price per gallon: 3.55
The cost of driving is $: 125.36
_______________Could you plz rate me well.Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.