感觉我的接口用处不是很大,有没有办法优化一下
package newpackage;
/**
*
* @author Administrator
*/
public class car {
private String name="";
private double money=0;
public car(){}
public car(String name,double money)
{
this.name=name;
this.money=money;
}
public void useway() { System.out.println("车"); }
public String getname(){return name;}
public double getmoney(){return money;}
public String toString()
{
return "name:"+name+" "+"money:"+money;
}
}
package newpackage;
/**
*
* @author Administrator
*/
public interface takepeople {
public int getpeoplenum();
}
package newpackage;
/**
*
* @author Administrator
*/
public interface takegoods {
public int getgoodsnum();
}
package newpackage;
/**
*
* @author Administrator
*/
public class 奥迪A4 extends car implements takepeople{
private int peoplenum=0;
public 奥迪A4()
{
super();
}
public 奥迪A4(String name,double money,int x)
{
super(name,money);
peoplenum=x;
}
public int getpeoplenum()
{
return peoplenum;
}
public String toString()
{
return "车名:奥迪A4"+super.toString()+"载人量:"+peoplenum;
}
}
package newpackage;
/**
*
* @author Administrator
*/
public class 马自达6 extends car implements takepeople{
private int peoplenum=0;
public 马自达6()
{
super();
}
public 马自达6(String name,double money,int x)
{
super(name,money);
peoplenum=x;
}
public int getpeoplenum()
{
return peoplenum;
}
public String toString()
{
return "车名:马自达6"+super.toString()+"载人量:"+peoplenum;
}
}
package newpackage;
/**
*
* @author Administrator
*/
public class 松花江货车 extends car implements takegoods {
private int goodsnum=0;
public 松花江货车()
{
super();
}
public 松花江货车(String name,double money,int x)
{
super(name,money);
goodsnum=x;
}
public int getgoodsnum()
{
return goodsnum;
}
public String toString()
{
return "车名:松花江货车"+super.toString()+"载货量:"+goodsnum;
}
}
package newpackage;
/**
*
* @author Administrator
*/
public class 皮卡雪6 extends car implements takegoods,takepeople{
private int peoplenum=0;
private int goodsnum=0;
public 皮卡雪6()
{
super();
}
public 皮卡雪6(String name,double money,int peoplenum,int goodsnum )
{
super(name,money);
this.peoplenum=peoplenum;
this.goodsnum=goodsnum;
}
public int getgoodsnum()
{
return goodsnum;
}
public int getpeoplenum()
{
return peoplenum;
}
public String toString()
{
return "车名:松花江货车"+super.toString()+"载人量"+peoplenum+"载货量:"+goodsnum;
}
}
package newpackage;
/**
*
* @author Administrator
*/
public class 金龙 extends car implements takegoods {
private int goodsnum=0;
public 金龙 ()
{
super();
}
public 金龙 (String name,double money,int x)
{
super(name,money);
goodsnum=x;
}
public int getgoodsnum()
{
return goodsnum;
}
public String toString()
{
return "车名:松花江货车"+super.toString()+"载货量:"+goodsnum;
}
}
package newpackage;
import java.util.*;
/**
*
* @author Administrator
*/
public class initail {
public static void main(String[] atgs)
{
奥迪A4 aodi=new 奥迪A4("奥迪A4",500,4);
松花江货车 shjhc=new 松花江货车("松花江货车",400,4);
皮卡雪6 pikaxue=new 皮卡雪6("皮卡雪6",450,4,2);
金龙 jinglong=new 金龙("金龙",800,20);
马自达6 mazida=new 马自达6("马自达6",400,4);
System.out.println("欢迎使用达达租车系统");
Scanner in=new Scanner(System.in);
System.out.println("您是否要租车:1是 0否");
int input=in.nextInt();
if(input==0)
return;
System.out.println("您可租车的类型和价目表");
System.out.println("1"+aodi);
System.out.println("2"+shjhc);
System.out.println("3"+pikaxue);
System.out.println("4"+jinglong);
System.out.println("5"+mazida);
System.out.println("请输入你要租车的数量");
int inp=in.nextInt();
double money=0;
int sumday=0;
for(int i=0;i<inp;i++)
{
System.out.println("请输入车的序号和天数");
int nex=in.nextInt();
int day=in.nextInt();
sumday=sumday+day;
while(nex<0||nex>5)
{
System.out.println("请重新输入车的序号");
nex=in.nextInt();
}
switch(nex)
{
case 1:
money=money+aodi.getmoney()*day;
break;
case 2:
money=money+shjhc.getmoney()*day;
break;
case 3:
money=money+pikaxue.getmoney()*day;
break;
case 4:
money=money+jinglong.getmoney()*day;
break;
case 5:
money=money+mazida.getmoney()*day;
break;
default:
break;
}
}
System.out.println("all money="+money+"yuan"+"sumday="+sumday);
}
}