-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
36 lines (29 loc) · 1.26 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public final class Main {
private Main() {
}
public static void main(String[] args) throws IOException {
// instantiez un obiect de tip Scanner pentru citire
Scanner scanner = new Scanner(new File(args[0]));
int n = Integer.parseInt(scanner.nextLine());
Shape[] shapes = new Shape[n];
// citesc fiecare linie si o transmit ca si parametru metodei createShape
// pentru a instantia un obiect de tipul specificat printre parametrii
for (int i = 0; i < n; i++) {
String[] shapeParameters = scanner.nextLine().split(" ");
shapes[i] = ShapeFactory.FACTORY.createShape(shapeParameters[0], shapeParameters);
}
// instantiez un vizitator de tipul DrawVisitor si vizitez fiecare Shape
DrawVisitor visitor = new DrawVisitor();
for (int i = 0; i < shapes.length; i++) {
shapes[i].accept(visitor);
}
// creez imaginea finala in format png
File output = new File("drawing.png");
ImageIO.write(visitor.getImg(), "PNG", output);
scanner.close();
}
}