问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

很简单的java初级设计程序

发布网友 发布时间:2022-05-12 19:13

我来回答

3个回答

热心网友 时间:2023-10-19 05:19

1.
Admin.java
public class Admin {
public static void main(String[] aa) {
Vehicle v1 = new Vehicle();
getResult(v1);
Vehicle v2 = new Vehicle(4, 1000);
getResult(v2);
}

private static void getResult(Vehicle v) {
System.out.println("载重量: " + v.getLoad());
System.out.println("速度: " + v.getSpeed());
System.out.println("自重: " + v.getWeight());
System.out.println("车轮个数:" + v.getWheels());
}
}

Vehicle.java
/**
* Transport的子类Vehicle
*
* @author xiaojianhx
* @data 2008-09-10
* @version 1.0
*/
public class Vehicle extends Transport {

/** 车轮个数 */
private int wheels;

/** 车重 */
private double weight;

/**
* 默认构造器
*/
public Vehicle() {
}

/**
* 构造方法
*
* @param wheels
* 车轮个数
* @param weight
* 车重
*/
public Vehicle(int wheels, double weight) {
this.wheels = wheels;
this.weight = weight;
}

/**
* 车重的取得
*
* @return double 车重
*/
public double getWeight() {
return weight;
}

/**
* 车重的设定
*
* @param weight
* 车重
*/
public void setWeight(double weight) {
this.weight = weight;
}

/**
* 车轮个数的取得
*
* @return int 车轮个数
*/
public int getWheels() {
return wheels;
}

/**
* 车轮个数的设定
*
* @param wheels
* 车轮个数
*/
public void setWheels(int wheels) {
this.wheels = wheels;
}
}
Transport.java
/**
* 运输工具类
*
* @author xiaojianhx
* @data 2008-09-10
* @version 1.0
*/
public class Transport {

/** 速度 */
private double speed;

/** 载重量 */
private double load;

/**
* 默认构造器
*/
public Transport() {
}

/**
* 构造方法
*
* @param speed
* 速度
* @param load
* 载重量
*/
public Transport(double speed, double load) {
this.speed = speed;
this.load = load;
}

/**
* 载重量的取得
*
* @return double 载重量
*/
public double getLoad() {
return load;
}

/**
* 载重量的设定
*
* @param load
* 载重量
*/
public void setLoad(double load) {
this.load = load;
}

/**
* 速度的取得
*
* @return double 速度
*/
public double getSpeed() {
return speed;
}

/**
* 速度的设定
*
* @param speed
* 速度
*/
public void setSpeed(double speed) {
this.speed = speed;
}
}

2.

Teacher.java
public class Teacher {

private int no;

private String name;

private int age;

private String seminary;

public Teacher(int no, String name, int age, String seminary) {
this.no = no;
this.name = name;
this.age = age;
this.seminary = seminary;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNo() {
return no;
}

public void setNo(int no) {
this.no = no;
}

public String getSeminary() {
return seminary;
}

public void setSeminary(String seminary) {
this.seminary = seminary;
}
}
Admin.java
public class Admin {
public static void main(String[] aa) {
int num = 0;
for (int i = 0; i < 5; i++) {
Teacher t = new Teacher(1 + i, "name" + i, 20 + i, "A" + i);
System.out.print(t.getNo() + " ");
System.out.print(t.getName() + " ");
System.out.print(t.getAge() + " ");
System.out.println(t.getSeminary() + " ");
num++;
}
System.out.println("共" + num + "位老师");
}
}

热心网友 时间:2023-10-19 05:19

--------------------------------------------
---1----------------------------------------
Transport.java

public class Transport {
public int speed;

public int load;

public int getLoad() {
return load;
}

public void setLoad(int load) {
this.load = load;
}

public int getSpeed() {
return speed;
}

public void setSpeed(int speed) {
this.speed = speed;
}

public Transport(int speed, int load) {
this.speed = speed;
this.load = load;
}

public Transport() {
super();
}
}

-------------------------------------------
Vehicle.java

public class Vehicle extends Transport {
public int wheels;

public int weight;

public int getWeight() {
return weight;
}

public void setWeight(int weight) {
this.weight = weight;
}

public int getWheels() {
return wheels;
}

public void setWheels(int wheels) {
this.wheels = wheels;
}

public Vehicle(int speed, int load) {
super(speed, load);
}

public Vehicle(int speed, int load, int wheels, int weight) {
super(speed, load);
this.wheels = wheels;
this.weight = weight;
}
}

-------------------------------------------
TestVehicle.java

public class TestVehicle {
public static void main(String[] args){
Vehicle vehicle = new Vehicle(180,50,4,100);
System.out.println(vehicle.getSpeed());
System.out.println(vehicle.getLoad());
System.out.println(vehicle.getWheels());
System.out.println(vehicle.getWeight());
vehicle.setSpeed(140);
vehicle.setLoad(60);
vehicle.setWheels(8);
vehicle.setWeight(110);
System.out.println(vehicle.getSpeed());
System.out.println(vehicle.getLoad());
System.out.println(vehicle.getWheels());
System.out.println(vehicle.getWeight());
}
}

-------------------------------------------
---2---------------------------------------
Teacher.java

public class Teacher {
public static int num;

public int no;

public String name;

public int age;

public String seminary;

public Teacher() {
super();
}

public Teacher(int no, String name, int age, String seminary) {
super();
this.no = no;
this.name = name;
this.age = age;
this.seminary = seminary;
}

public static int getNum() {
return num;
}

public static void setNum(int num) {
Teacher.num = num;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNo() {
return no;
}

public void setNo(int no) {
this.no = no;
}

public String getSeminary() {
return seminary;
}

public void setSeminary(String seminary) {
this.seminary = seminary;
}
}

---------------------------------------
TestTeacher.java

public class TestTeacher {
public static void main(String[] args){
Teacher t1 = new Teacher(1,"zhangsan",43,"计算机");
System.out.println(t1.getNo());
System.out.println(t1.getName());
System.out.println(t1.getAge());
System.out.println(t1.getSeminary());
t1.setName("wangwu");
t1.setAge(50);
t1.setSeminary("国际经贸");
System.out.println(t1.getNo());
System.out.println(t1.getName());
System.out.println(t1.getAge());
System.out.println(t1.getSeminary());
Teacher.setNum(Teacher.getNum() + 1);
System.out.println(Teacher.getNum());
Teacher t2 = new Teacher(2,"lisi",44,"经管");
Teacher.setNum(Teacher.getNum() + 1);
System.out.println(Teacher.getNum());
Teacher t3 = new Teacher(3,"zhouwu",45,"信息");
Teacher.setNum(Teacher.getNum() + 1);
System.out.println(Teacher.getNum());
}
}

热心网友 时间:2023-10-19 05:20

8313674---你个垃圾广告
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
如何分别真金和仿金首饰 怎样区分真金和仿金首饰呢 小学生新年晚会主持人的串词!!(不要太多)急 大大后天就需要了!!!_百度... 周年晚会策划公司 奥格瑞玛传送门大厅在哪 奥格瑞玛传送门大厅怎么走 锻炼颈椎的几个动作 水多久能结冰 冰能在多长时间内形成 请问水低于0度会结冰吗? 如何防止脱发严重 嘴唇上有黑印用蜜蜡和棉线去除了胡须 还有不到一个月就结婚了,四月二十四结婚,想在微博上发表一个邀请形式的微博说说,微信说说,求文采推荐 侄子今天结婚好心情语句微信说说 姜家镇的经济发展 哈尔滨到阿尔山多少公里 肇东的经济概况 肇东自助火锅哪家好吃? 宵夜哪家能好吃吗?? 肇东市美食 最新版本的优酷视频在线观看有倍数。离线观看没有倍速。是吗? 中国宇航员上太空的资料 抵免限额如何计算 小型微利企业标准2022 正当防卫4part文件安装好后怎么下载? 鼻子上总是长痘痘,又红又大又肿又痛 正当防卫4鼠标反转找不到 鼻子两侧总爱发红长痘是什么原因? 正当防卫4画质补丁到底装不装好 鼻子上老是很红,而且老是很红的痘痘,怎么用药? 正当防卫4 这个破船这里,让我装备这个,怎么就是安装不上去? 为什么鼻子上长痘痘,那个痘痘特别红还很软 正当防卫4为什么安装不了? 爸妈结婚记念日我在微信朋友圈发表了说说祝他们快乐合适吗? JAVA如何编一个初级程序 vue自动生成字幕时总出错 网页中我在div和css都限制了 这个图片的宽高为什么不起作用 如何鉴别宋官窑瓷器的真假 摩尔多瓦美乐天然干红葡萄酒价格2001 摩尔多瓦葡萄的抗病性 我是未成年人,可以用我妈妈的银行卡到建设银行柜台取信用卡的钱么 我的建行卡给了我妈用,再后来我因为工作重新办了张建行卡,今天我把工资卡的都钱都提现了,可是继续体 妈妈的建设银行信用卡在白俄罗斯给女儿刷卡消费可以吗? 急!~建行双币信用卡 信用卡刷卡退款 建行信用卡退款问题 在医院刷信用卡(我妈妈的)交了7280定金,两个月没去做,然后 我偷了妈妈卡里的钱,,又存了回去。。 在中国建设银行办了一张银行卡 是借记卡 里面存的是人民币 现在去韩国买东西 可以直接用这张银行卡刷吗? 我最近急需用钱,所以在建设银行做了5万的贷款,办理的时候留了我妈 我的手机照相机的镜头磨花了!看起来有点模糊,但不是很严重,要怎样才能弄好? 手机相机镜头磨花了,拍照不清晰,怎么搞好 如何做豆角素焖面 怎样做豆角素焖面 猫咪不让擦眼屎怎么办? 猫咪不让碰?