Added main class with some basic operations on templates with list;
This commit is contained in:
parent
f1f961dd14
commit
b0458db743
@ -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);
|
||||
}
|
||||
|
58
src/net/hypki/testjava/main/Templates.java
Normal file
58
src/net/hypki/testjava/main/Templates.java
Normal 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user