Source Code Structure

  1. Create a new project with the name "Lab4".
  2. Create a new package with the name "lab4".
  3. Create the following classes:
    • Point.java: You will need to implement the constructor and methods of the Point class in this file.
    • Rectangle.java : You will need to implement the constructor and methods of the Rectangle class in this file.
    • Lab4.java:
      • Select create the static main method stub. Note that only Lab4.java contains the main method, so only generate a main method stub for Lab4.java.
      • Copy and paste the following code into Lab4's main method. In your main method, the test code will retrieve coordinates of a rectangle from the user and display the length, width, area, and perimeter of that rectangle.
/*
  Scanner scanner = new Scanner(System.in);
  int x = 1;
  int y = 1;

  System.out.print("Enter the x-coordinate of the upperLeft :");
  x = scanner.nextInt();
  System.out.print("Enter the y-coordinate of the upperLeft :");
  y = scanner.nextInt();

  Point upperLeft = new Point(x, y);

  
  System.out.print("Enter the x-coordinate of the lowerLeft :");
  x = scanner.nextInt();
  System.out.print("Enter the y-coordinate of the lowerLeft :");
  y = scanner.nextInt();

  Point lowerLeft = new Point(x, y);
  
  
  System.out.print("Enter the x-coordinate of the lowerRight :");
  x = scanner.nextInt();
  System.out.print("Enter the y-coordinate of the lowerRight :");
  y = scanner.nextInt();

  Point lowerRight = new Point(x, y);
  
  
  System.out.print("Enter the x-coordinate of the upperRight:");
  x = scanner.nextInt();
  System.out.print("Enter the y-coordinate of the upperRight:");
  y = scanner.nextInt();

  Point upperRight = new Point(x, y);
  
  Rectangle rectangle = new Rectangle(upperLeft, lowerLeft, lowerRight, upperRight);

  System.out.printf("Length of rectangle : %.2f\n", rectangle.getLength());
  System.out.printf("Width of rectangle : %.2f\n", rectangle.getWidth());
  System.out.printf("Area of rectangle : %.2f\n", rectangle.getArea());
  System.out.printf("Perimeter of rectangle : %.2f\n", rectangle.getPerimeter());

  //test the copy constructor
  Rectangle rectangleNew = new Rectangle(rectangle);
  
  System.out.printf("Length of rectangleNew : %.2f\n", rectangleNew.getLength());
  System.out.printf("Width of rectangleNew : %.2f\n", rectangleNew.getWidth());
  System.out.printf("Area of rectangleNew : %.2f\n", rectangleNew.getArea());
  System.out.printf("Perimeter of rectangleNew : %.2f\n", rectangleNew.getPerimeter());

*/