I. Write a class definition for a Rectangle class that contains:

· Two int fields, length and width.

· Mutator and accessor methods for the length and width fields.

· A Boolean method named isSquare that returns true if the rectangle’s length and width are the same and false otherwise.

II. Write a class definition for a RectangleDriver class that contains a main method that acts as a driver for the Rectangle class of the previous problem. The main method should do this:

· Construct a Rectangle object named rect.

· Use the mutator methods to prompt the user for values to rect’s length and width fields.

· Use the Boolean method to determine if rect is a square.

o If rect is a square, print “Square: ” and then the square’s dimensions. For example:

Square: 4×4

o If rect is not a square, print “Rectangle: ” and then the rectangle’s dimensions. For example:

Rectangle: 6×13

· In printing the above messages, use the accessor methods to retrieve the rectangle’s dimensions.

III. Add a print method to the rectangle class, which prints a rectangle of asterisks corresponding to the dimensions of the rectangle; if the width is greater than 40 or the height is greater than 24 instead of printing the rectangle with asterisks, display the message “too big to print”.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *