javaSE基础编程——方法的重载(汽车类)

 

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);
  }
 }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值