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

Please read carfully this is for java object oriented design So i need two codes

ID: 3735965 • Letter: P

Question

Please read carfully this is for java object oriented design So i need two codes as instructed in the first 2 pages Using two classes, create a program that can convert a Fahrenheit temperature to Celsius and Kelvin. Temperature Class (Temperature.java) Should have one private field, a double, named fTemp. . Should have a no-arg constructor that simply initializes fTemp to 1. Should have a public mutator method named setTemperature that accepts a double as an argument. Name the parameter fTempln . This method should overwrite fTemp with the value of the argument passed in to the method o Should have a public accessor method named getTemperature that returns the value of fTemp. Should have a public accessor method named toCelsius that returns the temperature (value of fTemp) in Celsius. F to C conversion: (fTemp-32) * (5/9) .Should have a public accessor method named toKelvin that returns the temperature (value of fTemp) in Kelvin F to K conversion: (fTemp + 459.67) (5/9) . Neither the toCelsius or toKelvin method should overwrite or alter the value of the fTemp field. TemperatureDemo Class (TemperatureDemo.java) This is the class that will demo the Temperature class you created; thus, it contains the main In the main method method.

Explanation / Answer

Temperature.java

public class Temperature {

//Declaring instance variable

private double fTemp;

//Zero argumented constructor

public Temperature() {

this.fTemp = 1;

}

// getters and setters

public void setTemperature(double fTempin) {

this.fTemp = fTempin;

}

public double getTemperature() {

return fTemp;

}

//This method will convert Fahrenheit to Celsius

public double toCelsius()

{

return (fTemp-32)*(5.0/9.0);

}

//This method will convert Kelvin to Celsius

public double toKelvin()

{

return (fTemp+459.67)*(5.0/9.0);

}

}

_________________

TemperatureDemo.java

import java.util.Scanner;

public class TemperatureDemo {

public static void main(String[] args) {

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Creating an Instance of Temperature class

Temperature t=new Temperature();

//Getting the input entered by the user

System.out.print("Enter the temperature in Fahrenheit(F) :");

double tempF=sc.nextDouble();

t.setTemperature(tempF);

//Displaying the output

System.out.printf("You entered Temperature in Fahrenheit (F):%.2f ",t.getTemperature());

System.out.printf("Temperature in Celsius (C):%.2f ",t.toCelsius());

System.out.printf("You entered Temperature in Fahrenheit (F):%.2f ",t.toKelvin());

}

}

______________________

Output:

Enter the temperature in Fahrenheit(F) :50
You entered Temperature in Fahrenheit (F):50.00
Temperature in Celsius (C):10.00
You entered Temperature in Fahrenheit (F):283.15

______________Thank You

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