Test 3D Feedback

Fields
1 / 1  -is there a private, non-static list or map for the coins?
1 / 1  -is there a private, non-static field for the owner?

Constructors 
-OwnedPiggyBank(Owner)
1 / 1  -is a new empty collection of coins created?
1 / 1  -is the owner set using aggregation?
 
-OwnedPiggyBank(OwnedPiggyBank)
2 / 2  -is the collection of coins copied using a shallow (or deep) copy?
1 / 1  -the the owner set using aggregation?

Methods
-getOwner
1 / 1  -returns a reference to the owner?
      
-add(List<Coin>)
2 / 2  -are the coins added to the collection of coins?

-contains
1 / 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
1 / 2  -returns a sorted deep copy of the coins?
 
--------------------
TA Comments:

-see solutions for remove and removeCoins

-deepCopy is almost correct; you just needed to write the for each loop correctly

--------------------
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.ArrayList;
import java.util.List;

/**
 * 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.
         */
        private List<Coin> bank; 
        private Owner owner;
        /**
         * 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; // this is privacy leak, but I can't think of a good way to copy 
                // the parameter "owner" right away.
                
                this.bank = new ArrayList<Coin>();
        }

        /**
         * 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.bank = new ArrayList<Coin>(other.bank);
                this.owner = other.owner; // privacy leak... 
        }

        /**
         * Returns the owner of this piggy bank.
         * 
         * @return the owner of this piggy bank
         */
        public Owner getOwner() {
                
                return this.owner;
        }

        /**
         * 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) {
                this.bank.addAll(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 this.bank.contains(coin);
                
        }

        /**
         * 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) {
                if (this.owner.equals(user)){
                        
                }
                        
                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() {
                List<Coin> copyBank = new ArrayList<Coin>();
                for( : Coin t ){
                        
                        copyBank.add(new Coin(t));
                }
                return copyBank;
        }
}

--------------------

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?
1 / 1  -the coins in the list are immutable?

C 
1 / 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. 

(Part c)
 It is an aggregation of an Owner because it is impossible to make a copy of an Owner. 

C. 
piggy.getOwner() = me; doesn't compile. There is no way to change the owner of 
an OwnedPiggyBank.

It returns a reference to the owner which allows any client to empty the piggy 
bank of its coins. 
--------------------

Your submission:

A.
(a)
List<Owners> copyt = new ArrayList<>(t);

(b)

(c)
I choose an aggregation relationship between 
OwnedPiggyBank and it's owner. this is because 
owners doesn't have a copy constructor.  

B.
no, the Coin class does not have any way of changing a
coin objects value with out creating a new 
coin and since it is a copy of a list that is
returned, changinf the copy does not affect
the original list 

C.
Privacy leak is in OwnedPiggyBank's getOwner method.
Since the Owner class does not have a copy constructor
I can not return a copy of this.owner.

someone could call piggy.getOwner= me // me is an Owner object, piggy is a OwnedPiggyBank object