package com.cissst.software.model;
/**
*方法的重载
*/
public class Car {
//车类型
private String carType;
//颜色
private String color;
//轮子数量
private int wheelerCount;
//重量
private String weight;
//限定人数
private int personNumber;
//能源类型
private String sourceType;
public Car() {
super();
// TODO Auto-generated constructor stub
}
public Car(String carType, String color, int wheelerCount, String weight,
int personNumber, String sourceType) {
super();
this.carType = carType;
this.color = color;
this.wheelerCount = wheelerCount;
this.weight = weight;
this.personNumber = personNumber;
this.sourceType = sourceType;
}
public String getCarType() {
return carType;
}
public void setCarType(String carType) {
this.carType = carType;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getWheelerCount() {
return wheelerCount;
}
public void setWheelerCount(int wheelerCount) {
this.wheelerCount = wheelerCount;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public int getPersonNumber() {
return personNumber;
}
public void setPersonNumber(int personNumber) {
this.personNumber = personNumber;
}
public String getSourceType() {
return sourceType;
}
public void setSourceType(String sourceType) {
this.sourceType = sourceType;
}
@Override
public String toString() {
return "Car [carType=" + carType + ", color=" + color
+ ", wheelerCount=" + wheelerCount + ", weight=" + weight
+ ", personNumber=" + personNumber + ", sourceType="
+ sourceType + "]";
}
}
package com.cissst.software.transport;
import java.util.Scanner;
import com.cissst.software.model.Car;
public class Transport {
/**测试类
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("输入交通工具的名字:");
Scanner sc = new Scanner(System.in);
String c = sc.next();
Car car1 = new Car("汽车","红色",4,"1500kg",5,"汽油");
Car car2 = new Car("电动三轮车","蓝色",3,"200kg",5,"电瓶");
Car car3 = new Car("自行车","黑色",2,"20kg",1,"人力");
if(c.equals("汽车")){
System.out.println(car1);
}else if(c.equals("电动三轮车")){
System.out.println(car2);
}else if(c.equals("自行车")){
System.out.println(car3);
}
}
}