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

I cannot get my pubilc static void to work. This is what i have? import java.uti

ID: 3653936 • Letter: I

Question


I cannot get my pubilc static void to work. This is what i have?


import java.util.*;

public class Temperature

{

private String scale;

private float temp;

/***************************************************************/

public Temperature()

{

scale = "Celcius";

temp = 0;

}

public Temperature(float newTemp)

{

if (scale.equalsIgnoreCase("C"))

{

float temp = (5 * (newTemp - 32) / 9);

newTemp = temp;

}

else if (scale.equalsIgnoreCase("F"))

{

float temp = (9 * (newTemp / 5 ) + 32 );

newTemp = temp;

}

else

System.out.println ("You entered an incorrect temperature scale. Converion can not be done. Try again.");

}

public Temperature(String newScale)

{

if (scale.equalsIgnoreCase("C"))

newScale = "Celcius";

else if (scale.equalsIgnoreCase("F"))

newScale = "Fahrenheit";

else

System.out.println ("You entered an incorrect temperature scale. Try again.");

}

public Temperature(String newScale, float newTemp)

{

if (scale.equalsIgnoreCase("C"))

{

newScale = "Celcius";

float temp = (5 * (newTemp - 32) / 9);

newTemp = temp;

}

else if (scale.equalsIgnoreCase("F"))

{

newScale = "Fahrenheit";

float temp = (9 * (newTemp / 5 ) + 32 );

newTemp = temp;

}

else

System.out.println ("Oops, something went wrong. Try again.");

}


/***************************************************************/

public String toString ()

{

return ("The temperature scale you entered is: " + scale + " "

+ "The number of degrees you entered is: " + temp + " ");

}

/***************************************************************/

public void readInput()

{

Scanner keyboard = new Scanner(System.in);

System.out.println("What is the degree system which you are using? Enter the first letter.");

scale = keyboard.nextLine();

String newScale = scale;

System.out.println("What is the number of degrees?");

temp = keyboard.nextFloat();

float newTemp = temp;

}

/***************************************************************/

/***************************************************************/

public void writeOutput()

{

System.out.println("Temperature scale that you are using: " + scale + " ");

System.out.println("Number of degrees: " + temp + " ");

}

/***************************************************************/

/***************************************************************/

public void setTemp(float newTemp)

{

temp = newTemp;

}

public void setScale(String newScale)

{

scale = newScale;

}

public void setTempAndScale(String newScale, float newTemp)

{

temp = newTemp;

scale = newScale;

}

/***************************************************************/

/***************************************************************/

public String getScale( )

{

return scale;

}

public float getTemp( )

{

return temp;

}

public String getTempAndScale( )

{

return (temp + scale);

}


/***************************************************************/

/***************************************************************/

public static void main(String[] args)

{

Temperature trialOne = new Temperature();

Scanner keyboard = new Scanner(System.in);

trialOne.readInput();

trialOne.writeOutput();

System.out.println("Set Scale is: "+ scale);

System.out.println("Set Temp is: "+ temp);

}


/***************************************************************/

/***************************************************************/

}


thanks for the help

Explanation / Answer


public class Temperature
{

private double temperature;
private char scale;

public Temperature()
{
setTemperatureAndScale('C', 0.0);
}

public Temperature(double temp)
{
setTemperatureAndScale('C', temp);
}

public Temperature (char scale)
{
setTemperatureAndScale(scale, 0.0);
}

public Temperature(char scale, double temp)
{
setTemperatureAndScale(scale, temp);
}

public double getTemperatureInCelsius()
{
if(scale == 'C')
return temperature;
else
return (temperature - 32)*5/9;

}

public double getTemperatureInFahrenheit()
{
if(scale == 'F')
{
return temperature;
}
else
return temperature * 9/5 + 32;
}

public void setTemperature(double temp)
{
temperature = temp;
}

public void setScale(char scale)
{
if(scale == 'C' || scale == 'F')
this.scale = scale;
else
throw new IllegalArgumentException("Scale input is wrong");
}

public void setTemperatureAndScale(char scale, double temp)
{
setTemperature(temp);
setScale(scale);
}

public static boolean isEqual(Temperature temp1, Temperature temp2)
{
if(temp1.getTemperatureInCelsius() == temp2.getTemperatureInCelsius())
return true;
else
return false;
}

public static boolean isGreater(Temperature temp1, Temperature temp2)
{
if(temp1.getTemperatureInCelsius() > temp2.getTemperatureInCelsius())
return true;
else
return false;
}

public static boolean isLesser(Temperature temp1, Temperature temp2)
{
if(temp1.getTemperatureInCelsius() < temp2.getTemperatureInCelsius())
return true;
else
return false;
}

public String toString()
{
return String.format("%.1f %c ", temperature , scale );
}
}

public class DriverTemperature
{

public static void main(String[] args)
{
Temperature temp1 = new Temperature();
Temperature temp2 = new Temperature('F');
Temperature temp3 = new Temperature(-40);
Temperature temp4 = new Temperature('F',-40);
Temperature temp5 = new Temperature('C',100);
Temperature temp6 = new Temperature('F',212);
temp1.setTemperatureAndScale('C', 0);
temp2.setTemperature(32);
temp3.setScale('C');

System.out.printf("%s is equal to %s : %b ",
temp1,temp2,Temperature.isEqual(temp1, temp2));
System.out.printf("%s is greater than %s : %b ",
temp1,temp2,Temperature.isGreater(temp1, temp2));
System.out.printf("%s is less than %s : %b ",
temp1,temp2,Temperature.isLesser(temp1, temp2));

System.out.printf("%s is equal to %s : %b ",
temp3,temp4,Temperature.isEqual(temp3, temp4));
System.out.printf("%s is greater than %s : %b ",
temp3,temp4,Temperature.isGreater(temp3,temp4));
System.out.printf("%s is less than %s : %b ",
temp3,temp4,Temperature.isLesser(temp3,temp4));

System.out.printf("%s is equal to %s : %b ",
temp5,temp6,Temperature.isEqual(temp5,temp6));
System.out.printf("%s is greater than %s : %b ",
temp5,temp6,Temperature.isGreater(temp5,temp6));
System.out.printf("%s is less than %s : %b ",
temp5,temp6,Temperature.isLesser(temp5,temp6));



}

}

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