下面是一个简单的javabeen
package com.jsu.man;
public class Goods {
private String brand;
private int price;
private String color;
public Goods() {
}
public Goods(String brand, int price, String color) {
this.brand = brand;
this.price = price;
this.color = color;
}
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 getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
package com.jsu.man;
import java.util.Scanner;
public class CarTest {
public static void main(String[] args) {
Goods[] arr=new Goods[3];
Scanner scan = new Scanner(System.in);
for (int i = 0; i < arr.length; i++) {
Goods c=new Goods();
System.out.println("请输入汽车的品牌");
String brand=scan.next();
c.setBrand(brand);
System.out.println("请输入汽车的价格");
int price =scan.nextInt();
c.setPrice(price);
System.out.println("请输入汽车的颜色");
String color= scan.next();
c.setColor(color);
arr[i]=c;
}
for (int i = 0; i < arr.length; i++) {
Goods car =arr[i];
System.out.println(car.getBrand()+","+car.getPrice()+","+car.getColor());
}
}
}