Archived
Add files via upload
This commit is contained in:
1 parent
a522d70e6d
commit
a09f45a2a4
5 files changed
+132
-11
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,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; }
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user