I have to create a class that represents a rectangle. A rectangle is specified by the coordinates (x; y) of its top-left corner and its width and height.
This class will be used to create many rectangle objects, and it must feature:
{ dynamic fields (variables) to store x, y, the width and the height as fractional numbers;
{ a constructor with parameters that provide x, y, the width and the height;
{ a function that returns the area of the rectangle;
{ a function that returns the length of the perimeter of the rectangle; and
{ a function that returns a string representation of the rectangle, the four numbers, within a pair
of parentheses, separated by commas. This function must be named toString().
Write, in a separate Main class, a main method that accepts the four numbers as command line
arguments, instantiates a rectangle object, and prints the string representation of the rectangle, the area and the perimeter.
1
Expert's answer
2015-08-18T05:09:48-0400
public class MainClass {
public static void main(String[] args) {//topLeftX,topLeftY,width,height
Comments
Leave a comment