问答详情
源自:12-1 综合练习

求老师给我点建议

package com.zuche;

import java.util.Scanner;


public class Cshi {


public static void main(String[] args) {//主函数需要定义几个量

//1载人车名     2  载货车名    3载人数量    4 载货数量       5每天租金

// TODO Auto-generated method stub

String Cname = "   ";

String Hname = "   ";

int   Cren = 0 ;

int   Cliang =  0;

float zujin = 0;

System.out.println("欢迎使用达达租车系统:");

System.out.println("您是否需要租车:1 是 ; 0 否");

Scanner ip = new Scanner(System.in);

if (ip.nextInt() == 1){

System.out.println("您可租车的类型及价目表:");

System.out.println("序号    " + "汽车名称         "   +"租金                  "   + "容量" );

Xcar car1 = new Xcar();

System.out.println("1. "  + car1.name +"   "  + car1.price+ "元/天" +"   "+"载人:"+ car1.Sliang+"人");

//输出奥迪A4的表单

Carmzd car2 = new Carmzd();//创建了马自达6对象

System.out.println("2. "  + car2.name +"   "  + car2.price+ "元/天" +"   "+"载人:"+ car2.Sliang+"人");

Pka car3 = new Pka();//创建了皮卡雪6对象

System.out.println("3. "  + car3.name +"   "  + car3.price+ "元/天" +"   "+"载人:"+ car3.zairen+"人"+"载货:"+ car3.zaihuo+"吨");

Dbus car4 = new Dbus();//创建了  金龙  大巴对象

System.out.println("4. "  + car4.name +"   "  + car4.price+ "元/天" +"   "+"载人:"+ car4.Sliang+"人");

Xhuo car5 = new Xhuo();//创建了松花江   小货车对象

System.out.println("5. "  + car5.name +"   "  + car5.price+ "元/天" +"   "+"载货:"+ car5.Sliang+"吨");

Dhuo car6 = new Dhuo();//创建了松花江   大货车对象

System.out.println("6. "  + car6.name +"   "  + car6.price+ "元/天" +"   "+"载货:"+ car6.Sliang+"吨");

//表单打出来之后 就需要提示请输入的车辆数量

           //首先判断人家是否需要租车

//如果需要租车,再进入循环判断给每次租车赋值

System.out.println("请输入您需要租多少辆车");

Scanner ip3 = new Scanner(System.in);

int num = ip3.nextInt();

if(num > 0 && num <7){

for(int i = 1; i <= num;i++){

System.out.println("请输入您选择的第" + i +"辆车");

Scanner ip4 = new Scanner(System.in);

int a = ip4.nextInt();

if ( a== 1){//若租车判断人家第一辆租哪辆车

Cname =Cname+"   "+car1.name;

zujin = zujin+car1.price;

Cren = Cren+car1.Sliang;

}

if (a == 2){

Cname =Cname+"   "+car2.name;

zujin = zujin+car2.price;

Cren = Cren+car2.Sliang;

}

if (a == 3){

Cname =Cname+"   "+car3.name;

Hname =Hname+"   "+car3.name;

zujin = zujin+car3.price;

Cren = Cren+car3.zairen;

Cliang =Cliang+ car3.zaihuo;

}

if (a == 4){

Cname =Cname+"   "+car4.name;

zujin = zujin+car4.price;

Cren =Cren+ car4.Sliang;

}

if (a == 5){

Hname =Hname+"   "+car5.name;

zujin = zujin+car5.price;

Cliang =Cliang+ car5.Sliang;

}

if (a == 6){

Hname =Hname+"   "+car6.name;

zujin = zujin+car6.price;

Cliang = Cliang+car6.Sliang;

}

}

}

else if(ip.nextInt() == 2){

System.exit(0);

}


System.out.println("****您所选择的载人车型有:");

System.out.println(Cname+ "共计载人数:" + Cren);

System.out.println("****您所选择的载货车型有:");

System.out.println(Hname+ "共计载重量:" + Cliang);

System.out.println("请输入您需要租赁的天数:");

Scanner ip5 = new Scanner(System.in);

float tian  = ip5.nextFloat();

System.out.println("您的租金为:" + zujin * tian);

}

}


}


提问者:慕粉3874958 2017-09-11 16:39

个回答

  • 许秀军
    2017-09-12 09:47:14

    看视频吧  没怎么使用多态