Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have following methods: public void setFields(int newx, int newy,

Write a Java class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have following methods:

public void setFields(int newx, int newy, int newwidth, int newheight)

Set the values for the fields in the Rectangle objects whose top-left corner is specified by the given x and y coordinates and by the width and height.

public int getHeight()

Returns the Rectangles height.

public int getWidth()

Returns the Rectangles width.

public int getX()

Returns the Rectangles x-coordinate

public int getY()

Returns the Rectangles y-coordinate

public String toString()

Returns a String representation of this Rectangle, such as Rectangle [x=2, y=13, height =14, width =5]

Write a client program called RectangleClient that creates objects of the Rectangle class called rect1 and rect2. Assign values to the fields of these objects. Print out these Rectangle objects using System.out.println() method.

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

Logics For Databases And Information Systems

Authors: Jan Chomicki ,Gunter Saake

1st Edition

1461375827, 978-1461375821

More Books

Students also viewed these Databases questions

Question

=+4. What are their reputations?

Answered: 1 week ago