小白ccc
2016-05-24 21:01
package com.imooc;
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input =new Scanner(System.in);
System.out.println("**********欢迎使用哒哒租车系统******");
System.out.println("您是否要租车:1.是 0.否");
int a=input.nextInt();
if(a==1){
}else{
System.exit(0);
}
System.out.println("序号 汽车名称 租金 容量");
Car[] carrent={new PassageCar(1,"奥迪a6",500,4),
new PassageCar(2,"马自达6",400,4),
new Pika(3,"皮卡雪6",450,4),
new PassageCar(4,"金龙",800,20),
new WeightCar(5,"松花江",400,4),
new WeightCar(6,"依维柯",1000,20)};
System.out.println("请输入您要租车的序号:");
int b=input.nextInt();
System.out.println("请输入您要租车的数量:");
int c=input.nextInt();
System.out.println("请输入您要租车的天数");
int d=input.nextInt();
while(true){
try{
switch(b){
case 1:
int count1=500*c*d;
System.out.println("您选择了奥迪a6,共承载"+c*4+"人");
System.out.println("您的账单:"+count1);
break;
case 2:
int count2 =400*c*d;
System.out.println("您选择了马自达6,共承载"+c*4+"人");
System.out.println("您的账单:"+count2);
break;
case 3:
int count3 =450*c*d;
System.out.println("您选择了皮卡雪,共承载"+c*4+"人");
System.out.println("您的账单:"+count3);
break;
case 4:
int count4 =800*c*d;
System.out.println("您选择了金龙,共承载"+c*20+"人");
System.out.println("您的账单:"+count4);
break;
case 5:
int count5 =400*c*d;
System.out.println("您选择了松花江,共承载"+c*4+"吨货物");
System.out.println("您的账单:"+count5);
break;
case 6:
int count6 =1000*c*d;
System.out.println("您选择了依维柯,共承载"+c*20+"吨货物");
System.out.println("您的账单:"+count6);
break;
}}catch(Exception e){
if(b==7){
System.out.println("您的输入有误,请从新输入:");}
}
System.exit(0);
}
}}
package com.imooc;
public class Car {
public int sno;
public String name;
public float price;
public int num;
}
package com.imooc;
public class PassageCar extends Car {
public PassageCar(){}
public PassageCar(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"人/位");
}
}
package com.imooc;
public class Pika extends Car{
public Pika(){}
public Pika(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"人/4吨");
}
}
package com.imooc;
public class WeightCar extends Car {
public WeightCar(){}
public WeightCar(int sno,String name,float price,int num){
this.sno=sno;
this.name=name;
this.price=price;
this.num=num;
System.out.println(sno+"\t"+name+"\t"+price+"/天"+"\t"+num+"吨");
}
}
对象名只是一个名字,new 类名()是真正的创建了一个对象。不知道你知不知道堆栈,对象名是存在堆空间的,它指向栈空间真正创建出来的new 类名()。
Car[] carrent={new PassageCar(1,"奥迪a6",500,4),new PassageCar(2,"马自达6",400,4),new Pika(3,"皮卡雪6",450,4),new PassageCar(4,"金龙",800,20),new WeightCar(5,"松花江",400,4),new WeightCar(6,"依维柯",1000,20)};
楼主你能帮讲解一下 carrent[0] = new PassageCar(1,"奥迪a6",500,4) 这个什么意思呢?
创建对象时候不是 类名 对象名 = new 类名() 吗?为什么可以不创建对象就可以用呢?
实在不会,不明白,请楼主讲解一下
你的各种汽车类型没有输出,怎么去选择
啥玩意啊
懒得吐槽了。。你比第一个还不如。这样弄上一堆代码咋看啊,还不加注释
写的不错嘛!
Java入门第二季 升级版
530653 学习 · 6091 问题
相似问题