最佳答案
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 提供