diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a4fe3c6977171123955ae583411384d21a0bdf93 Binary files /dev/null and b/.DS_Store differ diff --git a/assignments/.DS_Store b/assignments/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a308dd9de4b911c6cf89af7d62423a9a192ba664 Binary files /dev/null and b/assignments/.DS_Store differ diff --git a/assignments/src/.DS_Store b/assignments/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8f370ce20024e01626b607bebd4111933ec46cae Binary files /dev/null and b/assignments/src/.DS_Store differ diff --git a/assignments/src/MV3500Cohort2023MarchJune/.DS_Store b/assignments/src/MV3500Cohort2023MarchJune/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a506183143edd57a28f7eb7f1281d354078197fe Binary files /dev/null and b/assignments/src/MV3500Cohort2023MarchJune/.DS_Store differ diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/.DS_Store b/assignments/src/MV3500Cohort2023MarchJune/projects/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..80878e3412d0634604e7b9926bedb652267797ee Binary files /dev/null and b/assignments/src/MV3500Cohort2023MarchJune/projects/.DS_Store differ diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Customer.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Customer.java new file mode 100644 index 0000000000000000000000000000000000000000..ce0d4e839d272f746531854f46af047095098c47 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Customer.java @@ -0,0 +1,54 @@ +import java.io.*; +import java.net.*; + +public class Client_Customer { + public static void main(String[] args) { + + // TODO - Fill out the following questionairre: + + double averageBeefPurchase = 2; // How many pounds of beef do you typically purchase when you buy groceries? + double averageVariationInBeefPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)? + + double averagePorkPurchase = 4; // How many pounds of pork do you typically purchase when you buy groceries? + double averageVariationInPorkPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)? + + double averageChickenPurchase = 6; // How many pounds of chicken do you typically purchase when you buy groceries? + double averageVariationInChickenPurchase = 0.5; // How much do you typically vary from the above amount (also in pounds)? + + double averageEggsPurchase = 2; // How many eggs do you typically purchase when you buy groceries (amount in dozens)? + double averageVariationInEggsPurchase = 0.5; // How much do you typically vary from the above amount (also in dozens)? + + // End of TODO section + + Customer myCustomer = new Customer(averageBeefPurchase, averageVariationInBeefPurchase, averagePorkPurchase, averageVariationInPorkPurchase, averageChickenPurchase, averageVariationInChickenPurchase, averageEggsPurchase, averageVariationInEggsPurchase); + + try { + // Create client socket and connect to the server + Socket clientSocket = new Socket("localhost", 12345); + System.out.println("Connected to server."); + + // Send request to server + PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); + String request = "doTransaction," + myCustomer.getBeefPreference().generate() + "," + myCustomer.getPorkPreference().generate() + "," + myCustomer.getChickenPreference().generate() + "," + myCustomer.getEggsPreference().generate(); + out.println(request); + System.out.println("Sent request to server: " + request); + + // Receive response from server + BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + StringBuilder responseBuilder = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) { + responseBuilder.append(line).append("\n"); + } + String response = responseBuilder.toString(); + System.out.print("Received response from server: " + response); + + // Close connections + in.close(); + out.close(); + clientSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Farm.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Farm.java new file mode 100644 index 0000000000000000000000000000000000000000..f5385a7da7b12daec9698f1ac230642118f27855 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Client_Farm.java @@ -0,0 +1,50 @@ +import java.io.*; +import java.net.*; + +public class Client_Farm { + public static void main(String[] args) { + + // TODO - Fill out the following questionairre: + + int cattleCount = 50; // How many cows are on the farm? + + int pigCount = 50; // How many pigs are on the farm? + + int broilerChickenCount = 300; // How many broiler chickens (think supermarket chickens - they don't lay eggs) are on the farm? + + int layerChickenCount = 500; // How many egg laying chickens are on the farm? + + // End of TODO section + + LivestockRanch myFarm = new LivestockRanch(cattleCount, pigCount, broilerChickenCount, layerChickenCount); + + try { + // Create client socket and connect to the server + Socket clientSocket = new Socket("localhost", 12345); + System.out.println("Connected to server."); + + // Send request to server + PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); + String request = "doResupply," + myFarm.getCattleProcessRate() + "," + myFarm.getPigProcessRate() + "," + myFarm.getChickenProcessRate() + "," + myFarm.getEggLayingRate(); + out.println(request); + System.out.println("Sent request to server: " + request); + + // Receive response from server + BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + StringBuilder responseBuilder = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) { + responseBuilder.append(line).append("\n"); + } + String response = responseBuilder.toString(); + System.out.print("Received response from server: " + response); + + // Close connections + in.close(); + out.close(); + clientSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Customer.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Customer.java new file mode 100644 index 0000000000000000000000000000000000000000..1ae3e48540c630bef80513b18ac5e8b986479bc1 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Customer.java @@ -0,0 +1,56 @@ +import simkit.SimEntityBase; +import simkit.random.RandomVariate; +import simkit.random.RandomVariateFactory; + +public class Customer extends SimEntityBase{ + private RandomVariate beefPreference; + private RandomVariate porkPreference; + private RandomVariate chickenPreference; + private RandomVariate eggsPreference; + + public Customer(double averagePurchaseOfBeef, double beefPlusMinus, double averagePurchaseOfPork, double porkPlusMinus, double averagePurchaseOfChicken, double chickenPlusMinus, double averagePurchaseOfEggs, double eggsPlusMinus) { + this.beefPreference = RandomVariateFactory.getInstance("Normal", averagePurchaseOfBeef, beefPlusMinus); + this.porkPreference = RandomVariateFactory.getInstance("Normal", averagePurchaseOfPork, porkPlusMinus); + this.chickenPreference = RandomVariateFactory.getInstance("Normal", averagePurchaseOfChicken, chickenPlusMinus); + this.eggsPreference = RandomVariateFactory.getInstance("Normal", averagePurchaseOfEggs, eggsPlusMinus); + } + + public void doRun() { + waitDelay("Transaction", 0.0); + } + + public void doTransaction() { + double beef = beefPreference.generate(); + beef = beef < 0 ? 0 : beef; + + double pork = porkPreference.generate(); + pork = pork < 0 ? 0 : pork; + + double chicken = chickenPreference.generate(); + chicken = chicken < 0 ? 0 : chicken; + + double eggs = eggsPreference.generate(); + eggs = eggs < 0 ? 0 : eggs; + + waitDelay("Transaction", 0.0, beef, pork, chicken, eggs); + waitDelay("Transaction", 7.0); + } + + public RandomVariate getBeefPreference() { + return beefPreference; + } + + public RandomVariate getPorkPreference() { + return porkPreference; + } + + public RandomVariate getChickenPreference() { + return chickenPreference; + } + + public RandomVariate getEggsPreference() { + return eggsPreference; + } + + +} diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/FarmStore.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/FarmStore.java new file mode 100644 index 0000000000000000000000000000000000000000..b099bc6bb78dad829f520fdb6c5969fc08b72131 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/FarmStore.java @@ -0,0 +1,69 @@ +import java.text.DecimalFormat; + +public class FarmStore { + private double bankAccount; + private double BEEFCOST = 10; // Cost per pound + private double PORKCOST = 5; // Cost per pound + private double CHICKENCOST = 2; // Cost per pound + private double EGGSCOST = 2; // Cost per dozen + + protected double beefQuantity; // Quantity in pounds + protected double porkQuantity; // Quantity in pounds + protected double chickenQuantity; // Quantity in pounds + protected double eggQuantity; // Quantity in dozens + + public FarmStore() { + this.bankAccount = 0; + this.beefQuantity = 0; + this.porkQuantity = 0; + this.chickenQuantity = 0; + this.eggQuantity = 0; + } + + public String doTransaction(double beef, double pork, double chicken, double eggs) { + DecimalFormat df = new DecimalFormat("#.##"); + + if (this.beefQuantity < beef) { + beef = Math.max(this.beefQuantity, 0); + System.out.println("We are out of beef"); + } + else {beef = Double.parseDouble(df.format(beef));} + if (this.porkQuantity < pork) { + pork = Math.max(this.porkQuantity, 0); + System.out.println("We are out of pork"); + } + else {pork = Double.parseDouble(df.format(pork));} + if (this.chickenQuantity < chicken) { + chicken = Math.max(this.chickenQuantity, 0); + System.out.println("We are out of chicken"); + } + else {chicken = Double.parseDouble(df.format(chicken));} + if (this.eggQuantity < eggs) { + eggs = Math.max(this.eggQuantity, 0); + System.out.println("We are out of eggs"); + } + else {eggs = Double.parseDouble(df.format(eggs));} + + this.beefQuantity -= beef; + this.porkQuantity -= pork; + this.chickenQuantity -= chicken; + this.eggQuantity -= eggs; + + double cost = beef * BEEFCOST + pork * PORKCOST + chicken * CHICKENCOST + eggs * EGGSCOST; + cost = Double.parseDouble(df.format(cost)); + this.bankAccount += cost; + + return "Product purchased:\nBeef: " + beef + " lbs\nPork: " + pork + " lbs\nChicken: " + chicken + " lbs\nEggs: " + eggs + " dozen\nTransaction total: $" + cost; + } + + public String doResupply(double beef, double pork, double chicken, double eggs) { + this.beefQuantity += beef; + this.porkQuantity += pork; + this.chickenQuantity += chicken; + this.eggQuantity += eggs; + + return "Product received:\nBeef: " + beef + " lbs\t\tCurrent Stock: " + beefQuantity + " lbs\nPork: " + pork + + " lbs\tCurrent Stock: " + porkQuantity + " lbs\nChicken: " + chicken + " lbs\tCurrent Stock: " + chickenQuantity + + " lbs\nEggs: " + eggs + " dozen\tCurrent Stock: " + eggQuantity + " dozen\nCurrent Profit: $" + bankAccount; + } +} \ No newline at end of file diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/LivestockRanch.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/LivestockRanch.java new file mode 100644 index 0000000000000000000000000000000000000000..5db0ee64982065b596cd7d7c162cd2c8e8948925 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/LivestockRanch.java @@ -0,0 +1,57 @@ +public class LivestockRanch { + private int totalCattle; + private int totalPigs; + private int totalBroilerChickens; + private int totalLayerChickens; + + private double cattleProcessRate; + private double pigProcessRate; + private double chickenProcessRate; + private double eggLayingRate; + + public LivestockRanch (int totalCattle, int totalPigs, int totalBroilerChickens, int totalLayerChickens) { + this.totalCattle = totalCattle; + this.totalPigs = totalPigs; + this.totalBroilerChickens = totalBroilerChickens; + this.totalLayerChickens = totalLayerChickens; + + this.cattleProcessRate = totalCattle * 500 / (3 * 12); // Processing 1/3 of the total population per year, 1 per month, at 500 lbs of beef per cow + this.pigProcessRate = totalPigs * 150 / 6; // Processing 1/6 of the total population per month, at 150 lbs of pork per pig + this.chickenProcessRate = totalBroilerChickens * 6 / 3; // Processing 1/3 of the total population per month, at 6 lbs per chicken + this.eggLayingRate = totalLayerChickens * (25 / 12); // 25 eggs per layer chicken (divided by 12 to be sold in dozens) + } + + public int getTotalCattle() { + return totalCattle; + } + + public int getTotalPigs() { + return totalPigs; + } + + public int getTotalBroilerChickens() { + return totalBroilerChickens; + } + + public int getTotalLayerChickens() { + return totalLayerChickens; + } + + public double getCattleProcessRate() { + return cattleProcessRate; + } + + public double getPigProcessRate() { + return pigProcessRate; + } + + public double getChickenProcessRate() { + return chickenProcessRate; + } + + public double getEggLayingRate() { + return eggLayingRate; + } + + +} diff --git a/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Server.java b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Server.java new file mode 100644 index 0000000000000000000000000000000000000000..ed276501a874c6af3d96562e835e503c12e6faa7 --- /dev/null +++ b/assignments/src/MV3500Cohort2023MarchJune/projects/Islas/Server.java @@ -0,0 +1,72 @@ +import java.io.*; +import java.net.*; + +public class Server { + public static void main(String[] args) { + + FarmStore market = new FarmStore(); + try { + // Create server socket + ServerSocket serverSocket = new ServerSocket(12345); + System.out.println("Server listening on port 12345..."); + + while (true) { + // Accept client connection + Socket clientSocket = serverSocket.accept(); + System.out.println("Client connected: " + clientSocket.getInetAddress().getHostAddress()); + + // Start a new thread to handle the client connection + ClientHandler clientHandler = new ClientHandler(clientSocket, market); + clientHandler.start(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + static class ClientHandler extends Thread { + private Socket clientSocket; + private FarmStore market; + + public ClientHandler(Socket socket, FarmStore market) { + this.clientSocket = socket; + this.market = market; + } + + public void run() { + try { + // Read data from client + BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + String request = in.readLine(); + String[] parsedRequest = request.split(","); + System.out.println("Received request from client: " + request); + + // Process request + String response = processRequest(parsedRequest[0], Double.parseDouble(parsedRequest[1]), Double.parseDouble(parsedRequest[2]), Double.parseDouble(parsedRequest[3]), Double.parseDouble(parsedRequest[4])); + System.out.print("Sending response to client: " + response); + + // Send response to client + PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); + out.println(response); + + // Close connections + in.close(); + out.close(); + clientSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private String processRequest(String request, double beef, double pork, double chicken, double eggs) { + // Process the request and execute the corresponding method + if (request.equals("doTransaction")) { + return market.doTransaction(beef, pork, chicken, eggs); // Assuming appropriate arguments for the method + } else if (request.equals("doResupply")) { + return market.doResupply(beef, pork, chicken, eggs); + } else { + return "Invalid request!"; + } + } + } +}