Create a wind chill calculator project that can determine the wind chill tempera
ID: 3796699 • Letter: C
Question
Create a wind chill calculator project that can determine the wind chill temperature given the Fahrenheit temperature and the wind speed. Formula for calculating wind chill temperature windChillTemperature- 35.74 0.6215 (temperature) 35.750windspeed) 0.4275 (temperature)(windspeed) To calculate the exponent use Math pow() 4.2 Math pow(4.2, 0.16) Test data: temperature of 5.3 and wind speed of 6 gives a wind chill temperature of -5.56707 Write a class definition file named WindChillCalculator that has these fields and constants: temperature wind speed constants: use two symbolic constants for 35.74 and 0.4275 Write the following methods: Two constructor methods: The no-args constructor that sets both of the field values to zero except for the constants The constants are set using the conversions given above The overloaded constructor accepts a value for the temperature and the wind speed and then calculates the value for the wind chill temperature (use the constants)Explanation / Answer
//WindChillCalculator.java
import java.io.*;
import java.util.*;
class WindChillCalculator
{
private static final double sym1=35.74; //first constant
private static final double sym2=0.4275; //Second constant
private double temperature;
private double windspeed;
private double windChillTemperature; //Stores the calculated windChillTemperature
//Default constructor
public WindChillCalculator()
{
temperature=0;
windspeed=0;
}
//Overloaded constructor
public WindChillCalculator(double t,double w)
{
temperature=t;
windspeed=w;
//Calculate windChillTemperature as per given formula
windChillTemperature=sym1+(0.6215*temperature)-35.75*(Math.pow(windspeed,0.16))+(sym2*temperature*Math.pow(windspeed,0.16));
System.out.println("WindChillTemperature :"+windChillTemperature);
}
//Setter method for temperature
public void setTemperature(double t)
{
if(temperature!=t)
{
temperature=t;
//Calculate windChillTemperature as per given formula
windChillTemperature=sym1+(0.6215*temperature)-35.75*(Math.pow(windspeed,0.16))+(sym2*temperature*Math.pow(windspeed,0.16));
System.out.println("Updated WindChillTemperature :"+windChillTemperature);
}
}
//Setter method for windspeed
public void setWindspeed(double w)
{
if(windspeed!=w)
{
windspeed=w;
//Calculate windChillTemperature as per given formula
windChillTemperature=sym1+(0.6215*temperature)-35.75*(Math.pow(windspeed,0.16))+(sym2*temperature*Math.pow(windspeed,0.16));
System.out.println("Updated WindChillTemperature :"+windChillTemperature);
}
}
//Getter method for temperature
public double getTemperature()
{
return temperature;
}
//Getter method for windspeed
public double getWindspeed()
{
return windspeed;
}
//toString() method returns both temperature and windspeed as a string with appropriate label
public String toString()
{
return "Temperature : "+temperature+" WindSpeed : "+windspeed;
}
}
//Wind.java
//Driver class with main() method for WindChillCalculator
import java.io.*;
import java.util.*;
public class Wind
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
WindChillCalculator w=new WindChillCalculator();
while(true)
{
//Taking choice from user and performing operation as per choice and displaying updated windChilltemperature and
//temperature and windspeed using toString() method
System.out.println("Choose your choice ");
System.out.println("1.Reset Temperature");
System.out.println("2.Reset Windspeed");
System.out.println("3.Reset Both");
System.out.println("Q.Exit");
char c=s.next().charAt(0);
if(c=='1')
{
System.out.println("Enter the Temperature:");
double t=s.nextDouble();
w.setTemperature(t);
System.out.println(w.toString());
}
else if(c=='2')
{
System.out.println("Enter the windspeed");
double wind=s.nextDouble();
w.setWindspeed(wind);
System.out.println(w.toString());
}
else if(c=='3')
{
System.out.println("Enter the Temperature:");
double t=s.nextDouble();
System.out.println("Enter the windspeed");
double wind=s.nextDouble();
//Create new object of WindChillCalculator with overloaded constructor and assign to w
w=new WindChillCalculator(t,wind);
System.out.println(w.toString());
}
else if(c=='Q')
{
break;
}
else
System.out.println("Wrong choice");
}
}
}
Output :
G580:~/codes/schegg$ javac WindChillCalculator.java
G580:~/codes/schegg$ javac Wind.java
G580:~/codes/schegg$ java Wind
Choose your choice
1.Reset Temperature
2.Reset Windspeed
3.Reset Both
Q.Exit
3
Enter the Temperature:
5.3
Enter the windspeed
6
WindChillTemperature :-5.567068455881625
Temperature : 5.3 WindSpeed : 6.0
Choose your choice
1.Reset Temperature
2.Reset Windspeed
3.Reset Both
Q.Exit
2
Enter the windspeed
5
Updated WindChillTemperature :-4.284786065563515
Temperature : 5.3 WindSpeed : 5.0
Choose your choice
1.Reset Temperature
2.Reset Windspeed
3.Reset Both
Q.Exit
1
Enter the Temperature:
4.6
Updated WindChillTemperature :-5.1069772369387145
Temperature : 4.6 WindSpeed : 5.0
Choose your choice
1.Reset Temperature
2.Reset Windspeed
3.Reset Both
Q.Exit
Q
G580:~/codes/schegg$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.