Please see if there are any errors to this code and if so make corrections and a
ID: 3822855 • Letter: P
Question
Please see if there are any errors to this code and if so make corrections and also provide a screenshot of the following code: *File: Toaster.java *Author:Jaime Jones *Date: April 21,2015 *Class: CMIS 141 7982 */ public class Toaster { private String color; private boolean hasToased; //construcotr public Toaster() { this.color="White"; this.hasToased=true; } public void toast() { this.color="Red"; this.hasToased=!this.hasToased; } public String status() { return "Color of bread is "+this.color+" and toaster is "+this.hasToased; } public static void main(String[] args) { //creating object of toaster class Toaster t=new Toaster(); //calling methods System.out.println(t.status()); t.toast(); System.out.println(t.status()); } }
Explanation / Answer
Note:I dont see any errors in this program.Executing perfectly.
____________________
Toaster.java
public class Toaster {
private String color;
private boolean hasToased;
// constructor
public Toaster() {
this.color = "White";
this.hasToased = true;
}
public void toast() {
this.color = "Red";
this.hasToased = !this.hasToased;
}
public String status() {
return "Color of bread is " + this.color + " and toaster is "
+ this.hasToased;
}
public static void main(String[] args) {
// creating object of toaster class
Toaster t = new Toaster();
// calling methods
System.out.println(t.status());
t.toast();
System.out.println(t.status());
}
}
_________________
Output:
Color of bread is White and toaster is true
Color of bread is Red and toaster is false
________________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.