--- ## Setup Make sure that your terminal shows `@peXXX` ![](https://i.imgur.com/Qag5NoL.png) --- ## Setup Example: ```bash ssh tankang@sunfire.comp.nus.edu ssh pe113 ``` --- ## Vim ```bash vim file.java # opens a file ``` ### While in vim ```vim :w -> Writes to file :q -> Quits :wq -> Writes and quits ``` --- ## Java Compiles all java files in the current directory. ```bash javac *.java ``` Compiles one single file ```bash javac Lab1.java javac Event.java ``` --- ## Java ### Running compiled Java code After compiling the Java files, you can run ```bash java <ClassName> java Lab1 java Main ``` This will run the `public static void main` method. E.g. doing `java Lab1` will run the following: ![](https://i.imgur.com/YfxIEZe.png) --- ## Java ### Testing your java code After running the following, your terminal will be waiting for input. ```bash java Lab1 ``` You can type this in manually and use CTRL+D to signify the end of input. --- ## Java ### Using inputs and outputs provided CS2030S provides some sample inputs and expected outpus. They can be found in the `inputs` and `outputs` folders. After compiling your code, run the following ```bash java Lab1 < inputs/Lab1.1.in ``` This will print to terminal, the `<` operator feeds whatever is in `Lab1.1.in` into the `Lab1` program. --- ## Java ### Comparing with output You can manually verify the outputs are the same, or run the following ```bash java Lab1 < inputs/Lab1.1.in > output diff output outputs/Lab1.1.out ``` There should be nothing printed if the outputs are the same. `diff` compares the 2 files for differences. --- ## Java ### One-liner ```bash diff <(Lab1 < inputs/Lab1.1.in) outputs/Lab1.1.out ``` --- ## First Task Most of you correctly identified that `ShopEvent` does not really represent anything specific but rather, all of the following ![](https://i.imgur.com/AEuve7E.png) **hint: lots of if-else statements here** --- What should this class be replaced with? --- Once you have identified what classes should be created instead, start with the **easiest** one that **does nothing**. --- ## Second Task The second task that you will need to do is with regards to **encapsulation** --- ![](https://i.imgur.com/R3E36u4.png) This is code snipper from `ShopSimulation`. We know a shop has customers and counters. How are they represented in this example? Can we make it better? --- Again in `ShopEvent`, many of you pointed out that there are **multiple** constructors, while this could be useful in **some** scenarios, what is their purpose here? ![](https://i.imgur.com/XcEtQc5.png) --- Going back to our `ShopSimulation`, look at this snippet: ```java= while (sc.hasNextDouble()) { double arrivalTime = sc.nextDouble(); double serviceTime = sc.nextDouble(); initEvents[id] = new ShopEvent(ShopEvent.ARRIVAL, arrivalTime, id, serviceTime, available); id += 1; } ``` --- Does an `ARRIVAL` event really need to know about the service time? `SERVICE_BEGIN` needs it to calculate the `SERVICE_END` timing, but do the other classes need it to do their job? --- In the first place, what is an **Event**? Think about what an event should consist of (**hint** or be made up of).
{"metaMigratedAt":"2023-06-15T19:08:03.282Z","metaMigratedFrom":"Content","title":"Untitled","breaks":true,"contributors":"[{\"id\":\"36fbdb8a-a026-41d1-93ca-02cf986c9b61\",\"add\":3278,\"del\":1}]"}
    224 views