车的轮胎数 重量
Posted 庚庚庚庚庚辰
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了车的轮胎数 重量相关的知识,希望对你有一定的参考价值。
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(); } }
以上是关于车的轮胎数 重量的主要内容,如果未能解决你的问题,请参考以下文章
按要求编写Java应用程序。 创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)减速(车速自减)修改车牌号,查询车的载重量(代码片段
11.按要求编写Java应用程序。 创建一个叫做机动车的类: 属性:车牌号(String),车速(int),载重量(double) 功能:加速(车速自增)减速(车速自减)修改车牌号,查询车的(代码片段