Advertisement
Guest User

Aaron Program

a guest
Jun 29th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.69 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6. //Room.java
  7.  
  8. package ac.forthvalley.data;
  9.  
  10.  
  11. public class Room {
  12.  
  13. /** The ID of the room */
  14. private static String roomNo;
  15.  
  16. /** The number of workstations the room has. */
  17. private String noOfWorkstations;
  18.  
  19. private static boolean booked = false;
  20.  
  21. /**
  22. * Construct a Room object.
  23. *
  24. * @param roodId - the ID of the room.
  25. * @param noOfWorkstations - the number of workstations belonging to the room.
  26. *
  27. */
  28. public Room(String roomNo, String noOfWorkstations, boolean Booked) {
  29.  
  30. this.roomNo = roomNo;
  31. }
  32.  
  33. /**
  34. * Get the Room No.
  35. *
  36. * @return the room No.
  37. */
  38. public static String getRoomNo()
  39. {
  40. return roomNo;
  41. }
  42.  
  43. void cancel()
  44. {
  45. booked = false;
  46. }
  47.  
  48.  
  49. static boolean isBooked()
  50. {
  51. return booked;
  52. }
  53.  
  54. public void setBooked(boolean booked) {
  55. Room.booked = booked;
  56. }
  57.  
  58.  
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. //Booking.java
  69.  
  70. package ac.forthvalley.data;
  71.  
  72. import java.time.LocalDate;
  73. import java.time.LocalTime;
  74. import java.util.Date;
  75. import java.util.Objects;
  76.  
  77. import ac.forthvalley.data.*;
  78. import ac.forthvalley.swing.Menu;
  79. import ac.forthvalley.swing.Search;
  80. import ac.forthvalley.swing.SearchDateTime;
  81.  
  82. /**
  83. * A simple class encapsulating Booking details.
  84. *
  85. * @author aaron.campbell
  86. */
  87.  
  88. public class Booking {
  89.  
  90. protected static String username = Menu.getUsername();
  91. protected static String requiredDate = SearchDateTime.getDate();
  92. protected static String requiredTime = SearchDateTime.getTime();
  93. protected static String roomNo = SearchDateTime.getRoomNo();
  94. protected static int requiredStations = Search.getStations();
  95.  
  96. public static String getUsername()
  97. {
  98. return username;
  99. }
  100.  
  101. public static String getDate()
  102. {
  103. return requiredDate;
  104. }
  105.  
  106. public static String getTime() {
  107. return requiredTime;
  108. }
  109.  
  110. public static String getRoomNo() {
  111. return roomNo;
  112. }
  113.  
  114. public static int getStations() {
  115. return requiredStations;
  116. }
  117.  
  118. protected Booking(String username, String roomNo, String requiredDate, String requiredTime, int requiredStations)
  119. {
  120. Objects.requireNonNull(username, "You must supply a Username");
  121. Objects.requireNonNull(requiredTime, "You must supply a time");
  122. Objects.requireNonNull(requiredDate, "You must supply a date");
  123. Objects.requireNonNull(roomNo, "You must supply a Room number");
  124. Objects.requireNonNull(requiredStations, "You must supply a number of workstations");
  125.  
  126. Booking.username = username;
  127. Booking.requiredDate = requiredDate;
  128. Booking.requiredTime = requiredTime;
  129. Booking.roomNo = roomNo;
  130. Booking.requiredStations = requiredStations;
  131.  
  132. }
  133.  
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. //DataManager.java
  142.  
  143. package ac.forthvalley.data;
  144.  
  145.  
  146. import java.util.HashMap;
  147. import java.util.Map;
  148.  
  149. import ac.forthvalley.data.Booking;
  150. import ac.forthvalley.data.Person;
  151. import ac.forthvalley.data.Room;
  152. import ac.forthvalley.swing.Search;
  153. import ac.forthvalley.swing.SearchDateTime;
  154.  
  155. /**
  156. * A driver class/a class for formatting data.
  157. *
  158. * @author aaron.campbell
  159. */
  160.  
  161. public class DataManager {
  162.  
  163. String username = Person.Username;
  164. public String requiredDate = SearchDateTime.getDate();
  165. public String requiredTime = SearchDateTime.getTime();
  166. public static String roomNo = Search.getRoomNo();
  167. public int requiredStations = Search.getStations();
  168. protected String password = Person.Password;
  169. static Room room;
  170.  
  171. private static int id;
  172.  
  173. public static Map<Integer, Person> Persons;
  174. public static Map<Integer, Booking> Bookings;
  175. private static int BookingID;
  176.  
  177.  
  178.  
  179. public DataManager() {
  180.  
  181. Persons = new HashMap<>();
  182. Bookings = new HashMap<>();
  183. }
  184.  
  185. public int addnewPerson(String Username, String Password)
  186. {
  187. id++;
  188. Person P = new Person(username, password);
  189. Persons.put(id, P);
  190. return id;
  191. }
  192.  
  193. public static int addNewBooking(String username, String roomNo, String requiredDate, String requiredTime, int requiredStations)
  194. {
  195. /*room = getRoom(roomNo);
  196. Room.isBooked(true);*/
  197.  
  198. BookingID++;
  199. Booking B = new Booking(username, roomNo, requiredDate, requiredTime, requiredStations);
  200. Bookings.put(BookingID, B);
  201. return BookingID;
  202. }
  203.  
  204.  
  205. public static int getBookingNumber(String username)
  206. {
  207. if (!Bookings.containsValue(username))
  208. {
  209. return 0;
  210. }
  211. return BookingID;
  212. }
  213.  
  214. public static Booking getBooking(int BookingNumber)
  215. {
  216. return Bookings.get(id);
  217. }
  218.  
  219. /* public static Room getRoom(String roomID){
  220.  
  221. for(Room r:DataManager.getRoomNo()){
  222.  
  223. if(Room.getRoomNo().equals(roomID)){
  224. return r;
  225. }
  226.  
  227. }
  228. return null;
  229.  
  230. }
  231. */
  232.  
  233. }
  234.  
  235.  
  236.  
  237. //SearchDateTime.java
  238.  
  239. package ac.forthvalley.swing;
  240.  
  241. import java.awt.BorderLayout;
  242. import java.awt.EventQueue;
  243.  
  244. import javax.swing.JFrame;
  245. import javax.swing.JPanel;
  246. import javax.swing.border.EmptyBorder;
  247.  
  248. import javax.swing.JLabel;
  249. import javax.swing.JMenu;
  250. import javax.swing.JMenuBar;
  251. import javax.swing.JMenuItem;
  252. import javax.swing.JTextField;
  253. import javax.swing.JButton;
  254. import java.awt.Font;
  255. import java.awt.event.ActionListener;
  256. import java.util.ArrayList;
  257. import java.awt.event.ActionEvent;
  258.  
  259. import ac.forthvalley.data.Booking;
  260. import ac.forthvalley.data.DataManager;
  261. import ac.forthvalley.data.Room;
  262. import ac.forthvalley.swing.Search;
  263. import ac.forthvalley.data.Person;
  264. import ac.forthvalley.swing.Menu;;
  265.  
  266. public class SearchDateTime extends JFrame {
  267.  
  268. private JPanel contentPane;
  269. private JTextField dateField;
  270. private JTextField timeField;
  271.  
  272. static String username;
  273.  
  274. String date;
  275. String time;
  276. int workstations;
  277.  
  278. public static String requiredDate;
  279. public static String requiredTime;
  280. public static String roomNo;
  281. public int requiredStations;
  282.  
  283. public Booking thisBooking;
  284.  
  285. private JTextField workstationField;
  286. private JTextField roomField;
  287.  
  288. public static String getDate() {
  289. return requiredDate;
  290. }
  291.  
  292. public static String getTime() {
  293. return requiredTime;
  294. }
  295.  
  296. public void setStations(int requiredStations) {
  297. workstationField.setText(String.valueOf(requiredStations));
  298. }
  299.  
  300. public int getStations() {
  301. return Integer.parseInt(workstationField.getText());
  302. }
  303.  
  304. public void setRoomNo(String roomNo) {
  305. roomField.setText(roomNo);
  306. }
  307.  
  308. public static String getRoomNo() {
  309. return roomNo;
  310. }
  311.  
  312. /**
  313. * Launch the application.
  314. */
  315. public static void main(String[] args) {
  316. EventQueue.invokeLater(new Runnable() {
  317. public void run() {
  318. try {
  319. SearchDateTime frame = new SearchDateTime();
  320. frame.setVisible(true);
  321. } catch (Exception e) {
  322. e.printStackTrace();
  323. }
  324. }
  325. });
  326. }
  327.  
  328. public void CloseFrame(){
  329. super.dispose();
  330. }
  331.  
  332. /**
  333. * Create the frame.
  334. */
  335. public SearchDateTime() {
  336. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  337. setBounds(100, 100, 450, 340);
  338. contentPane = new JPanel();
  339. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  340. setContentPane(contentPane);
  341. contentPane.setLayout(null);
  342.  
  343. JLabel label = new JLabel("Ex. DD/MM/YYYY");
  344. label.setBounds(101, 177, 121, 14);
  345. contentPane.add(label);
  346.  
  347. JLabel label_1 = new JLabel("Date Required:");
  348. label_1.setBounds(101, 152, 121, 25);
  349. contentPane.add(label_1);
  350.  
  351. dateField = new JTextField();
  352. dateField.setColumns(10);
  353. dateField.setBounds(232, 152, 121, 23);
  354. contentPane.add(dateField);
  355.  
  356. timeField = new JTextField();
  357. timeField.setColumns(10);
  358. timeField.setBounds(232, 201, 121, 23);
  359. contentPane.add(timeField);
  360.  
  361. JLabel label_2 = new JLabel("Time Required:");
  362. label_2.setBounds(101, 202, 121, 25);
  363. contentPane.add(label_2);
  364.  
  365. JLabel label_3 = new JLabel("Ex. HH:MM");
  366. label_3.setBounds(101, 226, 78, 14);
  367. contentPane.add(label_3);
  368.  
  369. JButton btnBack = new JButton("Back");
  370. btnBack.addActionListener(new ActionListener() {
  371. public void actionPerformed(ActionEvent e) {
  372.  
  373. Search search = new Search();
  374. search.setVisible(true);
  375. }
  376. });
  377. btnBack.setBounds(41, 265, 89, 25);
  378. contentPane.add(btnBack);
  379.  
  380. JLabel lblError = new JLabel("");
  381. lblError.setFont(new Font("Trebuchet MS", Font.PLAIN, 10));
  382. lblError.setBounds(0, 241, 414, 23);
  383. contentPane.add(lblError);
  384.  
  385. JButton btnSubmit = new JButton("Submit\r\n");
  386. btnSubmit.addActionListener(new ActionListener() {
  387. public void actionPerformed(ActionEvent e) {
  388.  
  389. requiredDate = dateField.getText();
  390. requiredTime = timeField.getText();
  391. username = Person.Username;
  392.  
  393.  
  394. if (requiredDate.isEmpty()) {
  395. lblError.setText("You must enter a date!");
  396. }
  397. else if (!requiredDate.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})")) {
  398. lblError.setText("You must enter a valid date Ex. DD/MM/YYYY!");
  399. }
  400. else if (requiredTime.isEmpty()) {
  401. lblError.setText("You must enter a time!");
  402. }
  403. else {
  404.  
  405. username = Menu.getUsername();
  406. requiredDate = getDate();
  407. requiredTime = getTime();
  408. requiredStations = getStations();
  409. roomNo = getRoomNo();
  410.  
  411. /*DataManager.addNewBooking(username, requiredDate, requiredTime, roomNo, requiredStations);
  412. int bookingNumber = DataManager.getBookingNumber(username);
  413. thisBooking = DataManager.getBooking(bookingNumber);*/
  414.  
  415.  
  416. ResultFrame resultframe = new ResultFrame();
  417. resultframe.setVisible(true);
  418.  
  419. }
  420. }
  421.  
  422. });
  423. btnSubmit.setBounds(204, 265, 89, 25);
  424. contentPane.add(btnSubmit);
  425.  
  426. JLabel label_4 = new JLabel("Book a Room\r\n");
  427. label_4.setFont(new Font("Tahoma", Font.BOLD, 20));
  428. label_4.setBounds(101, 22, 235, 23);
  429. contentPane.add(label_4);
  430.  
  431. JLabel lblRoomNo = new JLabel("No. of Workstations:");
  432. lblRoomNo.setBounds(101, 104, 121, 25);
  433. contentPane.add(lblRoomNo);
  434.  
  435. workstationField = new JTextField();
  436. workstationField.setColumns(10);
  437. workstationField.setBounds(232, 106, 121, 23);
  438. contentPane.add(workstationField);
  439. workstationField.setEditable(false);
  440.  
  441.  
  442. JLabel lblRoomNo_1 = new JLabel("Room No:");
  443. lblRoomNo_1.setBounds(101, 56, 121, 25);
  444. contentPane.add(lblRoomNo_1);
  445.  
  446. roomField = new JTextField();
  447. roomField.setEditable(false);
  448. roomField.setColumns(10);
  449. roomField.setBounds(232, 58, 121, 23);
  450. contentPane.add(roomField);
  451.  
  452. JMenuBar menuBar = new JMenuBar();
  453. menuBar.setBounds(0, 0, 434, 21);
  454. contentPane.add(menuBar);
  455.  
  456. JMenu mnNewMenu = new JMenu("File\r\n");
  457. menuBar.add(mnNewMenu);
  458.  
  459. JMenuItem mntmLogOut = new JMenuItem("Log Out");
  460. mntmLogOut.addActionListener(new ActionListener() {
  461. public void actionPerformed(ActionEvent e) {
  462.  
  463. CloseFrame();
  464. }
  465. });
  466. mnNewMenu.add(mntmLogOut);
  467. }
  468. }
  469.  
  470.  
  471.  
  472.  
  473.  
  474. //ResultFrame.java
  475.  
  476. package ac.forthvalley.swing;
  477.  
  478. import java.awt.BorderLayout;
  479. import java.awt.EventQueue;
  480.  
  481. import javax.swing.JFrame;
  482. import javax.swing.JPanel;
  483. import javax.swing.border.EmptyBorder;
  484.  
  485. import ac.forthvalley.data.Booking;
  486. import ac.forthvalley.swing.*;
  487. import javax.swing.JLabel;
  488. import javax.swing.JMenu;
  489. import javax.swing.JMenuBar;
  490. import javax.swing.JMenuItem;
  491.  
  492. import java.awt.Font;
  493. import javax.swing.JButton;
  494. import java.awt.event.ActionListener;
  495. import java.awt.event.ActionEvent;
  496.  
  497. public class ResultFrame extends JFrame {
  498.  
  499. private JPanel contentPane;
  500.  
  501. static String username = Menu.getUsername();
  502.  
  503.  
  504. /*public String requiredDate = Booking.getDate();
  505. public String requiredTime = Booking.getTime();
  506. public static String roomNo = Booking.getRoomNo();
  507. public int requiredStations = Booking.getStations();*/
  508.  
  509.  
  510. public String requiredDate = SearchDateTime.getDate();
  511. public String requiredTime = SearchDateTime.getTime();
  512. public static String roomNo = Search.getRoomNo();
  513. public int requiredStations = Search.getStations();
  514.  
  515. public void CloseFrame(){
  516. super.dispose();
  517. }
  518.  
  519. /**
  520. * Launch the application.
  521. */
  522. public static void main(String[] args) {
  523. EventQueue.invokeLater(new Runnable() {
  524. public void run() {
  525. try {
  526. ResultFrame frame = new ResultFrame();
  527. frame.setVisible(true);
  528. } catch (Exception e) {
  529. e.printStackTrace();
  530. }
  531. }
  532. });
  533. }
  534.  
  535. /**
  536. * Create the frame.
  537. */
  538. public ResultFrame() {
  539. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  540. setBounds(100, 100, 627, 314);
  541. contentPane = new JPanel();
  542. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  543. setContentPane(contentPane);
  544. contentPane.setLayout(null);
  545.  
  546. JLabel label = new JLabel("Book a Room\r\n");
  547. label.setFont(new Font("Tahoma", Font.BOLD, 20));
  548. label.setBounds(212, 27, 235, 23);
  549. contentPane.add(label);
  550.  
  551. JLabel lblNewLabel = new JLabel("");
  552. lblNewLabel.setBounds(21, 59, 580, 154);
  553. contentPane.add(lblNewLabel);
  554.  
  555. JButton btnLogOut = new JButton("Log Out\r\n");
  556. btnLogOut.addActionListener(new ActionListener() {
  557. public void actionPerformed(ActionEvent e) {
  558.  
  559. CloseFrame();
  560. }
  561. });
  562. btnLogOut.setBounds(228, 224, 89, 25);
  563. contentPane.add(btnLogOut);
  564.  
  565. lblNewLabel.setText("Congratulations, " + username + ". You have booked Room " + roomNo + " at " + requiredTime + " on " + requiredDate + ". This room has " + requiredStations + " seats.");
  566.  
  567. JMenuBar menuBar = new JMenuBar();
  568. menuBar.setBounds(0, 0, 611, 21);
  569. contentPane.add(menuBar);
  570.  
  571. JMenu mnNewMenu = new JMenu("File\r\n");
  572. menuBar.add(mnNewMenu);
  573.  
  574. JMenuItem mntmLogOut = new JMenuItem("Log Out");
  575. mntmLogOut.addActionListener(new ActionListener() {
  576. public void actionPerformed(ActionEvent e) {
  577.  
  578. CloseFrame();
  579. }
  580. });
  581. mnNewMenu.add(mntmLogOut);
  582.  
  583. }
  584.  
  585. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement