APCS-A Java Classwork: Marble Bank
For this classwork (and the next few classworks) you will practice creating
simple standalone classes from which "objects" can be created. So, for this
assignment, create a non-static class named 'MarbleBank' in its own file.
The class should contain two constructors. The first takes no arguments and
sets the starting marble count to zero. The second constructor takes a single
positive integer as its argument, representing the initial number of marbles
in the bank, and sets the starting marble count to that number. For example,
a call such as
MarbleBank bank1 = new MarbleBank();
will create a new MarbleBank object named 'bank1' that will set up a bank
containing no marbles, while a call such as
MarbleBank bank2 = new MarbleBank(25);
will create a new MarbleBank object named 'bank2' that will set up a bank
containing 25 marbles. If the argument sent into the second constructor
for the initial marble count is a negative integer, then the initial marble
count should be set to zero.
Note that the above calls to the 'MarbleBank' class are merely examples. The
identifiers 'bank1' and 'bank2', as well as the number 25 (or any specific
marble number), should not appear ANYWHERE in your "MarbleBank.java" file.
The method 'main' and the keyword 'static' must not appear anywhere in the
'MarbleBank' class. Make sure the internal variables in that class are
private. The class should contain the following public methods:
countMarbles
Arguments: None
Displays: Nothing
Returns: An integer equal to the current number of marbles in the
bank
-------------
addMarbles
Arguments: A positive integer representing the number of new marbles
to add to the bank
Actions: Adds the newly supplied number of marbles to the bank,
unless the integer is negative, in which case nothing
should happen
Displays: Nothing
Returns: Nothing
-------------
emptyBank
Arguments: None
Actions: Sets the current number of marbles in the bank to zero
Displays: Nothing
Returns: Nothing
As always, all of your code must be your own, written entirely and
only by you within your online CodeHS.com account. You must never
copy/paste, receive, view, or in any way use code that was created
or modified by another person, entity, or artificial intelligence.
Advanced Option
To the 'MarbleBank' class, add another public method named 'showHistory' that
displays the number of individual marbles added to the bank during each prior
call to the 'addMarbles' method since the creation of the 'MarbleBank' object
or since the last call to 'emptyBank'. The method should not return anything.