继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Java入门第二阶段6.1达达租车系统

Muse_ye
关注TA
已关注
手记 1
粉丝 2
获赞 0
package imook_dada;

abstract class Car {

	int price;

	public abstract void showInfro();

}

abstract class keche extends Car{

	int zaike;

	public abstract void showInfro();

}

public class dakeche extends keche{

	String name = new String("大客车");

	dakeche(){

		this.price = 400;

		this.zaike = 10;

	}

@Override

	public void showInfro() {

		// TODO Auto-generated method stub

		System.out.println("2." + name + " " + zaike + "人 " + price + "元/天");

	}

}

public class xiaokeche extends keche{

	String name = new String("小客车");

	xiaokeche(){

		this.price = 200;

		this.zaike = 5;

	}

@Override

	public void showInfro() {

		// TODO Auto-generated method stub

		System.out.println("1." + name + " " + zaike + "人 " + price + "元/天");

	}

}

public abstract class huoche extends Car{

	int zaihuo;

	public abstract void showInfro();

}

public class xiaohuoche extends huoche{

	String name = new String("小货车");

	xiaohuoche(){
	
	this.price = 300;

	this.zaihuo = 5;

	}

	@Override

	public void showInfro() {

		// TODO Auto-generated method stub

		System.out.println("3." + name + " " + zaihuo + "吨 " + price + "元/天");

	}

}

public class dahuoche extends huoche{

	String name = new String("大货车");

	dahuoche(){

		this.price = 700;

		this.zaihuo = 20;

	}

@Override

	public void showInfro() {
	
		// TODO Auto-generated method stub

		System.out.println("4." + name + " " + zaihuo + "吨 " + price + "元/天");

	}

}

public class pika extends Car{

	int zake;

	int zaihuo;

	String name = new String("皮卡");

	pika(){

		this.price = 300;

		this.zaihuo = 2;

		this.zake = 4;

	}

@Override

	public void showInfro() {

		// TODO Auto-generated method stub

		System.out.println("5." + name + " " + zaihuo + "吨 " + zake + "人 " + price + "元/天");

	}

}

//下面是租车程序

package imook_dada;

import java.util.Scanner;



public class Dadarent {

static int totalNum = 0;

static int totalPrice = 0;

static int choise = 0;

static int carType = 0;

static int carNum = 0;

static xiaokeche Dada_xiaokeche = new xiaokeche();

static dakeche Dada_dakeche = new dakeche();

static xiaohuoche Dada_xiaohuoche = new xiaohuoche();

static dahuoche Dada_dahuoche = new dahuoche();

static pika Dada_pika = new pika();

static Scanner sc = new Scanner(System.in);

static int[] carPrice = {200,400,300,700,300};//录入车辆的价格,与序号对应

public static void main(String[] args) {

// TODO Auto-generated method stub

String Start = new String("请问您是否需要租车?\n 1.是    2.否");

String Service1 = new String("本公司提供如下车型:");

String Service2 = new String("请选择您想要租的车型");

String Service3 = new String("请输入您想要租的数目:");

String Service4 = new String("请问您是否想要继续租车?\n 1.是    2.否");

String Service5 = new String("您一共需要支付:");

String notation = new String("请输入正确选项,谢谢合作");

String Goodbey = new String("感谢您使用达达租车系统,再见。");

System.out.println(Start);

choise = sc.nextInt();

System.out.println(choise);

while(choise !=1 && choise !=2) {

System.out.println(notation);

System.out.println(Service2);

choise = sc.nextInt();

}

if(choise == 2) {

System.out.println(Goodbey);

return ;

}

else {

while(choise == 1) {

System.out.println(Service1);

Dada_showInfro();

System.out.println(Service2);

carType = sc.nextInt();

System.out.println(Service3);

carNum = sc.nextInt();

totalPrice += carPrice[carType-1] * carNum;

System.out.println(Service4);

choise = sc.nextInt();

}

System.out.println(Service5 + totalPrice);

System.out.println(Goodbey);

return ;

}

}

public static void Dada_showInfro() {

Dada_xiaokeche.showInfro();

Dada_dakeche.showInfro();

Dada_xiaohuoche.showInfro();

Dada_dahuoche.showInfro();

Dada_pika.showInfro();

}



}


​
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP