Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone fix errors? I wrote the program and ran a junit test but there are so many errors. But problem is I tried to
Can someone fix errors? I wrote the program and ran a junit test but there are so many errors. But problem is I tried to fix it but I couldn't able to fix errors.
Please help me.
This is Junit test that I suppose to pass.
package BCIT.Comp2522; import org.junit.Rule; import org.junit.Test; import org.junit.Before; import org.junit.rules.ExpectedException; import java.util.Date; import static org.junit.Assert.*; public class InventoryItemsTest { private Rental rental1; private Rental rental2; private Rental rental3; private Date date1; private String comment; private long rentalID; private long SKU; private long SKU2; private long rentalItemID; private long rentalItemID2; private double rentalCost; private RentalItem rentalItem1; private RentalItem rentalItem2; private SalesItem salesItem1; private SalesItem salesItem2; // @Rule // public ExpectedException thrown = ExpectedException.none(); @Before public void setUp() throws Exception { comment = "XYZ Zibblefritz Deluxe Blender"; date1 = new Date(); rentalID = 1; SKU = 42; SKU2 = 54; rentalItemID = 2; rentalItemID2 = 4; rentalCost = 49.99; rental1 = new Rental(rentalID, rentalItemID, date1); rental1.setComments(comment); rental1.setCostOfRental(rentalCost); rental1.setConditionBefore(Condition.EXCELLENT); rental1.setConditionAfter(Condition.UNDEFINED); rental2 = new Rental(rentalID, rentalItemID, date1); rental2.setComments("XYZ Zibblefritz Standard Blender"); rental2.setCostOfRental(rentalCost); rental2.setConditionBefore(Condition.EXCELLENT); rental2.setConditionAfter(Condition.UNDEFINED); rental3 = new Rental(77, rentalItemID2, date1); rental3.setComments("Batmobile"); rental3.setCostOfRental(4999.99); rental3.setConditionBefore(Condition.EXCELLENT); rental3.setConditionAfter(Condition.UNDEFINED); rentalItem1 = new RentalItem(SKU, rentalItemID); rentalItem1.setCurrentCondition(Condition.EXCELLENT); rentalItem1.setDescription("ABC"); rentalItem1.setSold(true); rentalItem1.addRental(rental1); rentalItem1.addRental(rental2); rentalItem1.addRental(rental3); rentalItem2 = new RentalItem(SKU, rentalItemID); rentalItem2.setCurrentCondition(Condition.EXCELLENT); rentalItem2.setDescription("ABC"); rentalItem2.setSold(true); rentalItem2.addRental(rental1); rentalItem2.addRental(rental2); rentalItem2.addRental(rental3); salesItem1 = new SalesItem(SKU, 99); salesItem1.setPurchasePrice(49.99); salesItem1.setDescription("ABC TV Stand"); salesItem2 = new SalesItem(SKU, 98); salesItem2.setPurchasePrice(49.99); salesItem2.setDescription("ABC TV Stand"); } @Test(expected = NullPointerException.class) public void salesItemSetToNull() { salesItem1.setDescription(null); } @Test public void testSalesItemEqualsFalse() { assertFalse(salesItem1.equals(salesItem2)); } @Test public void testSalesToSalesHashcode() { assertTrue(salesItem1.hashCode() == salesItem2.hashCode()); } @Test public void testRentalItemEquality() { assertEquals(new RentalItem(44, 55), new RentalItem(44, 55)); } @Test public void testRentalItemRentalsCount() { assertEquals(rentalItem1.getTotalRentalCost(), (rentalCost * 2) + 4999.99, 0.0002); } @Test(expected = NullPointerException.class) public void rentalItemDescriptionSetToNull() { rentalItem1.setDescription(null); } @Test(expected = NullPointerException.class) public void rentalItemAddNullRental() { rentalItem1.addRental(null); } @Test(expected = NullPointerException.class) public void rentalItemConditionSetToNull() { rentalItem1.setCurrentCondition(null); } @Test(expected = RuntimeException.class) public void testRentalItemSoldMoreThanOnce() { rentalItem1.setSold(false); } @Test public void testRentalItemIsSellable() { assertTrue(rentalItem1.isSellable() == false); } @Test public void testRentalItemCondition() { assertTrue(rentalItem1.getCurrentCondition() == Condition.EXCELLENT); } @Test public void testRentalItemDesc() { assertTrue(rentalItem1.getDescription().equals("ABC")); } @Test public void testRentalRentalItemSKU() { assertTrue(rentalItem1.getSKU() == 42); } @Test public void testRentalRentalItemID() { System.out.println(rentalItem1.getRentalItemID()); assertTrue(rentalItem1.getRentalItemID() == 2); } @Test(expected = NullPointerException.class) public void rentalConditionBeforeSetToNull() { rental3.setConditionBefore(null); } @Test(expected = NullPointerException.class) public void rentalConditionAfterSetToNull() { rental3.setConditionAfter(null); } @Test(expected = NullPointerException.class) public void rentalCommentsSetToNull() { rental3.setComments(null); } @Test public void testRentaltoRentalEqualityEQUAL() { assertTrue(rental1.equals(rental2)); } @Test public void testRentaltoRentalEqualityNOTEQUAL() { assertFalse(rental1.equals(rental3)); } @Test public void testRentaltoRentalHashcode() { assertTrue(rental1.hashCode() == rental2.hashCode()); } and here is my classes. enum Condition { AVERAGE, POOR, EXCELLENT, GREAT, DAMAGED, UNDEFINED; }
package BCIT.Comp2522; import java.util.Date; import java.lang.Comparable; public class InventoryItem { Date IPD; long SKU; String desc; String name; double purchasePrice; long serialVersionUID; String type; int hashcode; //not sure as of it yet boolean equals; //not sure as of it yet public boolean equals (Object o) { return equals; } String getDesc() { return desc; } Date getIPD() { return IPD; } String getName() { return name; } double getPurchasePrice() { return purchasePrice; } long getSKU() { return SKU; } String getType() { return type; } public int hashCode() { return hashcode; } void setDesc (String desc) { this.desc = desc; } void setIPD (Date IPD) { this.IPD = IPD; } void setName (String name) { this.name = name; } void setPurchasePrice ( double purchasePrice) { this.purchasePrice = purchasePrice; } void setSKU (long SKU) { this.SKU = SKU; } void setType (String type) { this.type = type; } public String toString() { String result = getName() + getDesc() + getIPD() + getPurchasePrice() + getSKU() + getType(); // This is not defined properly yet. return result; } }
package BCIT.Comp2522; import java.util.Date; public class Rental { String comments; Condition conditionAfter; Condition conditionBefore; Date date; long rentalID; long serialVersionUID; Date dateRented; boolean equalsOrNot; //Don't know what this is as of yet int hashC; //?? what is this anyways private double costOfRental; private long rentalItemId; public Rental(long rentalID, long rentalItemID, Date date1) { } public Rental(long sku, long rentalItemID) { } public boolean equals(Object o) { return equalsOrNot; } String getComments() { return comments; } Condition getConditionAfter() { return conditionAfter; } Condition getConditionBefore() { return conditionBefore; } Date getDate() { return date; } long getRentalID() { return rentalID; } public int hashCode() { return hashC; } void setComments(String comments) { this.comments = comments; } void setConditionAfter(Condition conditionAfter) { this.conditionAfter = conditionAfter; } void setConditionBefore(Condition conditionBefore) { this.conditionBefore = conditionBefore; } void setRentalID (long rentalID) { this.rentalID = rentalID; } public String toString () { String result = getComments() + getConditionAfter() +getConditionBefore() + getDate() + getRentalID(); return result; } public void setCostOfRental(double rentalCost) { } void setDateRented(Date dateRented) { if (dateRented == null) this.dateRented = null; this.dateRented = dateRented; } public Date getDateRented() { return dateRented; } public double getCostOfRental() { return costOfRental; } public long getRentalItemID() { return rentalItemId; } }
package BCIT.Comp2522; import java.util.Date; public class RentalItem extends Rental { Condition currentCondition; Rental[] items; long rentalID; double rentalPrice; boolean sellable; long serialVersionUID; boolean sold; private int SKU = 42; double totalRentalCost; private Object description; long rentalItemID; public RentalItem(long rentalID, long rentalItemID, Date date1) { super(rentalID, rentalItemID, date1); } public RentalItem(long sku, long rentalItemID) { super(sku, rentalItemID); } Condition getCurrentCondition() { return currentCondition; } Rental[] getItems() { return items; } long getRentalID() { return rentalID; } double getRentalPrice() { return rentalPrice; } boolean isSellable() { return sellable; } boolean isSold() { return sold; } void setCurrentCondition(Condition currentCondition) { this.currentCondition = currentCondition; } void setItems (Rental[] items) { this.items = items; } void setRentalID (long rentalID) { this.rentalID = rentalID; } void setRentalPrice (double rentalPrice) { this.rentalPrice = rentalPrice; } void setSellable (boolean state) { this.sellable = state; } void setSold (boolean sold) { this.sold = sold; } public String toString() { return String.format("%s, %s, %d, %d, %s, %d, %s", currentCondition, items, rentalID, rentalPrice, sellable, serialVersionUID, sold); } public Object getDescription() { return description; } public void setDescription(String description) { this.description = description; } public void addRental(Rental rental1) { } public double getTotalRentalCost() { return totalRentalCost; } public int getSKU() { return SKU; } }
package BCIT.Comp2522; public class SalesItem extends InventoryItem { double salePrice; long salesID; boolean sellable; long serialVersionUID; boolean sold; String description; public SalesItem(long sku, int i) { super(); } double getSalePrice() { return salePrice; } long getSalesID() { return salesID; } boolean isSellable() { return sellable; } boolean isSold() { return sold; } void setSalePrice(double salePrice) { this.salePrice = salePrice; } void setSalesID(long salesID) { this.salesID = salesID; } void setSellable(boolean state) { this.sellable = state; } void setSold(boolean sold) { this.sold = sold; } String getDescription() { return description; } public String toString() { String result = String.valueOf(getSalePrice()) + String.valueOf(getSalesID()) + String.valueOf(isSellable()) + String.valueOf(isSold()); return result; } public void setDescription(String description) { this.description = description; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started