Added main class with some basic operations on templates with list;

This commit is contained in:
Arkadiusz Hypki 2023-03-28 16:55:05 +02:00
parent f1f961dd14
commit b0458db743
2 changed files with 63 additions and 0 deletions

View File

@ -8,6 +8,11 @@ public class Square extends Figure {
setName("Square");
}
public Square(double x) {
super("Square");
setX(x);
}
public Square(String name) {
setName(name);
}

View File

@ -0,0 +1,58 @@
package net.hypki.testjava.main;
import java.util.ArrayList;
import java.util.List;
import net.hypki.testjava.figures.Area;
import net.hypki.testjava.figures.Circle;
import net.hypki.testjava.figures.Figure;
import net.hypki.testjava.figures.Rectangle;
import net.hypki.testjava.figures.Square;
import net.hypki.testjava.figures.Triangle;
public class Templates {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("jeden");
list.add("dwa");
for (String s : list) {
System.out.println("ELEMENT " + s);
}
//=======================================
List<Square> squares = new ArrayList<Square>();
squares.add(new Square(5));
squares.add(new Square(10));
squares.add(new Square(20));
for (Square s : squares) {
System.out.println("Square " + s);
}
//=======================================
List<Figure> figures = new ArrayList<>();
figures.add(new Square(5));
figures.add(new Circle(5));
figures.add(new Rectangle(5, 6));
// figures.add(new Triangle(5, 10));
for (Figure s : figures) {
System.out.println("Figure " + s);
}
//=======================================implements Area
List<Area> areas = new ArrayList<>();
areas.add(new Square(5));
areas.add(new Circle(5));
areas.add(new Rectangle(5, 6));
areas.add(new Triangle(5, 10));
for (Area s : areas) {
System.out.println("Figure " + s.computeArea());
}
}
}