Advertisement
lpuarmy

Segiempat | oope

Jun 4th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.awt.Point;
  2. public class Segiempat {
  3. int x1 = 0;
  4. int y1 = 0;
  5. int x2 = 0;
  6. int y2 = 0;
  7.  
  8. public void buatSegiempat(int x1, int y1, int x2, int y2) {
  9. this.x1 = x1;
  10. this.y1 = y1;
  11. this.x2 = x2;
  12. this.y2 = y2;
  13. }
  14. public void buatSegiempat(Point topLeft, Point bottomRight) {
  15. x1 = topLeft.x;
  16. y1 = topLeft.y;
  17. x2 = bottomRight.x;
  18. y2 = bottomRight.y;
  19. }
  20. public void buatSegiempat(Point topLeft, int w, int h) {
  21. x1 = topLeft.x;
  22. y1 = topLeft.y;
  23. x2 = (x1 + w);
  24. y2 = (y1 + h);
  25. }
  26. void cetakSegiempat(){
  27. System.out.print("Segiempat: <" + x1 + ", " + y1);
  28. System.out.println(", " + x2 + ", " + y2 + ">");
  29. }
  30. public static void main(String[] arguments) {
  31. Segiempat rect = new Segiempat();
  32. System.out.println("Buat segiempat dengan koordinat (25,25) dan (50,50)");
  33. rect.buatSegiempat(25, 25, 50, 50);
  34. rect.cetakSegiempat();
  35. System.out.println();
  36. System.out.println("Buat segiempat dengan point (10,10) dan point (20,20):");
  37. rect.buatSegiempat(new Point(10,10), new Point(20,20));
  38. rect.cetakSegiempat();
  39. System.out.println();
  40. System.out.print("Buat segiempat dengan 1 point (10,10), koodinat (50,50)");
  41. rect.buatSegiempat(new Point(10,10), 50, 50);
  42. rect.cetakSegiempat();
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement