I have to write a code for class that takes in a temperature value, converts it to kelvin, and then determines if this is greater than, equal to, less than, or whatever to another entered temp. It has to say true or false for each of the boolean possibilities. I can't get it to compare the temperature that is set as t1, with the temperature t that the boolean methods take as a parameter? Any suggestions? Also, quit downvoting me, I know I don't know what I'm doing thats why I asked the queston. I started learning Java last week, I know that I'm not good at it?
public class Temperature {
public double degrees;
public static void main(String[] args) {
}
Temperature (){
degrees=0;
}
Temperature (double enteredtemp){
degrees = enteredtemp;
}
Temperature (double enteredtemp,char scale ){
Temperature t1 = new Temperature (enteredtemp, scale);
t1.set(enteredtemp,scale);
}
public void set (double enteredtemp, char scale){
if (scale == 'r'|| scale == 'R'){ degrees = (enteredtemp/(9/5));}
else if (scale == 'c'|| scale == 'C') {degrees = enteredtemp+273.15;}
else if (scale =='F'|| scale == 'f'){degrees = ((enteredtemp+459.67)*9/5);}
}
public double get(){
return degrees;
}
public double get(char scale){
if (scale == 'c'|| scale == 'C'){degrees = (degrees-273.15);}
else if (scale == 'r'||scale == 'R'){degrees = (degrees*(9/5));}
else if (scale == 'f'|| scale == 'F'){degrees = (degrees*(9/5)-459.67);}
return (degrees);
}
public boolean isLessThan(Temperature t){
if (t.get() < t1.get())
return true;
else {
return false;
}
}
public boolean isGreaterThan(Temperature t){
if (t.get() > t1.get()) {
return true;
}
else {
return false;
}
}
public boolean isEqual(Temperature t){
if ((Math.abs(t.get() - t1.get()))<=10E-12){
return true;
}
else {
return false;
}
}
public boolean isGreaterThanOrEqual(Temperature t){
if (t.get() >= t1.get()){
return true;
}
else {
return false;
}
}
public boolean isLessThanorEqual(Temperature t){
if (t.get() <= t1.get()){
return true;
}
else {
return false;
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…