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: 3886584 • 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) { 10 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

Error 1 : Line 6 : Temperature is Integer and we are assigning it to float is semantic error because its not integer.

Error 2 : Line 15: : getTemperature is returning temperature but there is no return type i.e
public int getTemperature() is the correct syntax , so its a Syntax error.


Error 3 : Line 19 :: :temperature + &39 ... i.e &39 is not string and we are trying to concatenate so its a Lexical error
temperature + "&39" + ..... is the correct Lexical expression , so its a Lexical error.

Thanks, let me know if there is any doubt/concern.


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