java有多少个类_java实训作业求帮助希望能给个类似的程序参考

原问题:java实训作业求帮助希望能给个类似的程序参考
分类:编程开发 > 最后更新时间:【2017-01-02 02:41:13】
问题补充:

每个学生均拥有若干个电子设备Edevice,包含属性信息:型号、所有者、已使用年数、电子设备分为Phone、Computer、Watch等。Phone具有独有属性:电话号码。PC独有的属性是isLapTop(笔记本电脑/台式电脑)、Watch独有的属性为:isWise(智能/非智能)

编写类:Edevice(父类)、(Phone、PC、Watch)(子类)

编写一个管理类ManageEdevice。

该类包含一个成员变量:

ArrayList<Edevice> devices;

包含方法:

能录入至少5个学生的各自的电子设备信息。

例如:

张三、iphone7、0.5(年)、号码:13201119897;

张三、联想天逸300、2(年)、笔记本电脑

李四、iphone5、4(年)、号码178909088

l 将某个学生的电子设备存入ArrayList<Edevice>中

voidsaveList(Student stu)

l 统计某个学生的电子设备总数。

int getStudentSum()

l 输出该学生的所有电子设备信息

int sumComputer()

l 统计Computer总数

int sumPhone()

l 统计phone总数

Shape getOldestDevice()

l 将已使用年数最高的设备信息输出

创新要求:

可自行设计其他类及方法。例如单个学生的phone总数及相关信息输出等方法的设计

最佳答案

package com.xx.entity
public class Edevice{
private String model;
private String owner;
private Long life;

public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public Long getLife() {
return life;
}
public void setLife(Long life) {
this.life = life;
}
}

package com.xx.entity
public class Phone extends Edevice{
private Long tele;

public Long getTele() {
return tele;
}

public void setTele(Long tele) {
this.tele = tele;
}
}

package com.xx.entity
public class PC extends Edevice{
private boolean isLapTop;

public boolean isLapTop() {
return isLapTop;
}
public void setLapTop(boolean isLapTop) {
this.isLapTop = isLapTop;
}
}

package com.xx.entity
public class Watch extends Edevice{
private boolean isWise;

public boolean isWise() {
return isWise;
}
public void setWise(boolean isWise) {
this.isWise = isWise;
}
}

package com.xx.entity
public class Student {
private ArrayList<Edevice> devices;

public void setDevices(ArrayList<Edevice> devices){
this.devices = devices;
}

public ArrayList<Edevice> getDevices(){
return this.devices;
}
}
package com.xx.util
public class ManageEdevice {
private ArrayList<Edevice> devices;

public void setDevices(ArrayList<Edevice> devices){
this.devices = devices;
}

public ArrayList<Edevice> getDevices(){
return this.devices;
}
//将某个学生的电子设备存入ArrayList<Edevice>中
voidsaveList(Student stu){
this.devices.addAll(stu.getDevices());
}
//统计某个学生的电子设备总数。
int getStudentSum(){
return this.devices.size();
}
//统计Computer总数
int sumComputer(Student stu){
int sum = 0;
for(Edevice dev : this.devices){
if(dev instanceof PC){
sum++;
}
}
return sum;
}
//统计phone总数
int sumPhone(){
int sum = 0;
for(Edevice dev : this.devices){
if(dev instanceof Phone){
sum++;
}
}
return sum;
}
//将已使用年数最高的设备信息输出
Shape getOldestDevice(){
Long max = 0L;
for(Edevice dev : this.devices){
Long life = dev.getLife();
if(life > max){
max = life;
}
}
return max;
}

}

最佳答案由网友  Prometheus_c  提供
公告: 为响应国家净网行动,部分内容已经删除,感谢网友理解。
13

分享到:

其他回答

暂无其它回答!

    推荐