Java第二季答答租车系统

释放双眼,带上耳机,听听看~!

package ddrentcar;

public class Car {
private String carName;//车辆的名称
private double price;//租用价格
private int busLoad;//载客量
private double cargo;//载货量
public String getCarName(){
return carName;
}
public void setCarName(String carName){
this.carName=carName;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price=price;
}
public int getBusLoad(){
return busLoad;
}
public void setBusLoad(int busLoad){
this.busLoad=busLoad;
}
public double getCargo(){
return cargo;
}
public void setCargo(double cargo){
this.cargo=cargo;
}
}
package ddrentcar;

public class Trunk extends Car {
public Trunk(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;

public class Pickup extends Car {
public Pickup(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;

public class Passengercar extends Car {
public Passengercar(String carName,double price,int busLoad,double cargo){
this.setCarName(carName);
this.setPrice(price);
this.setBusLoad(busLoad);
this.setCargo(cargo);
}
}
package ddrentcar;
import java.util.Scanner;
public class Initial {

public static void main(String[] args) {
    // TODO Auto-generated method stub

Car[] carForRent={new Passengercar(“奥迪A4”,500,4,0),new Passengercar(“马自达6”,400,4,0),new Pickup(“皮卡雪6”,450,4,2),new Passengercar(“金龙”,800,20,0),new Trunk(“依维柯”,1000,0,20),new Trunk(“松花江”,400,0,4)};
System.out.println(“欢迎使用答答租车系统:您是否需要租车:1是 0否”);
Scanner input=new Scanner(System.in);
int choose=input.nextInt();
if(choose==1){
System.out.println(“您可租车类型及价目表”);
System.out.println(“序号”+”/t”+”汽车名称”+”/t”+”租金”+”/t”+”载客量”+”/t”+”载货量”);
for(int i=0;i<carForRent.length;i++){
System.out.println((i+1)+”/t”+carForRent[i].getCarName()+”/t”+carForRent[i].getPrice()+”/t”+carForRent[i].getBusLoad()+”/t”+carForRent[i].getCargo());
}//打印租车信息列表
}else if(choose==0){
System.out.println(“感谢你的访问”);
}else{
System.out.println(“输入错误”);
}
System.out.println(“请输入您需要租车的数量:”);
int carNum=input.nextInt();//租车数量
double[] eachKindPrice=new double[6];//所租用的每种类型车的单日总租金
for(int i=0;i<carForRent.length;i++){
System.out.println(“请依次输入您所需的第”+(i+1)+”号车数量”);
int num=input.nextInt();
eachKindPrice[i]=numcarForRent[i].getPrice();
}
System.out.println(“请输入租车天数:”);
int days=input.nextInt();
double[] dailyPrice=new double[6];//单日总租金
double totalPrice=0;//总租金
System.out.println(“您的账单为:”);
for(int i=0;i<6;i++){
dailyPrice[i]=days
eachKindPrice[i];
System.out.println(“租第”+(i+1)+”号车的费用为:”+dailyPrice[i]+”元”);
totalPrice+=dailyPrice[i];
}
System.out.println(“总租金为:”+totalPrice+”元”);
}
}

【转自慕课】https://www.imooc.com

JAVA

面试官:怎么做JDK8的内存调优?

2022-3-3 7:11:55

JAVA

一篇文章彻底搞懂JVM加载中初始化的时机

2022-3-3 7:21:58

搜索