From a09f45a2a439cff3d301a9a27b2f46a0b589f05c Mon Sep 17 00:00:00 2001 From: Aesthetiful <62633768+DrChic0@users.noreply.github.com> Date: Thu, 21 Mar 2024 11:45:04 -0700 Subject: [PATCH] Add files via upload --- Row Compare/Part A/RowCompare.java | 26 +++++++++++++++++++ Row Compare/Part B/RowCompare.java | 22 ++++++++++++++++ Warehouse/Part A/Warehouse.java | 18 ++++++-------- Warehouse/Part B/Product.java | 37 +++++++++++++++++++++++++++ Warehouse/Part B/Warehouse.java | 40 ++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 11 deletions(-) create mode 100644 Row Compare/Part A/RowCompare.java create mode 100644 Row Compare/Part B/RowCompare.java create mode 100644 Warehouse/Part B/Product.java create mode 100644 Warehouse/Part B/Warehouse.java diff --git a/Row Compare/Part A/RowCompare.java b/Row Compare/Part A/RowCompare.java new file mode 100644 index 0000000..fc79b5e --- /dev/null +++ b/Row Compare/Part A/RowCompare.java @@ -0,0 +1,26 @@ +public class RowCompare +{ + public static boolean isRow(int[] arr, int[][] mat, int limit) { + if (limit < 0 || limit > mat.length) { + return false; + } + + for (int i = 0; i < limit; i++) { + if (mat[i].length == arr.length) { + boolean rowMatch = true; + for (int j = 0; j < arr.length; j++) { + if (mat[i][j] != arr[j]) { + rowMatch = false; + break; + } + } + + if (rowMatch) { + return true; + } + } + } + + return false; + } +} \ No newline at end of file diff --git a/Row Compare/Part B/RowCompare.java b/Row Compare/Part B/RowCompare.java new file mode 100644 index 0000000..b641145 --- /dev/null +++ b/Row Compare/Part B/RowCompare.java @@ -0,0 +1,22 @@ +public class RowCompare +{ + public static int uniqueRows(int[][] mat) { + int uniqueCount = 0; + + for (int i = 0; i < mat.length; i++) { + if (!isRow(mat[i], mat, i)) { + uniqueCount++; + } + } + + return uniqueCount; + } + + public static boolean isRow(int[] arr, int[][] mat, int limit) + { + /* COMPLETE WORKING METHOD PROVIDED */ + /* DO NOT MODIFY THE IMPLEMENTATION OF THIS METHOD*/ + return testing.FRQFunctions.isRow(arr, mat, limit); + } + +} diff --git a/Warehouse/Part A/Warehouse.java b/Warehouse/Part A/Warehouse.java index 45776ff..c4d9f27 100644 --- a/Warehouse/Part A/Warehouse.java +++ b/Warehouse/Part A/Warehouse.java @@ -11,24 +11,20 @@ public class Warehouse * @param orderQuant the quantity requested of this product * @return true if the order is completed; false otherwise. */ - public boolean fulfillOrder(String code, int orderQuant) - { - /* Implement your answer to part (a) here */ - for(Product[] row : stock) { - for(Product p : row) { - if(p.getProductCode().equals(code)) { - if(p.getQuant() >= orderQuant) { + public boolean fulfillOrder(String code, int orderQuant) { + for (Product[] row : stock) { + for (Product p : row) { + if (p.getProductCode().equals(code)) { + if (p.getQuant() >= orderQuant) { p.setQuant(p.getQuant() - orderQuant); return true; } else { return false; } - } else { - return false; } } } - + return false; } @@ -44,4 +40,4 @@ public class Warehouse public Warehouse(Product[][] s) { stock = s; } -} \ No newline at end of file +} diff --git a/Warehouse/Part B/Product.java b/Warehouse/Part B/Product.java new file mode 100644 index 0000000..33fc410 --- /dev/null +++ b/Warehouse/Part B/Product.java @@ -0,0 +1,37 @@ +public class Product +{ + + private final String productCode; + private int quantityInStock; + + /** @return the code of this product + */ + public String getProductCode() + { + return productCode; + } + + /** @return the current quantity in stock of this product. This should never be negative. + */ + public int getQuant() + { + return quantityInStock; + } + + /** Sets the current quantity in stock of this product to the parameter value + */ + public void setQuant(int quantity) + { + quantityInStock = quantity; + } + + + /* CLASS MEMBERS FOR TESTING */ + /* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW */ + public Product(String det) + { + productCode = det.split("/")[0]; + quantityInStock = Integer.parseInt(det.split("/")[1]); + } + +} diff --git a/Warehouse/Part B/Warehouse.java b/Warehouse/Part B/Warehouse.java new file mode 100644 index 0000000..c9fa142 --- /dev/null +++ b/Warehouse/Part B/Warehouse.java @@ -0,0 +1,40 @@ +public class Warehouse +{ + private Product[][] stock; + + + /** Attempts to swap the Product at the location frRow, frCol in stock with + * the Product at location toRow, toCol. This only happens if the + * quantity in stock of the Product at toRow, toCol before the method is called + * is 0. + * @param frRow a valid row index for stock + * @param frCol a valid column index for stock + * @param toRow a valid row index for stock + * @param toCol a valid column index for stock + * @return true if the swap is completed; false otherwise. + */ + public boolean reposition(int frRow, int frCol, int toRow, int toCol) { + if (stock[toRow][toCol].getQuant() > 0) { + return false; + } + + Product temp = stock[frRow][frCol]; + stock[frRow][frCol] = stock[toRow][toCol]; + stock[toRow][toCol] = temp; + + return true; + } + + + /* Methods for previous parts of this question are not shown */ + + /* CLASS MEMBERS FOR TESTING */ + /* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW */ + + public Product[][] getStock() + { return stock; } + + public Warehouse(Product[][] s) + { stock = s; } + +}