Question
While trying to do a project assigned in myprogramminglab, I received this unhelpful message when I submitted my java code: CODELAB ANALYSIS: LOGICAL ERROR(S) Problems
While trying to do a project assigned in myprogramminglab, I received this unhelpful message when I submitted my java code:
CODELAB ANALYSIS: LOGICAL ERROR(S)
Problems Detected: The contents of your standard output is incorrect.
Given the following was entered from the keyboard: 23 72 F 22 F you displayed: instead of: Invoking default constructor: Temperature obj1; getTempC= 0.0 getTempF= 32.0 getScale= C Enter a temperature to create an object with the second constructor:getTempC= 23.0 getTempF= 73.4 getScale= C Enter a temperature space F or C to create an object with the third constructor:getTempC= 22.2 getTempF= 72.0 ...
The 'you displayed is blank', so I don't even know where to begin to correct the code to what they want. Here is the full problem:
Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F' for Fahrenheit. The class should have - Four constructors : one for the number of degrees, one for the scale, one for both the degrees and the scale, and a default constructor . For each of these constructors , assume zero degrees if no value is specified and Celsius if no scale is given . - Two accessor methods : one to return the temperature in degrees Cel- sius, the other to return it in degrees Fahrenheit. Use the formulas from Practice Program 5 of Chapter 3 and round to the nearest tenth of a degree. - Three set methods : one to set the number of degrees, one to set the scale, and one to set both. - Three comparison methods : one to test whether two temperatures are equal , one to test whether one temperature is greater than another, and one to test whether one temperature is less than another. Write a driver program that tests all the methods . Be sure to invoke each of the constructors , to include at least one true and one false case for each comparison method , and to test at least the following three temperature pairs for equality: 0.0 degrees C and 32.0 degrees F, ?40.0 degrees C and ?40.0 degrees F, and 100.0 degrees C and 212.0 degrees F.
The formula mentioned is:"Degrees_C=5(Degrees_F-32)/9" and "Degrees_F=(9(Degrees_C)/5)+32)"
This is my code:
class Temperature { private double degrees; private char scale; public Temperature() { degrees = 0.0; scale = 'C'; } public Temperature(double newDegrees) { degrees = newDegrees; scale = 'C'; } public Temperature(char newScale) { degrees = 0.0; scale = newScale; } public Temperature(double newDegrees, char newScale) { degrees = newDegrees; scale = newScale; }
public double getDegreesC () { double val = scale == 'C' ? degrees : 5 * (degrees - 32) / 9; return Math.round (val * 10.0) / 10.0; } public double getDegreesF () { double val = scale == 'F' ? degrees : 9 * (degrees / 5) + 32; return Math.round (val * 10.0) / 10.0; } public void setDegrees(double newDegrees) { degrees = newDegrees; } public void setScale (char newScale) { scale = newScale;; } public void setDegreesAndScale (double newDegrees, char newScale) { degrees = newDegrees; scale = newScale; }
public boolean isEqualTo (Temperature newTemp) { if(scale == 'C') { if(newTemp.scale == 'C') return(degrees == newTemp.degrees); else return(degrees == newTemp.getDegreesC()); } else { if(newTemp.scale == 'F') return(degrees == newTemp.degrees); else return(degrees == newTemp.getDegreesF()); } } public boolean isGreaterThan (Temperature newTemp) { if(scale == 'C') { if(newTemp.scale == 'C') return(degrees > newTemp.degrees); else return(degrees > newTemp.getDegreesC()); } else { if(newTemp.scale == 'F') return(degrees > newTemp.degrees); else return(degrees > newTemp.getDegreesF()); } }
public boolean isLessThan (Temperature newTemp) { if(scale == 'C') { if(newTemp.scale == 'C') return(degrees < newTemp.degrees); else return(degrees < newTemp.getDegreesC()); } else { if(newTemp.scale == 'F') return(degrees < newTemp.degrees); else return(degrees < newTemp.getDegreesF()); } }
public String toString() { return degrees + "\u00b0" + scale; } }
class TemperatureTest { public static void main(String[] args) { Temperature temp1 = new Temperature(0.0, 'C'); Temperature temp2 = new Temperature(32.0, 'F'); Temperature temp3 = new Temperature(-40.0); Temperature temp4 = new Temperature(-40.0, 'F'); Temperature temp5 = new Temperature(20.0, 'C'); Temperature temp6 = new Temperature(100.0, 'C'); Temperature temp7 = new Temperature(212.0); temp3.setScale('C'); temp7.setScale('F'); System.out.println("Temperature " + temp1.toString() + " < " + temp6.toString() + " = true " + temp1.isLessThan(temp6)); System.out.println("Temperature " + temp1.toString() + " < " + temp2.toString() + " = false " + temp1.isLessThan(temp2)); System.out.println("Temperature " + temp5.toString() + " > " + temp7.toString() + " = false " + temp5.isGreaterThan(temp7)); System.out.println("Temperature " + temp5.toString() + " > " + temp1.toString() + " = true " + temp5.isGreaterThan(temp1)); System.out.println("Temperature " + temp1.toString() + " = " + temp2.toString() + " = true " + temp1.isEqualTo(temp2)); System.out.println("Temperature " + temp3.toString() + " = " + temp4.toString() + " = true " + temp3.isEqualTo(temp4)); System.out.println("Temperature " + temp6.toString() + " = " + temp7.toString() + " = true " + temp6.isEqualTo(temp7)); } }
I've searched other solutions on this site, and myprogramminglab accepts none of them. I'm at a bit of a loss and hope someone can help. Any ideas?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started