Question: Java OOP coding question need Help! Please fully answer the question below. public class OOPLecture2 { /*** Note: We are abusing inner classes in this
Java OOP coding question need Help! Please fully answer the question below.
public class OOPLecture2 {
/*** Note: We are abusing inner classes in this assignment by defining multiple classes inside the * OOPLecture1 class. In most cases it is better practice to define each class in a separate file ***/
// Q1: Create an interface named "Boilable" containing an abstract method named boil() that takes no parameters and // has return type void. public interface Boilable{ public abstract void boil(); } // Q2: Create a concrete class named "Egg" that implements Boilable. The Egg class should have 1 instance variable // that is a String named "state" that is initialized to "raw" in the default constructor. Override its boil // to set the value of state to "hard boiled" public class Egg implements Boilable{ protected String state; public Egg(){ this.state = "raw"; } @Override public void boil(){ this.state = "hard boiled"; } @Override public String toString(){ if(this.state = "raw"){ System.out.println("this egg is raw"); } } } // Q3: Override Egg's toString method to print "this egg is raw" or "this egg is hard boiled" depending on the // state of the egg.
// Q4: Create a concrete class named "Potato" that implements Boilable. The Potato class should have 1 instance // variable that is a boolean named "soft" that is initialized to false in the default constructor. Override // its boil method to set the value of soft to true.
// Q5: Override Potato's toString method to return "this potato is hard" if soft is false and "this potato is soft" // if soft is true.
public static void main(String[] args) { // The following code is an example of testing these inner classes // Uncomment this code to test your classes
// OOPLecture2 outerInstance = new OOPLecture2(); // // Boilable egg = outerInstance.new Egg(); // Boilable potato = outerInstance.new Potato(); // // System.out.println(egg); // System.out.println(potato); // // System.out.println(" boiling... "); // egg.boil(); // potato.boil(); // // System.out.println(egg); // System.out.println(potato);
}
}
Note that after the toString() is where I stopped and there was mistake in what to do after that and that's where I need help to finish answering the questions PLEASE HELP.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
