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

最佳答案

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 devices;

public void setDevices(ArrayList devices){

this.devices = devices;

}

public ArrayList getDevices(){

return this.devices;

}

}

package com.xx.util

public class ManageEdevice {

private ArrayList devices;

public void setDevices(ArrayList devices){

this.devices = devices;

}

public ArrayList getDevices(){

return this.devices;

}

//将某个学生的电子设备存入ArrayList中

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  提供

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值