【2011-10-07】创建一个表示汽车的JavaBean

【题目要求】

创建一个表示汽车的JavaBean,信息是(汽车品牌,价位,产地,生产商,销售电话)

创建一个使用该JavaBean的公共类


1.表示5种汽车信息的数组

2.打印信息清单

3.计算最贵的汽车并打印信息

4.把汽车按价位顺序打印

5. 使用InnerClass解决上述问题

【源程序】

OneCar.java(放在car文件夹下)

package car;

public class OneCar {
	
	private String brand;
	private int price;
	private String placeOfOrigin;
	private String salesTel;
	
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getPlaceOfOrigin() {
		return placeOfOrigin;
	}
	public void setPlaceOfOrigin(String placeOfOrigin) {
		this.placeOfOrigin = placeOfOrigin;
	}
	public String getSalesTel() {
		return salesTel;
	}
	public void setSalesTel(String salesTel) {
		this.salesTel = salesTel;
	}
	public OneCar(String brand, int price, String placeOfOrigin, String salesTel) {
		super();
		this.brand = brand;
		this.price = price;
		this.placeOfOrigin = placeOfOrigin;
		this.salesTel = salesTel;
	}

}


FiveKindsOfCars.java

/*
创建一个表示汽车的JavaBean,信息是(汽车品牌,价位,产地,销售电话)
创建一个使用该JavaBean的公共类
1.表示5种汽车信息的数组
2.打印信息清单
3.计算最贵的汽车并打印信息
4.把汽车按价位顺序打印
5. 使用InnerClass解决上述问题
*/

import car.OneCar;

public class FiveKindsOfCars {
    private OneCar[] cars = new OneCar[5];
    private boolean isIndexedByPrice = false;
    private int list[][];
    public FiveKindsOfCars(){
        cars[0] = new OneCar("Chevrolet Sonic",13735,"USA","800-001");
        cars[1] = new OneCar("Hyundai Sonata",19695,"German","800-002");
        cars[2] = new OneCar("Toyota Camry",21955,"Japan","800-003");
        cars[3] = new OneCar("Mercedes-Benz",34800,"China","800-004");
        cars[4] = new OneCar("Honda Accord",21380, "USA", "800-005");    
    }
    
    public void printHead()
    {
        System.out.println("Brand"+"\t\t"+"Price"+"\t"+"placeOfOrigin"+"\t"+"salesTel");
        System.out.println("=======         ======  =============   ==========");
    }
    public void printItem(OneCar i){
            System.out.println(i.getBrand()+"\t"+i.getPrice()+"\t"+i.getPlaceOfOrigin()+"\t\t"+i.getSalesTel());
    }
    

    private void indexByPrice(){
        list = new int [cars.length][2];
        for(int i=0; i


你可能感兴趣的:(Java练习题,string,list,class,电话,object)