zoukankan      html  css  js  c++  java
  • 车的轮胎数 重量

    29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数

    wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数

    loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个

    类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功

    能。

    package zuoye;
    
    public class Vehicle 
    {
        private int wheels;
        private double weight;
        Vehicle()
        {
        weight=1;wheels=4;
        }
        Vehicle(int geshu, double chezhong)
        {
        wheels=geshu;
        weight=chezhong;
        }
        public int getWheels() {
        return wheels;
        }
        public void setWheels(int wheels) {
        this.wheels = wheels;
        }
        public double getWeight() {
        return weight;
        }
        public void setWeight(double weight) {
        this.weight = weight;
        }
        public void shuchu(){
        System.out.println("轮子"+wheels+"个,"+"车重"+weight);
        }
    }
    {
        private int loader;
        Car1()
        {
        loader=4;
        }
        Car1(int zaike)
        {
        loader=zaike;
        }
        Car1(int geshu, double chezhong,int zaike)
        {
        super(geshu,chezhong);
        loader=zaike;
        }
        public void showData(){
        System.out.println("轮子"+getWheels()+"个"+"自重"+getWeight());
        System.out.println("载客人数:"+loader+"人");
        }
        public int getLoader() {
        return loader;
        }
        public void setLoader(int loader) {
        this.loader = loader;
        }
    }
    package zuoye;
    
    public class Truck extends Car1
    {
        private double payload;
        Truck()
        {
        payload=500;
        }
        Truck(double zaizhong)
        {
        payload=zaizhong;
        }
        Truck(int zaike,double zaizhong)
        {
        super(zaike);
        payload=zaizhong;
        }
        Truck(int lun, double chezhong,int zaike,double zaizhong)
        {
        super(lun,chezhong,zaike);
        payload=zaizhong;
        }
        public void showData(){
        System.out.println("轮子"+getWheels()+"个"+"自重"+getWeight());
        System.out.println("载客人数:"+getLoader()+"人");
        System.out.println("载重:"+payload);
        }
    }
    package zuoye;
    
    public class ceshi2 {
    
        public static void main(String[] args) 
        {
            Truck t=new Truck();
            t.showData();
            t=new Truck(500);
            t.showData();
            t=new Truck(20,500);
            t.showData();
            t=new Truck(20,21,22,500);
            t.showData();
    
        }
    
    }

  • 相关阅读:
    vue 给嵌套的iframe子页面传数据 postMessage
    左边宽度固定,右边宽度自适应的三种写法
    全局变量声明的规范化
    利用__index和__newindex实现默认值表、监控表、只读表
    Metatable和Metamethod
    Lua中的协同程序 coroutine
    Lua中的require
    Lua基础
    D3D的绘制
    效率相关笔记
  • 原文地址:https://www.cnblogs.com/Levi1995/p/5898232.html
Copyright © 2011-2022 走看看