diff --git a/Height Map/Part A/HeightMap.java b/Height Map/Part A/HeightMap.java new file mode 100644 index 0000000..6f10ba8 --- /dev/null +++ b/Height Map/Part A/HeightMap.java @@ -0,0 +1,33 @@ +public class HeightMap +{ + /** A two-dimensional array of height values, initialized in the constructor + * Guaranteed not to be null + */ + private double[][] heights; + + /** @param r a valid row index in heights + * @param c a valid column index in heights + * @return true if the height at row r, column c is not at the edge of the + * two-dimensional array heights, and is greater in value than all 8 surrounding + * values; false otherwise. + */ + public boolean isPeak(int r, int c) + { + if(r == 0 || c == 0 || r == heights.length - 1 || c == heights[r].length - 1) { + return false; + } + + //double h = heights[r][c]; + return true; + } + + /* Methods for subsequent parts of this question are not shown */ + + /* CLASS MEMBERS FOR TESTING */ + /* DO NOT MODIFY ANY OF THE CONSTRUCTORS OR METHODS BELOW*/ + + public HeightMap(double[][] h){ + heights = h; + } + +} \ No newline at end of file diff --git a/Warehouse/Part A/Product.java b/Warehouse/Part A/Product.java new file mode 100644 index 0000000..5833b2d --- /dev/null +++ b/Warehouse/Part A/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]); + } + +} \ No newline at end of file diff --git a/Warehouse/Part A/Warehouse.java b/Warehouse/Part A/Warehouse.java new file mode 100644 index 0000000..45776ff --- /dev/null +++ b/Warehouse/Part A/Warehouse.java @@ -0,0 +1,47 @@ +public class Warehouse +{ + private Product[][] stock; + + + /** Attempts to fulfill an order by decreasing the quantity in stock of a product with the + * specified productCode by the quantity requested. This is only completed if a + * Product with the code desired is found with quantity in stock greater than or equal + * to the quantity requested. + * @param code the product code to search for in stock + * @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) { + p.setQuant(p.getQuant() - orderQuant); + return true; + } else { + return false; + } + } else { + return false; + } + } + } + + return false; + } + + + /* Methods for subsequent 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; } + +} \ No newline at end of file