Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Room.java
- package ac.forthvalley.data;
- public class Room {
- /** The ID of the room */
- private static String roomNo;
- /** The number of workstations the room has. */
- private String noOfWorkstations;
- private static boolean booked = false;
- /**
- * Construct a Room object.
- *
- * @param roodId - the ID of the room.
- * @param noOfWorkstations - the number of workstations belonging to the room.
- *
- */
- public Room(String roomNo, String noOfWorkstations, boolean Booked) {
- this.roomNo = roomNo;
- }
- /**
- * Get the Room No.
- *
- * @return the room No.
- */
- public static String getRoomNo()
- {
- return roomNo;
- }
- void cancel()
- {
- booked = false;
- }
- static boolean isBooked()
- {
- return booked;
- }
- public void setBooked(boolean booked) {
- Room.booked = booked;
- }
- }
- //Booking.java
- package ac.forthvalley.data;
- import java.time.LocalDate;
- import java.time.LocalTime;
- import java.util.Date;
- import java.util.Objects;
- import ac.forthvalley.data.*;
- import ac.forthvalley.swing.Menu;
- import ac.forthvalley.swing.Search;
- import ac.forthvalley.swing.SearchDateTime;
- /**
- * A simple class encapsulating Booking details.
- *
- * @author aaron.campbell
- */
- public class Booking {
- protected static String username = Menu.getUsername();
- protected static String requiredDate = SearchDateTime.getDate();
- protected static String requiredTime = SearchDateTime.getTime();
- protected static String roomNo = SearchDateTime.getRoomNo();
- protected static int requiredStations = Search.getStations();
- public static String getUsername()
- {
- return username;
- }
- public static String getDate()
- {
- return requiredDate;
- }
- public static String getTime() {
- return requiredTime;
- }
- public static String getRoomNo() {
- return roomNo;
- }
- public static int getStations() {
- return requiredStations;
- }
- protected Booking(String username, String roomNo, String requiredDate, String requiredTime, int requiredStations)
- {
- Objects.requireNonNull(username, "You must supply a Username");
- Objects.requireNonNull(requiredTime, "You must supply a time");
- Objects.requireNonNull(requiredDate, "You must supply a date");
- Objects.requireNonNull(roomNo, "You must supply a Room number");
- Objects.requireNonNull(requiredStations, "You must supply a number of workstations");
- Booking.username = username;
- Booking.requiredDate = requiredDate;
- Booking.requiredTime = requiredTime;
- Booking.roomNo = roomNo;
- Booking.requiredStations = requiredStations;
- }
- }
- //DataManager.java
- package ac.forthvalley.data;
- import java.util.HashMap;
- import java.util.Map;
- import ac.forthvalley.data.Booking;
- import ac.forthvalley.data.Person;
- import ac.forthvalley.data.Room;
- import ac.forthvalley.swing.Search;
- import ac.forthvalley.swing.SearchDateTime;
- /**
- * A driver class/a class for formatting data.
- *
- * @author aaron.campbell
- */
- public class DataManager {
- String username = Person.Username;
- public String requiredDate = SearchDateTime.getDate();
- public String requiredTime = SearchDateTime.getTime();
- public static String roomNo = Search.getRoomNo();
- public int requiredStations = Search.getStations();
- protected String password = Person.Password;
- static Room room;
- private static int id;
- public static Map<Integer, Person> Persons;
- public static Map<Integer, Booking> Bookings;
- private static int BookingID;
- public DataManager() {
- Persons = new HashMap<>();
- Bookings = new HashMap<>();
- }
- public int addnewPerson(String Username, String Password)
- {
- id++;
- Person P = new Person(username, password);
- Persons.put(id, P);
- return id;
- }
- public static int addNewBooking(String username, String roomNo, String requiredDate, String requiredTime, int requiredStations)
- {
- /*room = getRoom(roomNo);
- Room.isBooked(true);*/
- BookingID++;
- Booking B = new Booking(username, roomNo, requiredDate, requiredTime, requiredStations);
- Bookings.put(BookingID, B);
- return BookingID;
- }
- public static int getBookingNumber(String username)
- {
- if (!Bookings.containsValue(username))
- {
- return 0;
- }
- return BookingID;
- }
- public static Booking getBooking(int BookingNumber)
- {
- return Bookings.get(id);
- }
- /* public static Room getRoom(String roomID){
- for(Room r:DataManager.getRoomNo()){
- if(Room.getRoomNo().equals(roomID)){
- return r;
- }
- }
- return null;
- }
- */
- }
- //SearchDateTime.java
- package ac.forthvalley.swing;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.Font;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import java.awt.event.ActionEvent;
- import ac.forthvalley.data.Booking;
- import ac.forthvalley.data.DataManager;
- import ac.forthvalley.data.Room;
- import ac.forthvalley.swing.Search;
- import ac.forthvalley.data.Person;
- import ac.forthvalley.swing.Menu;;
- public class SearchDateTime extends JFrame {
- private JPanel contentPane;
- private JTextField dateField;
- private JTextField timeField;
- static String username;
- String date;
- String time;
- int workstations;
- public static String requiredDate;
- public static String requiredTime;
- public static String roomNo;
- public int requiredStations;
- public Booking thisBooking;
- private JTextField workstationField;
- private JTextField roomField;
- public static String getDate() {
- return requiredDate;
- }
- public static String getTime() {
- return requiredTime;
- }
- public void setStations(int requiredStations) {
- workstationField.setText(String.valueOf(requiredStations));
- }
- public int getStations() {
- return Integer.parseInt(workstationField.getText());
- }
- public void setRoomNo(String roomNo) {
- roomField.setText(roomNo);
- }
- public static String getRoomNo() {
- return roomNo;
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- SearchDateTime frame = new SearchDateTime();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public void CloseFrame(){
- super.dispose();
- }
- /**
- * Create the frame.
- */
- public SearchDateTime() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 340);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel label = new JLabel("Ex. DD/MM/YYYY");
- label.setBounds(101, 177, 121, 14);
- contentPane.add(label);
- JLabel label_1 = new JLabel("Date Required:");
- label_1.setBounds(101, 152, 121, 25);
- contentPane.add(label_1);
- dateField = new JTextField();
- dateField.setColumns(10);
- dateField.setBounds(232, 152, 121, 23);
- contentPane.add(dateField);
- timeField = new JTextField();
- timeField.setColumns(10);
- timeField.setBounds(232, 201, 121, 23);
- contentPane.add(timeField);
- JLabel label_2 = new JLabel("Time Required:");
- label_2.setBounds(101, 202, 121, 25);
- contentPane.add(label_2);
- JLabel label_3 = new JLabel("Ex. HH:MM");
- label_3.setBounds(101, 226, 78, 14);
- contentPane.add(label_3);
- JButton btnBack = new JButton("Back");
- btnBack.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- Search search = new Search();
- search.setVisible(true);
- }
- });
- btnBack.setBounds(41, 265, 89, 25);
- contentPane.add(btnBack);
- JLabel lblError = new JLabel("");
- lblError.setFont(new Font("Trebuchet MS", Font.PLAIN, 10));
- lblError.setBounds(0, 241, 414, 23);
- contentPane.add(lblError);
- JButton btnSubmit = new JButton("Submit\r\n");
- btnSubmit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- requiredDate = dateField.getText();
- requiredTime = timeField.getText();
- username = Person.Username;
- if (requiredDate.isEmpty()) {
- lblError.setText("You must enter a date!");
- }
- else if (!requiredDate.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})")) {
- lblError.setText("You must enter a valid date Ex. DD/MM/YYYY!");
- }
- else if (requiredTime.isEmpty()) {
- lblError.setText("You must enter a time!");
- }
- else {
- username = Menu.getUsername();
- requiredDate = getDate();
- requiredTime = getTime();
- requiredStations = getStations();
- roomNo = getRoomNo();
- /*DataManager.addNewBooking(username, requiredDate, requiredTime, roomNo, requiredStations);
- int bookingNumber = DataManager.getBookingNumber(username);
- thisBooking = DataManager.getBooking(bookingNumber);*/
- ResultFrame resultframe = new ResultFrame();
- resultframe.setVisible(true);
- }
- }
- });
- btnSubmit.setBounds(204, 265, 89, 25);
- contentPane.add(btnSubmit);
- JLabel label_4 = new JLabel("Book a Room\r\n");
- label_4.setFont(new Font("Tahoma", Font.BOLD, 20));
- label_4.setBounds(101, 22, 235, 23);
- contentPane.add(label_4);
- JLabel lblRoomNo = new JLabel("No. of Workstations:");
- lblRoomNo.setBounds(101, 104, 121, 25);
- contentPane.add(lblRoomNo);
- workstationField = new JTextField();
- workstationField.setColumns(10);
- workstationField.setBounds(232, 106, 121, 23);
- contentPane.add(workstationField);
- workstationField.setEditable(false);
- JLabel lblRoomNo_1 = new JLabel("Room No:");
- lblRoomNo_1.setBounds(101, 56, 121, 25);
- contentPane.add(lblRoomNo_1);
- roomField = new JTextField();
- roomField.setEditable(false);
- roomField.setColumns(10);
- roomField.setBounds(232, 58, 121, 23);
- contentPane.add(roomField);
- JMenuBar menuBar = new JMenuBar();
- menuBar.setBounds(0, 0, 434, 21);
- contentPane.add(menuBar);
- JMenu mnNewMenu = new JMenu("File\r\n");
- menuBar.add(mnNewMenu);
- JMenuItem mntmLogOut = new JMenuItem("Log Out");
- mntmLogOut.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- CloseFrame();
- }
- });
- mnNewMenu.add(mntmLogOut);
- }
- }
- //ResultFrame.java
- package ac.forthvalley.swing;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import ac.forthvalley.data.Booking;
- import ac.forthvalley.swing.*;
- import javax.swing.JLabel;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import java.awt.Font;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class ResultFrame extends JFrame {
- private JPanel contentPane;
- static String username = Menu.getUsername();
- /*public String requiredDate = Booking.getDate();
- public String requiredTime = Booking.getTime();
- public static String roomNo = Booking.getRoomNo();
- public int requiredStations = Booking.getStations();*/
- public String requiredDate = SearchDateTime.getDate();
- public String requiredTime = SearchDateTime.getTime();
- public static String roomNo = Search.getRoomNo();
- public int requiredStations = Search.getStations();
- public void CloseFrame(){
- super.dispose();
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- ResultFrame frame = new ResultFrame();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public ResultFrame() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 627, 314);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel label = new JLabel("Book a Room\r\n");
- label.setFont(new Font("Tahoma", Font.BOLD, 20));
- label.setBounds(212, 27, 235, 23);
- contentPane.add(label);
- JLabel lblNewLabel = new JLabel("");
- lblNewLabel.setBounds(21, 59, 580, 154);
- contentPane.add(lblNewLabel);
- JButton btnLogOut = new JButton("Log Out\r\n");
- btnLogOut.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- CloseFrame();
- }
- });
- btnLogOut.setBounds(228, 224, 89, 25);
- contentPane.add(btnLogOut);
- lblNewLabel.setText("Congratulations, " + username + ". You have booked Room " + roomNo + " at " + requiredTime + " on " + requiredDate + ". This room has " + requiredStations + " seats.");
- JMenuBar menuBar = new JMenuBar();
- menuBar.setBounds(0, 0, 611, 21);
- contentPane.add(menuBar);
- JMenu mnNewMenu = new JMenu("File\r\n");
- menuBar.add(mnNewMenu);
- JMenuItem mntmLogOut = new JMenuItem("Log Out");
- mntmLogOut.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- CloseFrame();
- }
- });
- mnNewMenu.add(mntmLogOut);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement