Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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; 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started