I'm new to java programming and this is my assignment. This is the code I've done but couldn't able to display the error message . When I execute the program I'm only getting the error message "Class room table cannot have irregular-shape table." but was not successful in getting the error message for sides and legs which should obviously be displayed."Error in setting legs . Number of legs cannot be less than 3." "Error in setting sides, number of sides cannot be 0".
Thanks for the help.
//Class ClassRoomTable is to model class room table //Class table is to model table class Table { //Error handling class. //An object of this class is thrown if //the number of legs for a table is less than 3. public class TooFewLegsError extends Exception // -- 2% { public TooFewLegsError(){ System.out.println("Error in setting legs . Number of legs cannot be less than 3."); } } //An object of this class is thrown if //the number of sides for a table is 0 public class ZeroSideError extends Exception // --- 1% { public ZeroSideError(){ System.out.println("Error in setting sides, number of sides cannot be 0"); } } //By default the number of legs for a table is 4, and //the number of sides for a table is also 4. private int legs=0; // number of legs private int sides=0; // number of sides //Default constructor of the table class. //By default the number of legs for a table is 4, and //the number of sides for a table is also 4. public Table() // --- 1% { } //A TooFewLegsError is thrown if the number of legs //for a table is less than 3, or a ZeroSideError is thrown //if the number of sides for a table is equal to 0 public Table(int legs1, int sides1) throws TooFewLegsError, ZeroSideError //---- 3% { if(legs1==2){ throw new TooFewLegsError(); }else if(sides1==0){ throw new ZeroSideError(); } } //A TooFewLegsError error is thrown if the //number of legs for a table is less than 3 public void setLegs(int legs1) throws TooFewLegsError // -- 2% { if(legs1<3){ throw new TooFewLegsError(); } } //A ZeroSideError error is thrown if the number //of sizes for a table is equal to 0 public void setSides(int sides1) throws ZeroSideError // -- 2% { if(sides1==0){ throw new ZeroSideError(); } } } public class ClassRoomTable extends Table { //Error handling class. //An object of this class is thrown if //the shape of a classroom table is irregular. public class IrregularShapeError extends Exception { public IrregularShapeError() { System.out.println("Class room table cannot have irregular-shape table.");; } } private int shape=1; // 1: rectangular //2: circle //3: triangle //4: irregular //An error is thrown if the shape is irregular public ClassRoomTable(int shape1) throws IrregularShapeError { // -- 2% if(shape1==4){ throw new IrregularShapeError(); } } //An error is thrown if the shape is irregular public void setShape(int shape1) throws IrregularShapeError { // -- 2% if(shape1==4){ throw new IrregularShapeError(); } } public static void main(String argv[]) { try { ClassRoomTable p = new ClassRoomTable(2); p.setShape(4); p.setSides(0); // This line will cause an exception p.setLegs(2); // This line will not be executed. } catch (ClassRoomTable.IrregularShapeError n) { System.out.println( "Class room table cannot have irregular-shape table."); } catch (Table.TooFewLegsError n) { System.out.println("Error in setting legs . Number of legs cannot be less than 3."); } catch (Table.ZeroSideError n) { System.out.println( "Error in setting sides, number of sides cannot be 0"); } } }