大明狗
2015-08-06 08:39
package com.imooc;
public abstract class Car {
public abstract void showMessageAll();{
}
}
---------------------------------------------------------------------------------------
package com.imooc;
public class AutoCar extends Car {
String Auto1="奥迪";
int AM1=500;
int AP=4;
String Auto2="马自达";
int AM2=400;
String Auto3="金龙";
int AM3=800;
int AP2=20;
@Override
public void showMessageAll() {
// TODO Auto-generated method stub
System.out.println("1. "+Auto1+" "+AM1+"元/天 载客量"+AP+"人");
System.out.println("2. "+Auto2+" "+AM2+"元/天 载客量"+AP+"人");
System.out.println("3. "+Auto3+" "+AM3+"元/天 载客量"+AP2+"人");
}
public void showMessage1()
{
System.out.println("1. "+Auto1+" "+AM1+"元/天 载客量"+AP+"人");
}
public void showMessage2()
{
System.out.println("2. "+Auto2+" "+AM2+"元/天 载客量"+AP+"人");
}
public void showMessage3()
{
System.out.println("3. "+Auto3+" "+AM3+"元/天 载客量"+AP2+"人");
}
}
-----------------------------------------------------------------------------------------------------
package com.imooc;
public class Track extends Car {
String track1="松花江";
int tm1=400;
int tg1=4;
String track2="依维柯";
int tm2=1000;
int tg2=20;
@Override
public void showMessageAll() {
// TODO Auto-generated method stub
System.out.println("4. "+track1+" "+tm1+"元/天 载货量"+tg1+"吨");
System.out.println("5. "+track2+" "+tm2+"元/天 载货量"+tg2+"吨");
}
public void showMessage1()
{
System.out.println("4. "+track1+" "+tm1+"元/天 载货量"+tg1+"吨");
}
public void showMessage2()
{
System.out.println("5. "+track2+" "+tm2+"元/天 载货量"+tg2+"吨");
}
--------------------------------------------------------------------------------------------------------
package com.imooc;
public class Special extends Car {
String specialName1="皮卡雪";
int sm1=450;
int sp1=4;
int sg1=2;
@Override
public void showMessageAll() {
// TODO Auto-generated method stub
System.out.println("6. "+specialName1+" "+sm1+"元/天 载人量"+sp1+"人 载货量"+sg1+"吨");
}
public void showMessage1()
{
System.out.println("6. "+specialName1+" "+sm1+"元/天 载人量"+sp1+"人 载货量"+sg1+"吨");
}
}
---------------------------------------------------------------------------------------------------------------
package com.imooc;
import java.util.Scanner;
public class ZuChe {
public void show(){ //显示租车信息
System.out.println("您可租车的类型和项目表");
System.out.println("num name money peoplenum");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Car auto1=new AutoCar();
Car track1=new Track();
Car special1=new Special();
ZuChe show1=new ZuChe();
// TODO Auto-generated method stub
System.out.println("欢迎使用答答租车系统!"); //欢迎界面
System.out.println("是否进入系统?/n是 1 否 0"); //防误选阶段
int num= scanner.nextInt();
if(num==1) //选车阶段
{
show1.show();
auto1.showMessageAll();
track1.showMessageAll();
special1.showMessageAll();
}else
System.out.println("Over!");
System.out.println("请输入您要租车的数量");
Scanner s=new Scanner(System.in);
int carNum=s.nextInt();
int[] carNum2=new int[carNum];
for(int a=0;a<carNum;a++)
{
System.out.println("请您输入第"+(a+1)+"量车的序号");
int num2=s.nextInt();
carNum2[a]=num2;
}
System.out.println("请您输入租车的天数");
int carDays=s.nextInt();
System.out.println("您的账单有");
AutoCar auto2=new AutoCar();
Track track2=new Track();
Special special2=new Special();
int sumMoney=0;
for(int a=0;a<carNum;a++)
{
switch(carNum2[a])
{
case 1:{
auto2.showMessage1();
sumMoney+=auto2.AM1;
}break;
case 2:{
auto2.showMessage2();
sumMoney+=auto2.AM2;
}break;
case 3:{
auto2.showMessage3();
sumMoney+=auto2.AM3;
}break;
case 4:{
track2.showMessage1();
sumMoney+=track2.tm1;
}break;
case 5:{
track2.showMessage2();
sumMoney+=track2.tm2;
}break;
case 6:{
special2.showMessage1();
sumMoney+=special2.sm1;
}break;
}
}
System.out.println("总共的金额为:"+(sumMoney*carDays));
}
}
在第三季中会重点讲,你还没有看到,所以看不懂没关系,在你能力范围之内能看懂就好了,主要是面向对象的思路,我自己写的也很渣,和大神那个思路也不同,不过看了他的后感觉学习了好多,加油
这个可以用集合框架知识 会简单点 希望对你用帮助
我自己写完了以后才看大神的代码的,感觉整体上都和我的思路不太相同啊。。而且很多方法本人都看不懂
Java入门第二季 升级版
530656 学习 · 6091 问题
相似问题