为什么我用数组调用属性的值调用不过来,运行的时候值为空,不知道为什么
package com.dadachuzuche;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
public class Text {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Cat van =new Van(1,"奥迪",500,4);
Cat van1=new Van(2,"马自达6", 400, 4);
Cat van2=new Van(3,"金龙", 800, 20);
Cat passengcar=new Passengercar(4,"松花江",400,4);
Cat passengcar1=new Passengercar(5,"依维柯",1000,20);
Cat pk1=new Pk(6,"皮卡雪6",450,4,2);
Cat[] cat2={van,van1,van2,passengcar,passengcar1,pk1};//存车的对象
int cat;//判断是否要租车
int maneysum=0;
int mansum=0;
int zhongliangsum=0;
int today;
int number;//定义汽车的数量
int i;
int cat1;//定义输入的车辆序号
Scanner san=new Scanner(System.in);//实例化键盘输入信息
System.out.println("欢迎使用答答租车系统");
System.out.println("请是否要要租车:1是 0否");
cat=san.nextInt();//键盘获取的值赋值给cat
switch (cat=1) {//菜单展示全部数据
case 1:
System.out.println("您可租车的类型及其价格表如下");
case 2:
System.out.println("序号 汽车名称 租金 容量");
case 3:
System.out.println("1。奥迪A4 500元/天 载人:4人");
case 4:
System.out.println("2。马自达 400元/天 载人:4人");
case 5:
System.out.println("3。皮卡雪6 450元/天 载人:4人 载货:2吨");
case 6:
System.out.println("4。金龙 800元/天 载人:20人");
case 7:
System.out.println("5。松花江 400元/天 载货4吨");
case 8:
System.out.println("6。依维柯 1000元/天 载货20吨");
break;
default:
System.out.println("输入信息为否,欢迎下次使用答答租车");
break;
}
System.out.println("请输入您要租汽车的数量:");
number=san.nextInt();//获取车的数量
Cat[] cat3=new Cat[number];//定义一个数组来转要租车的序号
for(i=0;i<number;i++){//
System.out.println("请输入第"+(i+1)+"辆车序号");
cat1=san.nextInt();
cat3[i]=cat2[cat1-1];
if(cat1<0||cat1>7){
System.out.println("输入的车辆序号有误,请重新输入");
cat1=san.nextInt();
}
};
System.out.println("请输入要租的天数:");
today=san.nextInt();
System.out.println("**** 可用的车有:");
System.out.println("您租用的车载人的有:");
for(int h=0;h<cat3.length;h++){
cat3[h].show();
}
for(int j=0;j<cat3.length;j++){
System.out.println("您租用车的名字:"+cat3[j].getName()+"");
}
System.out.println("您的车载人数:"+mansum);
System.out.println("您的车载货数:"+zhongliangsum);
System.out.println("您的车租用的钱数:"+(zhongliangsum*today));
}
/*System.out.println("**** 可用的车有:");
System.out.println("您的账单是:"+(maneysum*today)+"元"+"总载货量"+zhongliangsum+"总人数"+mansum);
*/
}
父类
public abstract class Cat {
int id;
String name;
int maney;
int zrs;
int vsnzh;
public abstract void show();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getManey() {
return maney;
}
public void setManey(int maney) {
this.maney = maney;
}
public int getZrs() {
return zrs;
}
public void setZrs(int zrs) {
this.zrs = zrs;
}
public int getVsnzh() {
return vsnzh;
}
public void setVsnzh(int vsnzh) {
this.vsnzh = vsnzh;
}
载货的车
public class Passengercar extends Cat {
private int id;
private String name;
private int maney;
private int vsnzh;
public Passengercar(int Newid,String Newname, int Newmaney, int Newvanzh) {
// TODO Auto-generated constructor stub
this.id=Newid;
this.maney=Newmaney;
this.name=Newname;
this.vsnzh=Newvanzh;
}
public void show(){
System.out.println(name+ maney+"/天"+"载货:"+vsnzh+"吨");
}
}
PK的车:
public class Pk extends Cat {
private int id;
private String name;
private int maney;
private int zrs;
private int vsnzh;
public Pk(int Newid,String Newname, int Newmaney, int Newzrs, int Newvsnzh) {
// TODO Auto-generated constructor stub
this.id=Newid;
this.maney=Newmaney;
this.name=Newname;
this.vsnzh=Newvsnzh;
this.zrs=Newzrs;
}
public void show() {
// TODO Auto-generated method stub
System.out.println(name+ maney+"/天"+"载货:"+vsnzh+"吨" +"载人"+zrs);
}
}
载人的车:
public class Van extends Cat{
private int id;
private String name;
private int maney;
private int zren;
public Van(int Newid,String Newname, int Newmaney, int Newzren) {
// TODO Auto-generated constructor stub
this.name=Newname;
this.id=Newid;
this.maney=Newmaney;
this.zren=Newzren;
}
public void show(){
System.out.println(name+ maney+"/天"+"载人:"+zren+"人");
}
}