Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in Java*** Task 1: Create a class Rectangle. Create a class Rectangle that has the properties width and height. Be sure to create accessor

image text in transcribedimage text in transcribed

Code in Java***

Task 1: Create a class Rectangle. Create a class Rectangle that has the properties width and height. Be sure to create accessor and mutator methods for both of these properties. Create two constructors: Rectangle() - Sets the width and height to both 1 Rectangle(int w, int h) Sets the width to the parameter w and the height to the parameter h Write the methods getArea() and getPerimeter(). - These methods should return the area and perimeter, respectively. Tips: 1. Area of a rectangle = height of rectangle * width of rectangle 2. Perimeter of rectangle= 2 * (height of rectangle + width of rectangle) Task 2: Create static methods Write a static method addRectangles(Rectangle r1, Rectangle r2) that takes two Rectangle objects and adds their lengths and heights and returns a new Rectangle object. For example, if you have two Rectangle objects: Rectangle ri = new Rectangle(4,5) and Rectangle r2 = new Rectangle(2,5) The return value would be a new Rectangle with width = 6 and height = 10; Task 3: JUnit tests Create a class Rectangle Test that uses Junit to test each of the methods in your rectangle class. - Test each constructor. - Test the methods getArea() and getPerimeter(). Challenge (2 bonus points -- MUST be completed during class) Override the method checkEqual (Rectangle ri, Rectangle r2) in the Object class. It should return true if the two Rectangle objects have the same width and length, otherwise false. Please include a JUnit test

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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

3. Explain the forces that influence how people handle conflict

Answered: 1 week ago