Test 3D Feedback Fields 0 / 1 -is there a private, non-static list or map for the coins? 0.5 / 1 -is there a private, non-static field for the owner? Constructors -OwnedPiggyBank(Owner) 0 / 1 -is a new empty collection of coins created? 1 / 1 -is the owner set using aggregation? -OwnedPiggyBank(OwnedPiggyBank) 0 / 2 -is the collection of coins copied using a shallow (or deep) copy? 1 / 1 -the the owner set using aggregation? Methods -getOwner 0 / 1 -returns a reference to the owner? -add(List<Coin>) 0 / 2 -are the coins added to the collection of coins? -contains 0 / 1 -is the correct boolean value returned? -remove(Owner, Coin) 0 / 1 -returns null if the user is not the owner? 0 / 1 -removes the correct coin from the collection of coins? 0 / 1 -returns the correct coin? -removeCoins 0 / 2 -returns the correct list of coins? -deepCopy 0 / 2 -returns a sorted deep copy of the coins? -------------------- TA Comments: -the fields should not be public -you need a field for the collection of coins (a list, or array, or map) -please see solutions -------------------- Unit tester output: YOUR SUMBISSION FAILED SOME UNIT TESTS Here is the test output: java -classpath .:/home/burton/work/teaching/2017F/2030/marking/secEtest3D/_jar/* org.junit.runner.JUnitCore test3.Test3Suite JUnit version 4.12 Exception in thread "main" java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy -------------------- Your submission: package test3; import java.util.List; import test3.Coin; import test3.Owner; /** * A class representing a piggy bank that has an owner. * A piggy bank owns a collection (or possibly collections) of coins, * but does not own the coins themselves. * * <p> * Only the owner of the piggy bank is able to remove coins * from the piggy bank. */ public class OwnedPiggyBank { /** * You should add some fields here. */ public Owner owner; public Coin coin; private int value /** * Initializes this piggy bank so that it has the specified owner * and no coins. * * @param owner * the owner of this piggy bank */ public OwnedPiggyBank(Owner owner) { this.owner = owner; Coin nCoin = new Coin(0); } /** * Initializes this piggy bank by copying another piggy bank. This piggy * bank will have the same owner and the same number and type of coins as * the other piggy bank. * * @param other * the piggy bank to copy */ public OwnedPiggyBank(OwnedPiggyBank other) { this.owner = other.getOwner(); this.value = other. } /** * Returns the owner of this piggy bank. * * @return the owner of this piggy bank */ public Owner getOwner() { return null; } /** * Adds the specified coins to this piggy bank. * * @param coins * a list of coins to add to this piggy bank */ public void add(List<Coin> coins) { } /** * Returns true if this piggy bank contains the specified coin, and false * otherwise. * * @param coin * a coin * @return true if this piggy bank contains the specified coin, and false * otherwise */ public boolean contains(Coin coin) { return false; } /** * Allows the owner of this piggy bank to remove a coin equal to the value * of the specified coin from this piggy bank. * * <p> * If the specified user is not equal to the owner of this piggy bank, * then the coin is not removed from this piggy bank, and null is returned. * * @param user * the person trying to remove the coin * @param coin * a coin * @return a coin equal to the value of the specified coin from this piggy * bank, or null if user is not the owner of this piggy bank * @pre. the piggy bank contains a coin equal to the specified coin */ public Coin remove(Owner user, Coin coin) { return Coin.PENNY; } /** * Allows the owner of this piggy bank to remove * the smallest number of coins whose total value in cents is equal * to the specified value in cents from this piggy bank. * * <p> * Returns the empty list if the specified user is not equal to * the owner of this piggy bank. * * @param user * the person trying to remove coins from this piggy bank * @param value * a value in cents * @return the smallest number of coins whose total value in cents is equal * to the specified value in cents from this piggy bank * @pre. the piggy bank contains a group of coins whose total value is equal * to specified value */ public List<Coin> removeCoins(Owner user, int value) { // You should consider attempting this method last. return null; } /** * Returns a deep copy of the coins in this piggy bank. The returned list * has its coins in sorted order (from smallest value to largest value; * i.e., pennies first, followed by nickels, dimes, quarters, loonies, and * toonies). * * @return a deep copy of the coins in this piggy bank */ public List<Coin> deepCopy() { return null; } } -------------------- Written answers marking scheme A 2 / 2 -is the shallow copy performed correctly? 0 / 1 -no, a deep copy of a list of Owners cannot be made? 0 / 1 -is a suitable explanation given? 1 / 1 -aggregation instead of composition? 1 / 1 -is a suitable explanation given? B 1 / 1 -no, the state of the piggy cannot be modified using shallowCopy? 1 / 1 -the returned list is a new list? 0 / 1 -the coins in the list are immutable? C 0 / 1 -returns a reference to the owner? 0 / 2 -is a suitable explanation given? -------------------- TA Comments A. (Part b) No, there is no copy constructor in Owner, and the constructor Owner(String name) makes a new owner that is not equal to any other Owner because its id is guaranteed to be unique. B. No, the returned list is a new list so modifying the list does not modify the piggy bank's internal collection. Coin is immutable, so it is impossible to change the values of the coins in the returned list or in the piggy bank itself. C. Neither the Owner nor the Coins can be manipulated by a client; both classes are immutable. It returns a reference to the owner which allows any client to empty the piggy bank of its coins. -------------------- Your submission: A. (a)List<Owner> copyt = new ArrayList<>(t); List<Owner> newt = new ArrayList<>(copyt); (b)It is possible to make a deep copy of t List<Owner> copyt = new ArrayList<>(t); For(i=0;t.length()>i;i++){ copyt.add(i,t.get(i)); } (c)OwnedPiggyBank is an aggregation of an Owner because if the OwnedPiggyBank was removed as a class. Owner would still be a functional class B.No, because in a shallow copy, the list is a copy of the original and they can only manipulate the elements in the copy, not the original list. C.when creating an OwnedPiggyBank, the owner is directly copied as well as the coins, rather than deep copied. so if anyone has access to the orignial OwnedPiggyBank, they can manipulate the Owner and Coins objects as well