Advertisement
Guest User

wahahahahaha

a guest
Apr 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import java.lang.*;
  2. import java.util.*;
  3.  
  4. public class Rectangle{
  5. private MyPoint upperLeft;
  6. private MyPoint lowerRight;
  7.  
  8. public Rectangle(){
  9. this.upperLeft = new MyPoint();
  10. this.lowerRight = new MyPoint();
  11. }
  12.  
  13. public Rectangle(MyPoint upperLeft, MyPoint lowerRight){
  14. this.upperLeft = upperLeft;
  15. this.lowerRight = lowerRight;
  16. }
  17.  
  18. public MyPoint getupperLeft(){
  19. return upperLeft;
  20. }
  21.  
  22. public MyPoint getlowerRight(){
  23. return lowerRight;
  24. }
  25.  
  26. public void setupperLeft(MyPoint upperLeft){
  27. this.upperLeft = upperLeft;
  28. }
  29.  
  30. public void setlowerRight(MyPoint lowerRight){
  31. this.lowerRight = lowerRight;
  32. }
  33.  
  34. public double length(){
  35. double x1, x2;
  36. x1=upperLeft.getX();
  37. x2=lowerRight.getX();
  38. return x1>x2?((x1-x2)):((x2-x1));
  39. }
  40.  
  41. public double width(){
  42. double y1, y2;
  43. y1=upperLeft.getY();
  44. y2=lowerRight.getY();
  45. return y1>y2?((y1-y2)):((y2-y1));
  46. }
  47.  
  48. public double area(){
  49. return length() * width();
  50. }
  51.  
  52. public double perimeter(){
  53. return (length()+width())*2;
  54. }
  55.  
  56. public static void main(String[] args){
  57. Scanner yey = new Scanner(System.in);
  58. Rectangle recta = new Rectangle();
  59. int x1, x2, y1, y2;
  60.  
  61. System.out.println("nPoint A");
  62. System.out.print("nEnter coordinates x1: ");
  63. x1 = yey.nextInt();
  64. System.out.print("Enter coordinates y1: ");
  65. y1 = yey.nextInt();
  66. MyPoint point1 = new MyPoint(x1, y1);
  67. recta.setupperLeft(point1);
  68.  
  69. System.out.println("nPoint B");
  70. System.out.print("nEnter coordinates x2: ");
  71. x2 = yey.nextInt();
  72. System.out.print("Enter coordinates y2: ");
  73. y2 = yey.nextInt();
  74. MyPoint point2 = new MyPoint(x2, y2);
  75. recta.setlowerRight(point2);
  76.  
  77. System.out.print("nnLength: " + recta.length());
  78. System.out.print("nnWidth: " + recta.width());
  79. System.out.print("nArea: " + recta.area());
  80. System.out.print("nPerimeter: " +recta.perimeter());
  81. System.out.print("nn");
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement