diff --git a/src/main/java/sim/SimDockingStationThread.java b/src/main/java/sim/SimDockingStationThread.java index 40273b6a96e81434ad65cf95b1ec2dcb18452693..cf7ebfaad543720f84b8e719be2c68155fadb553 100644 --- a/src/main/java/sim/SimDockingStationThread.java +++ b/src/main/java/sim/SimDockingStationThread.java @@ -7,6 +7,11 @@ import main.java.db.DockingStationDAO; import java.util.ArrayList; +/** + * Thread used to simulate charging and power consumption on docking stations + * + * @author Magne + */ public class SimDockingStationThread implements Runnable { private DockingStationDAO dockingStationDAO; @@ -43,7 +48,7 @@ public class SimDockingStationThread implements Runnable { int powerConsumption = bikesCharging*POWER_PER_BIKE; chargingLogDAO.addChargingLog(dockingname, powerConsumption); System.out.println("Dockingstation: " + dockingname + ", Bikes charging: " + bikesCharging + - ", Power consumption: " + powerConsumption + "W"); + ", Power consumption: " + powerConsumption + "W"); } bikeDAO.chargeAllBikesDocked(); System.out.println("All docked bikes charged 1%"); diff --git a/src/main/java/sim/SimTripThread.java b/src/main/java/sim/SimTripThread.java index 2c2a2fd3976886ffdb69c81c2bce0eaa51e5a51d..52e0ff26097c7e0d9329246d1811e840357d9b39 100644 --- a/src/main/java/sim/SimTripThread.java +++ b/src/main/java/sim/SimTripThread.java @@ -9,6 +9,11 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Random; +/** + * Thread used to simulate a complete trip + * + * @author Magne + */ public class SimTripThread implements Runnable { private UserDAO userDAO; @@ -16,11 +21,9 @@ public class SimTripThread implements Runnable { private BikeLogDAO bikeLogDAO; private TripDAO tripDAO; private TransactionHistoryDAO transactionHistoryDAO; + private DockingStationDAO dockingStationDAO; - private String userEmail; - private String dockingname; - private String dockingTo; - private String type; + private String userEmail, dockingname, dockingTo, type; private int tripDuration; private double tripLength; private ArrayList<Position> positions; @@ -34,6 +37,7 @@ public class SimTripThread implements Runnable { BikeLogDAO bikeLogDAO, TripDAO tripDAO, TransactionHistoryDAO transactionHistoryDAO, + DockingStationDAO dockingStationDAO, String userEmail, String dockingname, String dockingTo, @@ -46,6 +50,7 @@ public class SimTripThread implements Runnable { this.bikeLogDAO = bikeLogDAO; this.tripDAO = tripDAO; this.transactionHistoryDAO = transactionHistoryDAO; + this.dockingStationDAO = dockingStationDAO; this.userEmail = userEmail; this.dockingname = dockingname; @@ -89,6 +94,7 @@ public class SimTripThread implements Runnable { //Placing bike back into dockingstation: bikeDAO.setName(selectedBikeId, dockingTo); + bikeDAO.setPosition(selectedBikeId, dockingStationDAO.getPosition(dockingTo)); System.out.println("Bike " + selectedBikeId + " placed back in dockingstation"); //Saving the trip: diff --git a/src/main/java/sim/SimulationClient.java b/src/main/java/sim/SimulationClient.java index 48ac077b8c909d1ac1c65f57be0dd039d9e6ed36..f65e4a5091ce29a9f56ad6b39e722adee627f21b 100644 --- a/src/main/java/sim/SimulationClient.java +++ b/src/main/java/sim/SimulationClient.java @@ -1,12 +1,16 @@ package main.java.sim; -import main.java.data.ChargingLog; import main.java.data.Position; import main.java.db.*; import java.sql.SQLException; import java.util.ArrayList; +/** + * Client used to run the simulation with Threads + * + * @author Magne + */ public class SimulationClient { public static void main(String[] args) throws SQLException { UserDAO userDAO = new UserDAO(); @@ -30,29 +34,29 @@ public class SimulationClient { positions.add(new Position(56.023233, 45.959595)); // Complete trip simulation: - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "olanordmann@gmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "olanordmann@gmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "olanordmann@gmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "olanordmann@gmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Pirbadet", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "olanordmann@gmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "olanordmann@gmail.com", "Pirbadet", "Jernbanestasjonen","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Jernbanestasjonen", "Pirbadet","Adult", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "olanordmann@gmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "olanordmann@gmail.com", "Jernbanestasjonen", "Pirbadet","Adult", 10, 2.3, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Lady", 5, 1.1, positions)).start(); - new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, "karihansen@hotmail.com", + new Thread(new SimTripThread(userDAO, bikeDAO, bikeLogDAO, tripDAO, transactionHistoryDAO, dockingStationDAO, "karihansen@hotmail.com", "Jernbanestasjonen", "Jernbanestasjonen","Child", 5, 1.1, positions)).start(); // Complete docking station simulation: