AOOP Lab day 1

October 31, 2013 3:01 pm Java

Flower.java

package folwer;
public class Flower {
 
	public Flower() {}
 
	public Flower(String fname,int price) {
		 this.fname = fname;
		 this.price = price;
	}
 
	public String getFname() {
		return fname;
	}
	public void setFname(String fname) {
		this.fname = fname;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
 
	public String getDetail() {
		return "Flower";
	}
 
	private String fname;
	private int price;
 
}

FlowerMain.java

package folwer;
public class FlowerMain {
 
	public static void main(String[] args) {
		SunFlower sun1 = new SunFlower("SunFlower",1);
 
		Tulip tul1 = new Tulip();
		tul1.setFname("myTulip");
		tul1.setPrice(5);
 
		Flower orc1 = new Orchid();
		orc1.setFname("myOrchid");
		orc1.setPrice(6);
 
		Flower fArray[] = new Flower[5];
		fArray[0] = sun1;
		fArray[1] = tul1;
		fArray[2] = orc1;
 
		for(int i=0;i<=2;i++) {
			System.out.println(fArray[i].getFname()+" : "+fArray[i].getPrice());	
		}
 
		/*
		System.out.println(sun1.getFname());
		System.out.println(sun1.getPrice());
		System.out.println(tul1.getFname());
		System.out.println(tul1.getPrice());
		System.out.println(orc1.getFname());
		System.out.println(orc1.getPrice());
		*/
	}
 
}

Orchid.java

package folwer;
 
public class Orchid extends Flower{
 
	public Orchid() {}
 
		public Orchid(String fname, int price) {
		super(fname, price);
	}
		public String getDetail() {
			return "Orchid";
 
		}
 
		private String fname = "Orchid";
		private int price =6;
}

SunFlower.java

package folwer;
 
public class SunFlower extends Flower{
 
 
	public SunFlower(String fname, int price) {
		super(fname, price);
	}
 
	public String getDetail() {
		return "SunFlower";
 
	}
 
	private String fname = "SunFlower";
	private int price =1;
 
}

Tulip.java

package folwer;
 
public class Tulip extends Flower{
 
	public Tulip() {}
	public Tulip(String fname, int price) {
		super(fname, price);
	}
	public String getDetail() {
		return "Tulip";
 
	}
 
	private String fname = "Tulip";
	private int price =5;
 
}