Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Scanner reader = new Scanner(System.in);
- public static void main(String[] args) {
- // make variables for all of the Xs
- int newX;
- int newY;
- int Triangle1X = 50;
- int Triangle1Y = 120;
- int l3X = Triangle1X+300; // because the third line starts at the end of the first line
- int Triangle2X = Triangle1X+150; // because it needs to be a bit forward
- int Triangle2Y = Triangle1Y-65; // because it needs to be a bit below
- // the first triangle
- Line l1 = new Line(Triangle1X, Triangle1Y, Triangle1X+300, Triangle1Y, "blue");
- Line l2 = new Line(Triangle1X, Triangle1Y, Triangle1X+150, Triangle1Y+170, "blue");
- Line l3 = new Line(l3X, Triangle1Y, l3X-150, Triangle1Y+170, "blue");
- // the second triangle
- Line l4 = new Line(Triangle2X, Triangle2Y, Triangle2X+130, Triangle2Y+180, "blue");
- Line l5 = new Line(Triangle2X, Triangle2Y, Triangle2X-130, Triangle2Y+180, "blue");
- Line l6 = new Line(Triangle2X-130, Triangle2Y+180, Triangle2X+130, Triangle2Y+180, "blue");
- // prompt the user for the position set the star's position
- System.out.print("Enter the value to add to X: ");
- newX = reader.nextInt();
- System.out.print("Enter the value to add to Y: ");
- newY = reader.nextInt();
- // erase all of the lines to draw new ones at the new location
- l1.erase();
- l2.erase();
- l3.erase();
- l4.erase();
- l5.erase();
- l6.erase();
- // move all of the lines to the new location
- l1.move(newX, newY);
- l2.move(newX, newY);
- l3.move(newX, newY);
- l4.move(newX, newY);
- l5.move(newX, newY);
- l6.move(newX, newY);
- // after all of the lines were moved, draw them in their new location
- l1.draw();
- l2.draw();
- l3.draw();
- l4.draw();
- l5.draw();
- l6.draw();
- // notify the user of the change
- System.out.println("Changed the position of the star to (" + (Triangle1X+newX) + "," + (Triangle1Y+newY) + ")");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement