package com.zueb.runningerrands.pojo; import java.util.ArrayList; import java.util.List; /** * Created by ccwant on 2023-3-6. */ public class UserSet { public List<User> users = new ArrayList<>(); public UserSet() { } public User put(String username) { return new User(username); } public User getUser(int position) { return users.get(position); } public User getUser(String username) { for (User user : users) { if (user.username.equals(username)) { return user; } } return null; } public final class User { public String username; public List<Set> list = new ArrayList<>(); private User(String username) { this.username = username; } public User set(String username, int score) { this.list.add(new Set(username, score)); return this; } public void create() { users.add(this); } public Set find(String username) { for (Set set : list) { if (set.username.equals(username)) { return set; } } return null; } @Override public String toString() { return "User{" + "username='" + username + '\'' + '}'; } } public final class Set implements Comparable<Set> { public String username; public int score; public Set(String username, int score) { this.username = username; this.score = score; } @Override public String toString() { return "Set{" + "username='" + username + '\'' + ", score=" + score + '}'; } @Override public int compareTo(Set o) { return score > o.score ? -1 : 1; } } }
时间: 2023-03-28 20:03:40 浏览: 137
Java毕业设计-基于springboot+vue的甜品店(烘焙)管理系统源码+数据库(毕业设计)
这是一个 Java 类,用于管理用户和他们的得分记录。它包含一个 User 类和一个 Set 类,以及一个 UserSet 类,用于管理用户和他们的得分记录。你可以使用 UserSet 类来创建用户、添加得分记录、查找用户和得分记录等操作。
阅读全文