המחלקה של האטרקציה | המחלקה של העיר | מחלקה ראשית |
---|---|---|
public class Atraction
{ private String name; private int type; // 1 הצגות // 2 kids , 3 exstrim , 4 food , 5 other private double price; public Atraction(String name, int type, double price) { this.name = name; this.type = type; if (price <0)price=0; this.price = price; } public Atraction(String name, double price) { this.name = name; this.type = 5; if (price <0)price=0; this.price = price; } public Atraction(String name) { this.name = name; this.type = 5; this.price = 0; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public double getPrice() { return this.price; } public void setPrice(double price) { int pass =0; if(price<0) price=0; this.price = price; } public int getType() { return this.type; } public void setType(int type) { this.type = type; } public String toString(){ String t="other"; if(type==1) t= " הצגות "; if(type==2) t= " kids "; if(type==3) t= " extrim "; if(type==4) t= " food "; return name +" price: "+ price + " type "+ t; } } |
import unit4.collectionsLib.Node; import unit4.collectionsLib.Stack; public class City { private String name; private Node public City(String name) { this.name = name; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public void addAtration(Atraction a) { head = new Node public void printAtractions(int op) // op 0 == כל האטרקציות { System.out.println("City :"+ name); Node double sum = 0; while (tmp != null) { if (op == 0 || op == tmp.getInfo().getType()) { System.out.println(tmp.getInfo()); sum = sum + tmp.getInfo().getPrice(); } tmp = tmp.getNext(); } System.out.println("total:"+sum); } public void rekursiya(Node if(tmp !=null) { rekursiya(tmp.getNext()); System.out.println(tmp.getInfo()); } } public void hafoch(){ System.out.println("\nHafoch()"); rekursiya(head); } } |
public class Program
{ static long atz(int i){ if (i==1) return 1; return i* atz(i-1); } public static void main(String[] args) { City[] citys = new City[5]; citys[0] = new City("hifa"); Atraction a = new Atraction("hagnim Habahaim"); citys[0].addAtration(a); citys[0].addAtration(new Atraction("Shipodim",4,70)); citys[0].addAtration(new Atraction("Gan Hahyot",2,30)); citys[0].addAtration(new Atraction("Racevel",3,50)); citys[0].addAtration(new Atraction("בית לסינג",1,70)); citys[0].printAtractions(0); citys[1] = new City("Tel aviv"); citys[1].addAtration(a); citys[1].addAtration(new Atraction("Shipodim",4,70)); citys[1].addAtration(new Atraction("Gan Hahyot",2,30)); citys[1].addAtration(new Atraction("Luna Park",3,150)); citys[1].addAtration(new Atraction("Habima",1,90)); citys[1].printAtractions(0); citys[1].hafoch(); System.out.println("atzert 15:"+atz(15)); } } |