【发布时间】:2018-12-28 21:09:32
【问题描述】:
我正在为一个假装的健身房构建一个预订系统,我有一个针对客户的课程,一个针对 Gym Sessions 的课程,以及一个将 Sessions 收集到一个 HashMap 中的 Session Manager。
每个会话都有一个哈希映射来收集预订的客户。我有一个带有 GUI 的大师班来执行各种功能。 I would like to be able to open a new JPanel/JFrame containing a Jlist, that when a particular session is selected, it displays the customers which are booked on to it, however I've been unable to find这样做的相关方法。
相关代码如下:
客户类别
public class Customer {
private final String name;
private final String payMethod;
public final UUID uniqueId;
/*
* Constructor for me.davehargest.weekendfitness.customer.struct.Customer
*
* @param String name The customers name
* @param int id The sequential ID Reference of the customer
*/
public Customer(String name, UUID uniqueId, String payMethod) {
this.name = name;
this.uniqueId = uniqueId;
this.payMethod = payMethod;
}
}
会话类
public class Session {
private int sessionId;
private String sessionName;
private double price; // Cost of the session per Person
private double totalEarnings; // Total Earnings of the Session (Number of People * @price
private Date sessionDate; //Date that the session takes place
private int classNumber = 1;
/*
* Generates a HashMap of the Customers that will be booked onto a class
*/
public Map <Integer, Customer> customers = new HashMap <>();
/**
* Session Constructor
* Creates a new instance of a session
*
* @param sessionId - An identification ID for the Exercise Session
* @param sessionName - A description of the actual exercise i.e. "Yoga"
* @param price - The cost to attend the session per person
* @param sessionDate
*/
public Session(int sessionId, String sessionName, double price, Date sessionDate)
{
this.sessionId = sessionId;
this.sessionName = sessionName;
this.price = price;
this.sessionDate = sessionDate;
totalEarnings = 0;
}
/*
* Method addCustomer
*
* @param Customer - Adds a new Customer to the Exercise Session
*/
public void addCustomer (Customer customer)
{
if (customers.size() >= 20){
System.out.println("Class is full");
} else {
customers.put(classNumber, customer); // Adds in a new Customer to the session ArrayList
totalEarnings += price; // Adds the per person cost to total fees
classNumber++;
System.out.println("Added: " + classNumber + customer);
}
}
SessionManager 类
public class SessionManager {
/*
* A HashMap of all of the different Sessions that WeekEnd Fitness Offers
*/
public Map<Integer, Session> sessions = new HashMap<>();
private int sId = 1;
public SessionManager() {}
public void addSession(String sessionName, double price, String seshDate) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat ("dd-MM-yyyy HH:mm");
sessionDate = format.parse(seshDate);
this.sessions.put(this.sId, new Session(sId, sessionName, price, sessionDate));
sId ++;
}
}
我确信这真的很简单,但目前似乎超出了我的理解范围,任何提示或指示将不胜感激,谢谢!
【问题讨论】:
-
尝试编辑标题以描述您尝试做的事情,例如“从 hashmap 创建 jframe”或其他内容,并在标签中包含 jframe,您可能会更幸运地得到答案
-
欢迎来到 Stack Overflow!请拿起tour,环顾四周,并通读help center,尤其是How do I ask a good question? 和What topics can I ask about here?。 - 文问 GUI 相关的东西,你不应该显示你的 GUI 代码吗?