Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a driver that allows the user to enter a temperature in either Celsius or

ID: 3886510 • Letter: W

Question

Write a driver that allows the user to enter a temperature in either Celsius or Fahrenheit and then prints the temperature value in Fahrenheit, and Celsius along with the wind chill index. Allow the user to change the value of the temperature (either scale) and the speed of the wind in miles per hour. Then display the same information anytime the user changes a value. Allow the user to continue changing values until they enter a ‘q’ or ‘Q’ to quit Create only ONE instance of the WindChill class and one instance of the TemperatureConversion class. After that, call the appropriate set( ) methods. Validate user input for the following input: Allow only: T or t to change temperature S or s to change wind speed F or f for Fahrenheit C or c for Celsius

Explanation / Answer

//WindChill class to compute the wind chill with temperature in Fahrenheit

public class WindChill {

double temperature;

double windspeed;

double windchill;

public double getTemperature() {

return temperature;

}

public void setTemperature(double temperature) {

this.temperature = temperature;

}

public double getWindspeed() {

return windspeed;

}

public void setWindspeed(double windspeed) {

this.windspeed = windspeed;

}

public double getWindchill() {

return windchill;

}

public void setWindchill() {

this.windchill = 35.74 + 0.6215*this.temperature + (0.4275*this.temperature - 35.75) * Math.pow(this.windspeed, 0.16);

}

}

-----------------------------------------------------------------------------------------------------------------------------------------------

import java.util.Scanner;

public class TemperatureConversion {

double degreeFahrenheit;

double degreeCelsius;

public double getDegreeFahrenheit() {

return degreeFahrenheit;

}

public void setDegreeFahrenheit(double degreeFahrenheit) {

this.degreeFahrenheit = degreeFahrenheit;

this.degreeCelsius=5 * (degreeFahrenheit -32)/9;

}

public double getDegreeCelsius() {

return degreeCelsius;

}

public void setDegreeCelsius(double degreeCelsius) {

this.degreeCelsius = degreeCelsius;

this.degreeFahrenheit = degreeCelsius * 9/5 + 32;

}

public static void main(String[] args)

{

Scanner keyboard = new Scanner(System.in);

  

TemperatureConversion tc=new TemperatureConversion();

WindChill wc=new WindChill();

char quit = 'n'; //Program loop control

// - set up to enter while loop

// - repeat unless it is 'Q' or 'q'

double degrees,windspeed; // user input

char units; // user input: 'F' or 'f' for Fahrenheit

// or 'C' or 'c' for Celsius

while(quit != 'Q' && quit != 'q')

{

System.out.println();//Blank lines for readability

System.out.println();

System.out.println

("Enter a temperature in degrees (for example 30.6): ");

degrees = keyboard.nextDouble();

System.out.println();

System.out.println

("Enter 'F' (or 'f') for Fahrenheit or "

+ "'C' (or 'c') for Celsius: ");

units = keyboard.next().charAt(0);

System.out.println();

  

System.out.println();

System.out.println

("Enter the speed of the wind in miles per hour");

windspeed = keyboard.next().charAt(0);

System.out.println();

switch(units)

{

case 'F':

case 'f':

tc.setDegreeFahrenheit(degrees);

wc.setTemperature(degrees);

wc.setWindspeed(windspeed);

wc.setWindchill();

System.out.println(degrees + " degrees F = "

+ tc.getDegreeCelsius() + " degrees Celsius.");

System.out.println("Wind Chill "+ wc.getWindchill());

break;

case 'C':

case 'c':

tc.setDegreeCelsius(degrees);

wc.setTemperature(tc.getDegreeFahrenheit());

wc.setWindspeed(windspeed);

wc.setWindchill();

System.out.println(degrees + " degrees C = "

+ tc.getDegreeFahrenheit()

+ " degrees Fahrenheit.");

System.out.println("Wind Chill "+ wc.getWindchill());

break;

default:

System.out.println("Unknown units -");

System.out.println(" cannot do calculation -");

System.out.println(" next time enter either "

+ "'F' for Fahrenheit or 'C' for Celsius.");

} //end switch

System.out.println();

System.out.println("Enter 'Q' to quit or any other character");

System.out.println(" to perform another temperature conversion.");

quit = keyboard.next().charAt(0);

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote