看看我这个怎样?

来源:12-2 项目问题解析 1

慕粉4206482

2016-10-23 11:07

package CarRental;


public class Car {

    int Carnumber;

String CarName;

int CarRebtal;

int MannedQuantity;

int cargo;



}

package CarRental;


public class Audi extends Car {

public  Audi(int Carnumber,String CarName,int CarRebtal,int MannedQuantity){

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

}


}

package CarRental;


public class Iveco extends Car {

public Iveco(int Carnumber, String CarName, int CarRebtal, int MannedQuantity) {

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

}


}

package CarRental;


public class JinLong extends Car {

public JinLong(int Carnumber, String CarName, int CarRebtal, int MannedQuantity) {

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

}


}

package CarRental;


public class Mazda extends Car {

public Mazda(int Carnumber,String CarName,int CarRebtal,int MannedQuantity){

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

}


}

package CarRental;


public class PickupSnow extends Car {

public PickupSnow (int Carnumber, String CarName, int CarRebtal, int MannedQuantity,int cargo) {

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

this.cargo = cargo;


}


}

package CarRental;


public class SongHuaJing extends Car {

public SongHuaJing (int Carnumber, String CarName, int CarRebtal, int MannedQuantity) {

this.Carnumber = Carnumber;

this.CarName = CarName;

this.CarRebtal = CarRebtal;

this.MannedQuantity = MannedQuantity;

}


}

package CarRental;


import java.io.StreamCorruptedException;

import java.util.ArrayList;

import java.util.Collection;

import java.util.Scanner;


import javax.swing.plaf.synth.SynthSpinnerUI;

import javax.swing.plaf.synth.SynthSplitPaneUI;


public class Test {


public static void main(String[] args) {

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

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

Scanner c = new Scanner(System.in);

int k = c.nextInt();

if (k == 1) {

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

Car[] CarType = { new Audi(1,"奥迪A6",500,4), 

new Mazda(2,"馬自達6",400,4), new PickupSnow(3,"雪福來",450,4,2), new JinLong(4,"金龍",400,4), new SongHuaJing(5,"松花江",400,4),new Iveco(6,"依維柯",1000,20) };

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

for (Car Type : CarType) {

if(Type instanceof Audi ){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+ "載人"+Type.MannedQuantity + "人");

}

if(Type instanceof Mazda){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+"載人"+ Type.MannedQuantity + "人");

}

if(Type instanceof PickupSnow){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+ "載人"+Type.MannedQuantity + "人"+"載貨"+Type.MannedQuantity+"吨");

}

if(Type instanceof JinLong){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+ "載人"+Type.MannedQuantity + "人");

}

if(Type instanceof SongHuaJing){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+"載貨"+ Type.MannedQuantity+"吨");

}

if(Type instanceof Iveco){

System.out.println(Type.Carnumber + "\t" + Type.CarName + "\t" + Type.CarRebtal + "天" + "\t"+ "載貨"+Type.MannedQuantity+"吨");

}

}

System.out.println("请输入您要租车的数量:");

int Carnum = c.nextInt();

int Rent = 0;

int TotalRent =0;

String CarName = null;

int Manned = 0;

int Cargo = 0;

int TotalManned = 0;

int TotalCargo = 0;

int m = 0;

int n = 0;

String[] book = new String[Carnum];

String[] books = new String[Carnum];

for(int i = 0;i<Carnum;i++){

System.out.println("请输入第"+(i+1)+"辆车的序号:");

int num = c.nextInt();

switch(num){

case 1:

Rent = 500;

CarName = "奥迪A6";

Manned = 4;

Cargo = 0;

break;

case 2:

Rent = 400;

CarName = "马自达6";

Manned = 4;

Cargo = 0;

break;

case 3:

Rent = 450;

CarName = "皮卡雪6";

Manned = 4;

Cargo = 2;

break;

case 4:

Rent = 800;

CarName = "金龙";

Manned = 20;

Cargo = 0;

break;

case 5:

Rent = 400;

CarName = "松花江";

Manned = 0;

Cargo = 4;

break;

case 6:

Rent = 1000;

CarName = "依维柯";

Manned = 0;

Cargo = 20;

break;

}

TotalRent += Rent;

if(Manned>0){

book[m] = CarName;

TotalManned += Manned;

m++;

}

if(Cargo>0){

TotalCargo += Cargo;

n++;

books[n] = CarName;

}

}

System.out.println("请输入租车天数:");

int Day = c.nextInt();

int Total = Day*TotalRent;

System.out.println("您的账单:");

System.out.println("***可载人的车有:");

for(String as : book){

if(as==null){

continue;

}

System.out.print(as);

System.out.print("\t");

}

System.out.println("共载人"+TotalManned+"人");

System.out.println("***可载货的车有:");

for(String ad : books){

if(ad==null){

continue;

}

System.out.print(ad);

System.out.print("\t");

}

System.out.println("共载货"+TotalCargo+"吨");

System.out.println("***租车总价格:"+Total+"元");

}else{

System.out.println("您的输入信息有误:");

}

}

}


写回答 关注

3回答

  • 朦胧是种美
    2016-10-23 21:56:46

    还行啊   后面和我有些不同 不过大致差不多

  • 吃货666
    2016-10-23 16:09:13

    废话,人家 定义了包,你要运行先把子程序放包里,建议把import放开头

  • ziom
    2016-10-23 11:23:09

    很好,有大神潜质,祝早日成神!求采纳!

    ziom 回复慕粉4206...

    采纳我,楼主!

    2016-10-25 21:50:39

    共 4 条回复 >

Java入门第二季 升级版

课程升级!以终为始告别枯燥,在开发和重构中体会Java面向对象编程的奥妙

530655 学习 · 6091 问题

查看课程

相似问题