永发信息网

求java集合编写,

答案:2  悬赏:70  手机版
解决时间 2021-02-23 23:10
  • 提问者网友:星軌
  • 2021-02-23 18:28
为某音像店开发一个迷你DVD管理器,实现DVD碟片的管理,包括如下功能:新增DVD、查看DVD、删除DVD、借出DVD、归还DVD。(后台使用集合来存放DVD对象)。
设计:
1)DVD类(属性:id ,name ,lendCount,lendDate,status)(默认每张DVD都是唯一的) lendCount字段每借一次加1
2)DVDManager类(提供操纵功能),添加DVD、查看DVD、删除DVD、借出DVD、归还DVD、DVD排行榜(按借出次数降序排序),退出系统
4.把集合这一章的实例代码敲一遍。
最佳答案
  • 五星知识达人网友:行雁书
  • 2021-02-23 20:07
题目较长,应该给100分
全部回答
  • 1楼网友:山有枢
  • 2021-02-23 21:37
package com.dy.test; import java.io.ioexception; import java.util.arraylist; import java.util.collections; import java.util.list; import java.util.map; import java.util.random; import java.util.set; import java.util.treemap; import java.util.treeset; public class test {  public static void main(string[] args) throws ioexception {   student[] stu = new student[10];   stu[0] = new student("20170101", "小明", new random().nextint(41) + 60);   stu[1] = new student("20170102", "小红", new random().nextint(41) + 60);   stu[2] = new student("20170103", "小华", new random().nextint(41) + 60);   stu[3] = new student("20170104", "小风", new random().nextint(41) + 60);   stu[4] = new student("20170105", "小黄", new random().nextint(41) + 60);   stu[5] = new student("20170106", "小绿", new random().nextint(41) + 60);   stu[6] = new student("20170107", "小帅", new random().nextint(41) + 60);   stu[7] = new student("20170108", "小黑", new random().nextint(41) + 60);   stu[8] = new student("20170109", "小军", new random().nextint(41) + 60);   stu[9] = new student("20170110", "小胖", new random().nextint(41) + 60);   system.out.println("排序前:");   for (int i = 0; i < stu.length; i++) {    system.out.println(stu[i]);   }   // list集合   list stulist = new arraylist();   for (int i = 0; i < stu.length; i++) {    stulist.add(stu[i]);   }   system.out.println("list排序:");   collections.sort(stulist); // 排序方法   for (int i = 0; i < stulist.size(); i++) {    system.out.println(stulist.get(i));   }   // set集合   set stuset = new treeset(); // treeset自动排序   for (int i = 0; i < stu.length; i++) {    stuset.add(stu[i]);   }   system.out.println("set排序:");   for (int i = 0; i < stuset.size(); i++) {    system.out.println(stuset.toarray()[i]);   }   // map   map stumap = new treemap(); // treemap自动排序   for (int i = 0; i < stu.length; i++) {    stumap.put(stu[i], i);   }   system.out.println("map排序:");   object[] keys = stumap.keyset().toarray();   for (int i = 0; i < keys.length; i++) {    system.out.println(keys[i]);   }  } } class student implements comparable {  private string sid;  private string sname;  private int score;  public student(string sid, string sname, int score) {   super();   this.sid = sid;   this.sname = sname;   this.score = score;  }  public string getsid() {   return sid;  }  public void setsid(string sid) {   this.sid = sid;  }  public string getsname() {   return sname;  }  public void setsname(string sname) {   this.sname = sname;  }  public int getscore() {   return score;  }  public void setscore(int score) {   this.score = score;  }  @override  public int compareto(student o) { //  return this.score - o.getscore(); // 从低到高   int r = o.getscore() - this.score; // 从高到低   return r == 0 ? o.getsid().hashcode() - sid.hashcode() : r;  }  @override  public string tostring() {   return sname + "(" + sid + ") " + score + "分";  } } 运行效果:
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯