tsounakis

OT_Final_Exams_2021

Feb 13th, 2021
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.88 KB | None | 0 0
  1. import java.awt.Button;
  2. import java.awt.Color;
  3. import java.awt.Frame;
  4. import java.awt.Panel;
  5. import java.awt.TextField;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.WindowAdapter;
  9. import java.awt.event.WindowEvent;
  10. import java.awt.event.WindowListener;
  11. import java.sql.Date;
  12. import java.time.LocalDate;
  13. import java.time.LocalTime;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16.  
  17. public class SC1072771 {
  18.     int i;
  19.     public static Shop shop;
  20.     public static Buyer buyer;
  21.     public static void main(String[] args) {
  22.         //INSTANCES NO TIME
  23.         userInterface GUI = new userInterface(shop, buyer);
  24.     }
  25. }
  26.  
  27. class Shop{
  28.     List<Request> visitReqBox = new ArrayList<Request>();
  29.     private int deleted = 0;
  30.     public void receiveRequest(Request request) {
  31.         if (visitReqBox.size() != 0) {
  32.             visitReqBox.remove(visitReqBox.size() - 1);
  33.             deleted++;
  34.             System.out.println(deleted);
  35.         }
  36.         visitReqBox.add(request);
  37.         System.out.println("Request with ID " + visitReqBox.get(0).details());
  38.     }
  39. }
  40.  
  41. class Buyer{
  42.     public Request createReq(int i, int buyers) {
  43.         Request req = new Request(LocalDate.now(), LocalTime.now(), i, buyers);
  44.        
  45.         return req;
  46.     }
  47.    
  48. }
  49.  
  50. class Request{
  51.     LocalDate date;
  52.     LocalTime time;
  53.     int ID, buyers;
  54.    
  55.     public Request(LocalDate date, LocalTime time, int ID, int buyers) {
  56.         this.date = date;
  57.         this.time = time;
  58.         this.ID = ID;
  59.         this.buyers = buyers;
  60.     }
  61.    
  62.     public String details() {
  63.         return ("Request ID: "+this.ID+", " + this.buyers + "buyers, with timestamp: " +
  64.                 this.date + this.time);
  65.     }
  66. }
  67.  
  68.  
  69.  
  70. @SuppressWarnings("serial")
  71. class userInterface extends Frame {
  72.    
  73.    
  74.     private static TextField display;
  75.     public static Shop shop;
  76.     public static Buyer buyer;
  77.     final Button buttonShop, buttonBuyer, buttonStart;
  78.        
  79.         public userInterface(Shop shop, Buyer buyer) {
  80.             userInterface.shop = shop;
  81.             userInterface.buyer = buyer;
  82.            
  83.             new Frame("Click Away 2021");
  84.            
  85.             setLayout(null);
  86.             setBackground(Color.red);
  87.  
  88.             buttonShop = new Button("Shop");
  89.             buttonShop.setBounds(50,100,50,30);
  90.             buttonShop.setForeground(Color.blue);
  91.             buttonShop.addActionListener(new ButtonHandler("Shop"));
  92.  
  93.             buttonBuyer = new Button("Buyer");
  94.             buttonBuyer.setBounds(50,190,50,30);
  95.             buttonBuyer.setForeground(Color.blue);
  96.             buttonBuyer.addActionListener(new ButtonHandler("Buyer"));
  97.            
  98.             buttonStart = new Button("Start");
  99.             buttonStart.setBounds(50,150,50,30);
  100.             buttonStart.setForeground(Color.blue);
  101.             buttonStart.addActionListener(new ButtonHandler("Start"));
  102.  
  103.             add(buttonShop);
  104.             add(buttonBuyer);
  105.             add(buttonStart);
  106.  
  107.             display = new TextField("0");
  108.             display.setEditable(false);
  109.             display.setBounds(13, 55, 370, 30);
  110.  
  111.             add(display);
  112.             setSize(400, 300);
  113.             setLocation(40, 80);
  114.             setVisible(true);
  115.             setResizable(false);
  116.             addWindowListener(new CloseWindowAndExit());
  117.         }
  118.        
  119.     }
  120.  
  121.  
  122. class CloseWindowAndExit extends WindowAdapter {
  123.     public void windowClosing(WindowEvent closeWindowAndExit) {
  124.         System.exit(0);
  125.     }
  126. }
  127.  
  128. class ButtonHandler implements ActionListener {
  129.     int i=0;
  130.     Shop shop;
  131.     Buyer buyer;
  132.     String key;
  133.     public ButtonHandler(String key) {
  134.         this.key = key;
  135.     }
  136.  
  137.     public void actionPerformed(ActionEvent pushingButton) {
  138.         switch (this.key) {
  139.         case "Shop":
  140.             this.shop = new Shop();
  141.             break;
  142.         case "Buyer":
  143.             this.buyer = new Buyer());
  144.             break;
  145.         case "Start":
  146.             for (int j=0; j<40;j++) {
  147.                 this.shop(Buyer.createRequest(++i,3));
  148.                 System.out.println(this.shop.visitReqBox.get(0).details());
  149.             }
  150.             break;
  151.         default:
  152.             break;
  153.     }
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment