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

The following class contains several errors that violate the rules of Java: clas

ID: 3784474 • Letter: T

Question

The following class contains several errors that violate the rules of Java: class Thermometer {private int temperature public Thermometer(int degrees) {temperature = degrees;} public Thermometer() {temperature = 0.0;} public void makeWarmer(int degrees) {temperature degrees; public void makeCooler(int degrees) {temperature -= degrees;} public getTemperature () {return temperature;} public string tostring() {return temperature + ' degrees';}} Describe each error and specify whether it is (a) lexical, (b) syntactic, or (c) semantic. Use the numbers shown to identify the line on which each error occurs. The class may also contain programming errors that do not violate the rules of Java and will not be detected by a Java compiler. You should ignore these errors.

Explanation / Answer

Here are the errors identified for you:

class Thermometer {
   private int temperature   //Missing semicolon. Syntactic error.
   public Thermometer(int degrees)   {
       temperature = degrees;
   }
   public Thermometer()   {
       temperature = 0.0;   //A double value cannot be assigned to an integer. Semantic error.
   }
   public void makeWarmer(int degrees)   {
       temperature =+ degrees;   //=+ It should be +=. Semantic error.
   }      
   public void makeCooler(int degrees)   {
       temperature -= degrees;
   }
   public getTemperature()   {   //Should have a return type. Semantic error.
       return temperature;
   }
   public string tostring()   {   //Datatype in java is String, and not string. Lexical error.
       return temperature + ' degrees';   //A string should be represented in double quotes, and not single quotes. Lexical error.
   }
}  

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