JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 新手區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[問]MAP觀念應用 [Re:ggininder]
clock

小時候在看國外測試機器人的影片



發文: 65
積分: 0
於 2018-11-17 10:37 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
乾脆MAP +ArrayList+資料封裝
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.ArrayList;
import java.util.HashMap;
 
public class ClockClass3 {
 
    public static void main(String[] args) {
        HashMap<String, ArrayList<Student>> hmap = new HashMap();
 
        String classNameStr = "一、二、三、四、五、六、七、八、九、十";
 
        String[] classNameAry = classNameStr.split("、");
        String name = "陳、林、黃、張、李、王、吳、蔡、劉、楊、許、鄭、謝、"
                + "郭、賴、曾、洪、邱、周、葉、廖、徐、莊、蘇、江、何、蕭、"
                + "羅、呂、高、彭、朱、詹、胡、簡、沈、施、柯、盧、余、翁、"
                + "潘、游、魏、顏、梁、趙、蘇、方、孫、鐘、戴、杜、連、宋、"
                + "鄧、曹、侯、溫、傅、藍、姜、馮、白、涂、蔣、姚、丁、童、"
                + "黎、金、韓、錢、夏、袁、倪、阮、柳、毛、駱";
 
        String[] nameAry = name.split("、");
        ArrayList<Student> a1 = new ArrayList();
 
        for (int i = 0; i < 3; i++) {
            int studentCount = (int) (Math.random() * 5) + 3;
            String className = classNameAry[i] + "年一班";
            String classCode = "Y" + (i + 1);
            for (int j = 0; j < studentCount; j++) {
                String stuNum = classCode + "S00" + (j + 1);
                String stuName = nameAry[(int) (Math.random() * nameAry.length)];
                Student student = new Student("前鎮國中", className, stuNum, stuName);
                a1.add(student);
            }
        }
        hmap.put("前鎮國中", a1);
        a1 = new ArrayList();
        for (int i = 0; i < 6; i++) {
            int studentCount = (int) (Math.random() * 5) + 3;
            String className = classNameAry[i] + "年一班";
            String classNum = "Y" + (i + 1);
            for (int j = 0; j < studentCount; j++) {
                String stuNum = classNum + "S00" + (j + 1);
                String stuName = nameAry[(int) (Math.random() * nameAry.length)];
                Student student = new Student("前鎮國小", className, stuNum, stuName);
                a1.add(student);
            }
        }
        hmap.put("前鎮國小", a1);
 
        ArrayList<Student> reslutList = hmap.get("前鎮國中");
        String classname = reslutList.get(0).className;
        System.out.println("(前鎮國中)" + classname);
        for (Student s : reslutList) {
            if (!s.className.equalsIgnoreCase(classname)) {
                System.out.println("-----------------");
                classname = s.className;
                System.out.println("(前鎮國中)" + classname);
            }
 
            System.out.println(s);
        }
        System.out.println("-----------------------------");
        reslutList = hmap.get("前鎮國小");
        classname = reslutList.get(0).className;
        System.out.println("(前鎮國小)" + classname);
 
        for (Student s : reslutList) {
            if (!s.className.equalsIgnoreCase(classname)) {
                System.out.println("-----------------");
                classname = s.className;
                System.out.println("(前鎮國小)" + classname);
            }
 
            System.out.println(s);
        }
    }
}
 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public class Student {
    String schoolName;
    String className;
    String stuNum;
    String name;
 
   
 
    public Student(String schoolName, String className, String stuNum, String name) {
        this.schoolName = schoolName;
        this.className = className;
        this.stuNum = stuNum;
        this.name = name;
    }
 
    
 
    @Override
    public String toString() {
        return "學號:" + stuNum + ", 姓:" + name ;
    }
    
}


clock edited on 2018-11-17 10:41
reply to postreply to post
c:你好像很喜歡研究機械產品
X:我從小就跟博士做研究
c:哪位博士
X:南宮博士
話題樹型展開
人氣 標題 作者 字數 發文時間
347 [問]MAP觀念應用 ggininder 242 2018-11-16 01:22
288 Re:[問]MAP觀念應用 clock 1051 2018-11-16 08:25
272 Re:[問]MAP觀念應用 mmolis 360 2018-11-16 09:15
287 Re:[問]MAP觀念應用 frankiewu 4454 2018-11-16 09:58
267 Re:[問]MAP觀念應用 ggininder 221 2018-11-19 01:40
248 Re:[問]MAP觀念應用 clock 3462 2018-11-17 10:37
» JWorld@TW »  Java 新手區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8