Answered step by step
Verified Expert Solution
Link Copied!

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; }

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago