Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rectangle //object
- {
- int x1;
- int y1;
- int h1;
- int w1;
- public Rectangle (int x2, int y2, int w2, int h2)
- {
- h1 = h2;
- w1 = w2;
- x1 = x2;
- y1 = y2;
- }
- public int getHeight()
- {
- return h1;
- }
- public int getWidth()
- {
- return w1;
- }
- public int getX()
- {
- return x1;
- }
- public int getY()
- {
- return y1;
- }
- public static int Area(int w, int h)
- {
- return w*h;
- }
- public String toString()
- {
- return ("Rectangle[x=" + x1 + "," + " y=" + y1 + "," + " width=" + w1 + "," + " height=" + h1);
- }
- }
- import java.util.*;
- public class RectangleMain //main class
- {
- public void main(String[] args)
- {
- int x = scannerX();
- int y =scannerY();
- int w=scannerW();
- int h=scannerH();
- Rectangle r1 = new Rectangle(x,y,w,h);
- System.out.println("The top-left corner of the rectangle is (" + r1.getX() + "," + r1.getY() + ")");
- System.out.println("The width of the rectangle is " + r1.getWidth());
- System.out.println("The height of the rectangle is " + r1.getHeight());
- System.out.println("The area of the rectangle is " + r1.Area(w,h));
- System.out.println(toString());
- }
- public int scannerX()
- {
- Scanner xCoord = new Scanner(System.in);
- System.out.print("Type in an x-coordinate.");
- int x = xCoord.nextInt();
- System.out.println();
- return x;
- }
- public int scannerY()
- {
- Scanner yCoord = new Scanner(System.in);
- System.out.print("Type in a y-coordinate.");
- int y = yCoord.nextInt();
- System.out.println();
- return y;
- }
- public int scannerW()
- {
- Scanner width = new Scanner(System.in);
- System.out.print("Type in a width.");
- int w = width.nextInt();
- System.out.println();
- return w;
- }
- public int scannerH()
- {
- Scanner height = new Scanner(System.in);
- System.out.print("Type in a height.");
- int h = height.nextInt();
- System.out.println();
- return h;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment