not sure exactly on how many files to make any help on suggestions would be grea
ID: 3646887 • Letter: N
Question
not sure exactly on how many files to make any help on suggestions would be great or guidespublic interface Colorable {
public void howToColor ();
}//Interface Colorable end
public class GeometricObject {
public GeometricObject () {
}//Cconstructor end
} //class GeometricObject end
import javax.swing.JOptionPane;
public class Square extends GeometricObject implements Colorable {
public Square () {
}//Square end
public void howToColor () {
JOptionPane.showMessageDialog(null, "Color all four sides!");
} // howToColor end
} class howToColor End
//TEst Program
import javax.swing.JOptionPane;
public class TestColorableObject {
public static void main(String[] args) {
GeometricObject[] objects = new GeometricObject[5];
objects[0] = new Square();
objects[1] = new GeometricObject();
objects[2] = new Square();
objects[3] = new GeometricObject();
objects[4] = new Square();
for (int i = 0; i < objects.length; i++) {
GeometricObject object = objects[i];
JOptionPane.showMessageDialog(null, "Object [ " + i + " ] ");
if (object instanceof Colorable) {
Colorable colorable = (Colorable) object;
colorable.howToColor();
}else {
JOptionPane.showMessageDialog(null, " NOT COLORABLE!");
} //end else
} //end for
}
Explanation / Answer
4 files will b use 1- for interface public interface Colorable { public void howToColor (); } 2- for Class GeometricObject public class GeometricObject { public GeometricObject () { }//Cconstructor end } //class GeometricObject end 3- for class Square import javax.swing.JOptionPane; public class Square extends GeometricObject implements Colorable { public Square () { }//Square end public void howToColor () { JOptionPane.showMessageDialog(null, "Color all four sides!"); } // howToColor end } class howToColor End 4- for Test Program //TEst Program import javax.swing.JOptionPane; public class TestColorableObject { public static void main(String[] args) { GeometricObject[] objects = new GeometricObject[5]; objects[0] = new Square(); objects[1] = new GeometricObject(); objects[2] = new Square(); objects[3] = new GeometricObject(); objects[4] = new Square(); for (int i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.