Describe each error and specify whether it is (a) lexical, (b) syntactic, or (c)
ID: 3785947 • Letter: D
Question
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.
1. class Thermometer 2. private int temperature 3. public Thermometer (int degrees) temperature degrees 6. public Thermometer temperature 0.0 9. public void makewarmer (int degrees) f temperature degrees; 10 12 public void makeCooler (int degrees) temperature degrees 13 14 15 public get Temperature f 16. return temperature 17 18. public string tostring return temperature degrees 19 20 21.Explanation / Answer
class Thermometer{
private int temperature // ; should be used to terminate the declaration, error is syntactic
public Thermometer(int degrees){
temperature = degrees;
}
public Thermometer(){
temperature = 0.0; // double value 0.0 is assigned to integer temperature, error is semantic
}
public void makeWarmer(int degrees){
temperature =+ degrees; // should be +=, error is lexical
}
public void makeCooler(int degrees){
temperature -= degrees;
}
public getTemperature(){ // return type not mentioned, error is syntactic
return temperature;
}
public string toString(){ // return should be with capital S, String, error is syntactic
return temperature + ' degrees'; // '' unclosed character literal, error is semantic
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.