手记

java入门二季_综合练习_答答租车小项目

//测试类
package dadacar;
import java.util.Scanner;
public class Tester {
private static int countA;
private static int countM;
private static int countP;
private static int countJ;
private static int countS;
private static int countY;
private static int mnumber;//租车天数

public static void main(String[] args) {
	//
	Car acar=new Acar();
	Car mcar=new Mcar();
	Pcar pcar=new Pcar();
	Car jcar=new Jcar();
	Car scar=new Scar();
	Car ycar=new Ycar();
	
	Scanner number=new Scanner(System.in);
	Scanner data=new Scanner(System.in);

	System.out.println("欢迎使用答答租车系统"+"\n"+"您是否需要租车:1是 0否");

     if(number.nextInt()==1)
     {Baobiao.baobiao();

System.out.println(“请输入您要租车的数量”);
int amount=number.nextInt(); //租车数量

for(int i=1;i<=amount;i++)
{System.out.println("请输入第"+i+"辆车的序号");
int kk=number.nextInt();

//计所选车辆数
if(kk1){countA++;}
if(kk2){countM++;}
if(kk3){countP++;}
if(kk4){countJ++;}
if(kk5){countS++;}
if(kk6){countY++;}
}

    System.out.println("请输入租车天数");
int mnumber=number.nextInt();
System.out.println("您的账单:");

//判断载人车是否有零辆,如果有则不输出
if(countA!=0&&countM!=0&&countJ!=0)
{System.out.println("载人的车有:"
		+countA+"辆奥迪A4"+"\t"+countM+"辆马自达4"+"\t"+countJ+"辆金龙");}

else if(countA!=0&&countM!=0)
{System.out.println("载人的车有:"
		+countA+"辆奥迪A4"+"\t"+countM+"辆马自达4");}
else if(countA!=0&&countJ!=0)
{System.out.println("载人的车有:"
		+countA+"辆奥迪A4"+"\t"+countJ+"辆金龙");}
else if(countA!=0)
{System.out.println("载人的车有:"
		+countA+"辆奥迪A4");}
else if(countM!=0)
{System.out.println("载人的车有:"
		+countM+"辆马自达4");}
else if(countJ!=0)
{System.out.println("载人的车有:"
		+countJ+"辆金龙");}
else if(countM!=0&&countJ!=0)
{System.out.println("载人的车有:"
		+countM+"辆马自达4"+"\t"+countJ+"辆金龙");}

//

//输出载货
if(countS!=0&&countY!=0)
{System.out.println("载货的车有:"
		+countS+"辆松花江"+"\t"+countY+"辆依维柯");}

else if(countS!=0)
{System.out.println("载货的车有:"
		+countS+"辆松花江");}
else if(countY!=0)
{System.out.println("载货的车有:"
		+countY+"依维柯");}

if(countP>0)
{System.out.println("即可载人又可载货的车有:"+countP+"辆皮卡雪");}

//输出载人载货
if(countA!=0||countM!=0||countJ!=0||countP!=0)
	
{
	int rent=acar.Totalcapacty(countA)+mcar.Totalcapacty(countM)+jcar.Totalcapacty(countJ)
			                          +pcar.LoadMan(countP);
			                         
	System.out.println("共载人: "+rent+"人");}

if(countS!=0||countY!=0||countP!=0)
	
{
	int rent=scar.Totalcapacty(countS)+ycar.Totalcapacty(countY)+pcar.Totalcapacty(countP);;
	System.out.println("共载货: "+rent+"吨");}


//输出租金
double rent=acar.Rent(mnumber,countA)+mcar.Rent(mnumber,countM)+pcar.Rent(mnumber,countP)
		                      +jcar.Rent(mnumber,countJ)
		                      +scar.Rent(mnumber,countS)+ycar.Rent(mnumber,countY);
System.out.println("租车总价格为:"+rent+"元");
 }
//如果不输入1,程序重新执行

else{
Tester.main(args);
}
}}

public abstract class Car {

public abstract double Rent(int data,int mnumber);//计算租金的方法
public abstract int Totalcapacty(int number) ; //计算载人(载货)的方法

}

public class Baobiao {
public static void baobiao()
{System.out.println(“序号”+"\t"+“汽车名称”+"\t\t"+“租金”+"\t\t"+“容量”+"\n"+
“1”+"\t"+“奥迪A4”+"\t\t"+“500元/天”+"\t\t"+“载人:4人”+"\n"+
“2”+"\t"+“马自达6”+"\t\t"+“400元/天”+"\t\t"+“载人:4人”+"\n"+
“3”+"\t"+“皮卡雪6”+"\t\t"+“450元/天”+"\t\t"+“载人:4人 载货:2吨”+"\n"+
“4”+"\t"+“金龙”+"\t\t"+“800元/天”+"\t\t"+“载人:20人”+"\n"+
“5”+"\t"+“松花江”+"\t\t"+“400元/天”+"\t\t"+“载货:4吨”+"\n"+
“6”+"\t"+“依维柯”+"\t\t"+“1000元/天”+"\t"+“载货:20吨”+"\n");}
public static void main(String[] args)
{
baobiao();}
}

package dadacar;

public class Acar extends Car {
private final int rent=500;
private final int LoadMan=4;
private double totalRent;
private int totalcapacity;
public int Manned(int number, int data) {

	return 0;
}

     public int CarrayL(int number, int data) {
	
	return 0;
}

public int PCar() {
	return 0;
}
     public double Rent(int data,int mnumber) {
	totalRent=rent*data*mnumber;
	return totalRent;
}
           public int Totalcapacty(int number) {
	totalcapacity=number*LoadMan;
	return totalcapacity;
}

}
package dadacar;

public class Jcar extends Car {
private final int rent=800;
private final int LoadMan=20;
private double totalRent;
private int totalcapacity;
public double Rent(int data,int mnumber) {
totalRent=rentdatamnumber;
return totalRent;
}
public int Totalcapacty(int number) {
totalcapacity=number*LoadMan;
return totalcapacity;
}

}
package dadacar;
public class Mcar extends Car {
private final int rent=400;
private final int LoadMan=4;
private double totalRent;
private int totalcapacity;
public double Rent(int data,int mnumber) {
totalRent=rentdatamnumber;
return totalRent;
}
public int Totalcapacty(int number) {
totalcapacity=number*LoadMan;
return totalcapacity;
}}
package dadacar;

public class Pcar extends Car {
private final int rent=450;
private final int LoadMan=4;
private final int Loadthings=2;
private double totalRent;
private int totalcapacity;
public double Rent(int data,int mnumber) {
totalRent=rentdatamnumber;
return totalRent;
}
public int LoadMan(int number)
{int totalman=number*LoadMan;
return totalman;}

	public int Totalcapacty(int number) {
		totalcapacity=number*Loadthings;
		return totalcapacity;
	}}

package dadacar;
public class Scar extends Car{
private final int rent=400;
private final int Loadthings=4;//载货量
private double totalRent;
private int totalcapacity;
public double Rent(int data,int mnumber) {
totalRent=rentdatamnumber;
return totalRent;
}

	//载货方法
	public int Totalcapacty(int number) {
		totalcapacity=number*Loadthings;
		return totalcapacity;
	}}

package dadacar;
public class Ycar extends Car {
private final int rent=1000;
private final int Loadthings=20;
private double totalRent;
private int totalcapacity;

  public double Rent(int data,int mnumber) {
		totalRent=rent*data*mnumber;
		return totalRent;
	}
  public int Totalcapacty(int number) {
		totalcapacity=number*Loadthings;
		return totalcapacity;
	}}

//程序有些繁琐,欢迎各位慕友指正

3人推荐
随时随地看视频
慕课网APP