Vector和Stack

託帕發表於2018-09-05
import java.util.*;
public class Test1 {
	public static void main(String[] args){
		Vector cc=new Vector();
		Sp sp1=new Sp("001","巧克力",20f);
		Sp sp2=new Sp("002","果脯",10f);
		
		cc.add(sp1);
		cc.add(sp2);
		
		for(int i=0;i<cc.size();i++){
			System.out.println(((Sp)cc.get(i)).getMingcheng());
		}
		
		System.out.println();

		Stack dd=new Stack();
		Sp sp3=new Sp("001","香蕉",20f);
		Sp sp4=new Sp("002","蘋果",10f);
		
		dd.add(sp3);
		dd.add(sp4);
		
		for(int i=0;i<cc.size();i++){
			System.out.println(((Sp)dd.get(i)).getMingcheng());
		}
		
	}
}

class Sp{
	private String bianhao;
	private String mingcheng;
	private float jiage;

	Sp(String bianhao,String mingcheng,float jiage){
		this.bianhao=bianhao;
		this.mingcheng=mingcheng;
		this.jiage=jiage;
	}

	public String getBianhao() {
		return bianhao;
	}

	public void setBianhao(String bianhao) {
		this.bianhao = bianhao;
	}

	public String getMingcheng() {
		return mingcheng;
	}

	public void setMingcheng(String mingcheng) {
		this.mingcheng = mingcheng;
	}

	public float getJiage() {
		return jiage;
	}

	public void setJiage(float jiage) {
		this.jiage = jiage;
	}	
}

相關文章