日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Java打卡系统

發(fā)布時間:2023/12/31 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java打卡系统 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

打卡系統(tǒng)

import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; //構建一個學生類 public class Student {private String name;private int count;//打卡時間是隨時變動的,所以需要用一個集合存儲,并且時間是通過Date的形式進行獲取的private ArrayList<Date> arr = new ArrayList<>();@Overridepublic String toString() {//把時間按特定的格式輸出SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm;ss");//創(chuàng)建一個字符串集合,存儲修改后的內容StringBuffer stringBuffer = new StringBuffer();for (int i = 0;i<arr.size();i++){//獲取集合中的數(shù)據(jù)Date date = arr.get(i);//格式化數(shù)據(jù),了解格式化的形式String format = sim.format(date);//把格式化的增加到字符串中,知道append方法stringBuffer.append(format+"\n");}return "Student{" +"姓名='" + name + '\'' +", 打卡數(shù)量=" + count +", 打卡時間=" + stringBuffer +'}';}//這里面我們是把姓名和打卡的數(shù)量看作一個整體,用于進行實例化這個學生類public Student(String name, int count) {this.name = name;this.count = count;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getCount() {return count;}public void setCount(int count) {this.count = count;}public ArrayList<Date> getArr() {return arr;}public void setArr(ArrayList<Date> arr) {this.arr = arr;} } //該類的功能主要是實現(xiàn)打卡的功能 public class Function {//此方法主要用于實現(xiàn)打卡功能public void dk() {HashMap<Integer, Student> map = new HashMap<>();//初始話三個對象Student wangwu = new Student("王五", 0);Student lisi = new Student("李四", 0);Student zhangsan = new Student("張三", 0);map.put(1, wangwu);map.put(2, lisi);map.put(3, zhangsan);while (true) {Scanner sc = new Scanner(System.in);System.out.println("1、王五2、李四3、張三4、查詢5、退出");System.out.println("請你輸入:");int key = sc.nextInt();if (key == 4) {//要實現(xiàn)查詢首先是先獲取到每個成員,需要遍歷輸出map集合System.out.println("查詢結果如下:");//獲取map集合中的所有的鍵,通過keyset方法獲得Set<Integer> set = map.keySet();//通過for循環(huán)遍歷輸出map中的內容for (Integer integer : set) {//通過鍵獲取map中的所有信息System.out.println(map.get(integer));}} else if (key == 5) {System.out.println("成功退出系統(tǒng)");System.exit(0);} else {Student stu = map.get(key);//對該集合成員的打卡數(shù)量加1stu.setCount(map.get(key).getCount() + 1);//在集合中增加時間stu.getArr().add(new Date());System.out.println("你已經打卡成功" + stu.getName());}}} } //測試函數(shù) public class Program {public static void main(String[] args) {Function function = new Function();function.dk();} }

總結

以上是生活随笔為你收集整理的Java打卡系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。