//父类
package ThirdEx;
public abstract class One{
public static int number;
public static int carMoney;
public int no;
public String carName;
public static int weight;
public void Aodi() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry person:"+number);
}
public void Mazida() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry person:"+number);
}
public void PiKaxue() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry person:"+number+" "+"can carry weight:"+weight+"t");
}
public void JinLong() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry person:"+number);
}
public void SongHuaJiang() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry weight:"+weight+"t");
}
public void YiWeiHe() {
// TODO Auto-generated method stub
System.out.println(no+"."+" "+carName+" "+carMoney+"/day"+" "+"can carry weight:"+weight+"t");
}
}
//Aodi类
package ThirdEx;
public class Aodi extends One {
public Aodi(){
no = 1;
carName = "Aodi";
carMoney = 500;
number = 4;
}
}
//Mazida类
package ThirdEx;
public class Mazida extends One {
public Mazida(){
no=2;
carName="Mazida";
carMoney=400;
number=4;
}
}
//PiKaxue类
package ThirdEx;
public class PiKaxue extends One {
public PiKaxue(){
no=3;
carName="PiKaxue";
carMoney=450;
number=4;
weight=2;
}
}
还有其他车的类都一样的写法 就不贴上来了
//测试类
package ThirdEx;
import java.util.Scanner;
public class Initial {
private static int b;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to DADA Rent Car!If you want to rent a car?" );
System.out.println("1.Yes 0.No");
Scanner input =new Scanner(System.in);
int a=input.nextInt();
if(a==0){
System.out.println("Thank you!Good bye!");
}else if(a==1){
System.out.println("You can use these cars:");
Aodi carA=new Aodi();
carA.Aodi();
Mazida carM=new Mazida();
carM.Mazida();
PiKaxue carP=new PiKaxue();
carP.PiKaxue();
JinLong carJ=new JinLong();
carJ.JinLong();
SongHuaJiang carS=new SongHuaJiang();
carS.SongHuaJiang();
YiWeiHe carY=new YiWeiHe();
carY.YiWeiHe();
System.out.println("How much cars do you want?");
Scanner input11=new Scanner(System.in);
b = input11.nextInt();
int sum=0;
int people=0;
int weight=0;
for(int i=1;i<=b;i++){
System.out.println("Please enter the "+i+" car's No.");
Scanner inputi=new Scanner(System.in);
int id=input.nextInt();
if(id==1){
sum=sum+Aodi.carMoney;
people=people+Aodi.number;
}
if(id==2){
sum=sum+Mazida.carMoney;
people=people+Mazida.number;
}
if(id==3){
sum=sum+PiKaxue.carMoney;
people=people+PiKaxue.number;
weight=weight+PiKaxue.weight;
}
if(id==4){
sum=sum+JinLong.carMoney;
people=people+JinLong.number;
}
if(id==5){
sum=sum+SongHuaJiang.carMoney;
weight=weight+SongHuaJiang.weight;;
}
if(id==6){
sum=sum+YiWeiHe.carMoney;
weight=weight+YiWeiHe.weight;
}
}
System.out.println("Plaese enter the days do you want to rent?");
Scanner input12=new Scanner(System.in);
int c1=input12.nextInt();
System.out.println("Your pill is:");
System.out.println("can carry "+ people +"people");
System.out.println("can carry "+ weight +"weight");
int sumTotil = sum*c1;
System.out.println("All money:"+sumTotil);
}
}
}
我测试的结果就是错的
为什么传人数、车钱的值都是似乎是地址值而不是我赋的值呢 求指点
cars 用 many。。。
你最后的输出输出的是啥!