Archived
Add files via upload
This commit is contained in:
1 parent
24a4f18380
commit
a522d70e6d
3 files changed
+117
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user