Question: In java plz, Need to construct a test that passes only one of them. On the other words, need to find an edge test that

In java plz,

Need to construct a test that passes only one of them. On the other words, need to find an edge test that passes only Basket 8 or 12. They cannot have same test result.

 ====================================================================================== Basket 8 ======================================================================================= package cse12pa1student; import java.util.ArrayList; public class Basket8 implements Basket { ArrayList items; public Basket8() { this.items = new ArrayList(); } @Override public int count() { return this.items.size(); } @Override public int countItem(Item i) { int countItem = 0; for (int j = 0; j < this.items.size(); j += 1) { if (this.items.get(j) == i) { countItem += 1; } } return countItem; } @Override public int totalCost() { int price = 0; for (int j = 0; j < this.items.size(); j += 1) { price += this.items.get(j).priceInCents; } return price; } @Override public void addToBasket(Item i) { this.items.add(i); } @Override public boolean removeFromBasket(Item i) { return this.items.remove(i); } @Override public boolean removeAllFromBasket(Item i) { while (this.items.contains(i)) { this.items.remove(i); } return this.items.contains(i); } @Override public void empty() { this.items.clear(); } }

=================================================================================================================================== Basket12 ===================================================================================================================================

package cse12pa1student; import java.util.ArrayList; public class Basket12 implements Basket { public Basket12() { this.items = new ArrayList(); } ArrayList items; @Override public int count() { return this.items.size(); } @Override public int countItem(Item i) { int countItem = 0; for (int j = 0; j < this.items.size(); j += 1) { if (this.items.get(j) == i) { countItem += 1; } } return countItem; } @Override public int totalCost() { int price = 0; for (int j = 0; j < this.items.size(); j += 1) { price += this.items.get(j).priceInCents; } return price; } @Override public void addToBasket(Item i) { this.items.add(i); } @Override public boolean removeFromBasket(Item i) { return this.items.remove(i); } @Override public boolean removeAllFromBasket(Item i) { this.items.removeAll(this.items); return this.items.remove(i); } @Override public void empty() { this.items.clear(); } }

===============================================================================================================================

Basket.java

=================================================================================================================================

package cse12pa1student; public interface Basket { /* * @return the total count of all items, counting duplicates, in the basket. */ int count(); /* * @param i The item to count * * @return The number of the provided Item that are in the basket */ int countItem(Item i); /* * @return the total cost in cents of all items in the basket, counting duplicates */ int totalCost(); /* * @param i The item to add */ void addToBasket(Item t); /* * Remove a single copy of an item from the basket * * @param i The Item to remove * * @return false if the item was not in the basket, true otherwise */ boolean removeFromBasket(Item i); /* * Remove all copies of an item from the basket * * @param i The Item to remove * * @return false if the item was not in the basket, true otherwise */ boolean removeAllFromBasket(Item i); /* * Remove all items from the basket */ void empty(); } ======================================================================================================================================= Item.java ======================================================================================================================================== package cse12pa1student;
public class Item { String name; int priceInCents; public Item(String name, int priceInCents) { this.name = name; this.priceInCents = priceInCents; } @Override public boolean equals(Object other) { if(!(other instanceof Item)) { return false; } Item i = (Item)other; return i.name.equals(this.name) && i.priceInCents == this.priceInCents; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER The complete test class java import static orgjunitAssert import orgjunitTest p... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!