大神们看看我的能不能在简洁了
//父类
package com.imooc;
public abstract class Da {
public abstract void run();
}
package com.imooc;
import java.util.Scanner;
public class Track extends Da {
Scanner imput=new Scanner(System.in);
public void run() {
System.out.print("请您输入所需货车吨位(吨):");
int score1=imput.nextInt();
System.out.print("请您输入租赁时间(天):");
int score2=imput.nextInt();
if(score1<=50){
String name="小货车载货50吨以下(含50吨)";
float price=120;
float num=price*score2;
System.out.println("**********");
System.out.println("根据您的情况以下是您的租车信息请确认:");
System.out.println("车型:"+name);
System.out.println("租赁时间:"+score2+"天");
System.out.println("总金额:"+num+"元");
System.out.println("**********");
}else if(50<score1&&score1<=300){
String name="大货车50吨以上";
float price1=500;
float num1=price1*score2;
System.out.println("**********");
System.out.println("根据您的情况以下是您的租车信息请确认:");
System.out.println("车型:"+name);
System.out.println("租赁时间:"+score2+"天");
System.out.println("总金额:"+num1+"元");
System.out.println("**********");
}else{
System.out.println("您所选吨位无法满足,请您重新选择!");
}
}
}
package com.imooc;
import java.util.Scanner;
public class Car extends Da {
Scanner imput=new Scanner(System.in);
@Override
public void run() {
// TODO Auto-generated method stub
System.out.print("请您输入载客量:");
int score1=imput.nextInt();
System.out.print("请您输入租赁时间(天):");
int score2=imput.nextInt();
if(score1<=5){
String name="小汽车";
float price=100;
float num=price*score2;
System.out.println("**********");
System.out.println("根据您的情况以下是您的租车信息请确认:");
System.out.println("车型:"+name);
System.out.println("租赁时间:"+score2+"天");
System.out.println("总金额:"+num+"元");
System.out.println("**********");
}else if(5<score1&&score1<=30){
String name="大客车";
float price1=200;
float num1=price1*score2;
System.out.println("**********");
System.out.println("根据您的情况以下是您的租车信息请确认:");
System.out.println("车型:"+name);
System.out.println("租赁时间:"+score2+"天");
System.out.println("总金额:"+num1+"元");
System.out.println("**********");
}else{
System.out.println("您所选载客量无法满足,请您重新选择!");
}
}
}
package com.imooc;
import java.util.Scanner;
public class Pickup extends Da {
Scanner imput=new Scanner(System.in);
@Override
public void run() {
// TODO Auto-generated method stub
System.out.print("请您输入租赁时间(天):");
int score2=imput.nextInt();
String name="皮卡";
float price=130;
float num=price*score2;
System.out.println("**********");
System.out.println("根据您的情况以下是您的租车信息请确认:");
System.out.println("车型:"+name);
System.out.println("租赁时间:"+score2+"天");
System.out.println("总金额:"+num+"元");
System.out.println("**********");
}
}
package com.imooc;
import java.util.Scanner;
public class Initail {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner imput=new Scanner(System.in);
System.out.println(" 本公司供选车型:1.货车;2.客车;3.皮卡");
System.out.print("请您选择您所需的车型:");
int score=imput.nextInt();
switch(score){
case 1:
Da pl1=new Track();
pl1.run();
break;
case 2:
Da pl2=new Car();
pl2.run();
break;
case 3:
Da pl3=new Pickup();
pl3.run();
break;
default:
System.out.println("您输入有误,请重新选择!!!");
}
}
}