Advertisement
Guest User

starofdavid

a guest
Oct 22nd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1.     public static Scanner reader = new Scanner(System.in);
  2.     public static void main(String[] args) {
  3.         // make variables for all of the Xs
  4.         int newX;
  5.         int newY;
  6.        
  7.         int Triangle1X = 50;
  8.         int Triangle1Y = 120;
  9.        
  10.         int l3X = Triangle1X+300; // because the third line starts at the end of the first line
  11.        
  12.         int Triangle2X = Triangle1X+150; // because it needs to be a bit forward
  13.         int Triangle2Y = Triangle1Y-65; // because it needs to be a bit below
  14.        
  15.         // the first triangle
  16.         Line l1 = new Line(Triangle1X, Triangle1Y, Triangle1X+300, Triangle1Y, "blue");
  17.         Line l2 = new Line(Triangle1X, Triangle1Y, Triangle1X+150, Triangle1Y+170, "blue");
  18.         Line l3 = new Line(l3X, Triangle1Y, l3X-150, Triangle1Y+170, "blue");
  19.        
  20.         // the second triangle
  21.         Line l4 = new Line(Triangle2X, Triangle2Y, Triangle2X+130, Triangle2Y+180, "blue");
  22.         Line l5 = new Line(Triangle2X, Triangle2Y, Triangle2X-130, Triangle2Y+180, "blue");
  23.         Line l6 = new Line(Triangle2X-130, Triangle2Y+180, Triangle2X+130, Triangle2Y+180, "blue");
  24.        
  25.         // prompt the user for the position set the star's position
  26.         System.out.print("Enter the value to add to X: ");
  27.         newX = reader.nextInt();
  28.        
  29.         System.out.print("Enter the value to add to Y: ");
  30.         newY = reader.nextInt();
  31.        
  32.         // erase all of the lines to draw new ones at the new location
  33.         l1.erase();
  34.         l2.erase();
  35.         l3.erase();
  36.         l4.erase();
  37.         l5.erase();
  38.         l6.erase();
  39.        
  40.         // move all of the lines to the new location
  41.         l1.move(newX, newY);
  42.         l2.move(newX, newY);
  43.         l3.move(newX, newY);
  44.         l4.move(newX, newY);
  45.         l5.move(newX, newY);
  46.         l6.move(newX, newY);
  47.        
  48.        
  49.         // after all of the lines were moved, draw them in their new location
  50.         l1.draw();
  51.         l2.draw();
  52.         l3.draw();
  53.         l4.draw();
  54.         l5.draw();
  55.         l6.draw();
  56.        
  57.         // notify the user of the change
  58.         System.out.println("Changed the position of the star to (" + (Triangle1X+newX) + "," + (Triangle1Y+newY) + ")");
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement