Question: Shape.java: class Shape { //Attributes private int numOfSides; private String color; private boolean striped; //Constructors public Shape(int s,String c,boolean str) { numOfSides=s; color=c; striped=str; }

 Shape.java: class Shape { //Attributes private int numOfSides; private String color;

Shape.java:

class Shape { //Attributes private int numOfSides; private String color; private boolean striped; //Constructors public Shape(int s,String c,boolean str) { numOfSides=s; color=c; striped=str; } public Shape() { numOfSides=4; color="red"; striped=false; } //get methods public int getNumOfSides() { return numOfSides; } public String getColor() { return color; } public boolean getStriped() { return striped; } //set methods public void setNumOfSides(int n) { numOfSides=n; } public void setColor(String c) { color=c; } public void setStriped(boolean b) { striped=b; } //Methods public String toString() { return "numOfSides: "+numOfSides+" color: "+color+" striped: "+striped; } public boolean equals(Shape s) { if(this.numOfSides==s.getNumOfSides() && this.color.equals(s.getColor()) && this.striped==s.getStriped()) return true; return false; } }

RBG.java:

class RGB { private int R,G,B; public RGB() { this(0,0,0); } public RGB(int R,int G,int B) { this.R=R; this.G=G; this.B=B; } public int[] getColor() { return new int[]{R,G,B}; } public void setColor(int[] c) { R=c[0]; G=c[1]; B=c[2]; } public String toString() { return "("+R+","+G+","+B+")"; } public boolean equals(RGB r) { int[] c=r.getColor(); return (this.R==c[0]) && (this.G==c[1]) && (this.B==c[2]); } public RGB invert() { return new RGB(255-R,255-G,255-B); } }

2. Using the RGB class on blackboard we are going to update the Shape class. First read through the RGB.java file. Make sure you understand what each line is doing. How should we use RGB to modify the Shape class? Now update the color attribute in Shape to be an RGB object. You also need to modify the triangle and test classes. 3. Add an exception for checking if RGB values are outside [0,255). 4. Add an exception for checking if the sides of a triangle are valid. 5. Practice throwing and handling the exceptions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!