OOPDA Lab 02-1: Continues from demonstration to create class BillEclipse Project: Lab02_1Weissman (use your own
name!).
•
•
Each paper BILL has a value in dollars (1, 2,
5, 10, 20 etc.)
Each paper BILL also has a series designator
consisting of a 4-digit year and (usually) a
letter, like “2004A”
class Bill contains the following methods:
public Bill(int value, String series);
public int getValue(); //returns value of bill in dollars
public String getSeries(); //returns series designator
public String toString();
1. [Instructor-led: create Eclipse project, Bill, and initial version of Tester]
• Code class Bill in a project Lab02_1Weissman (use your own name!!)
WALLET contains a collection of zero or more paper money BILLs.
2. Code class Wallet to encapsulate a collection of
➔Required: Implement the collection using an ArrayList with custom methods to
•
Constructor with no arguments [must initialize the private instance variable]
Pseudo-code for
void addBill( int value, String series )
billsList.add (new Bill( value, series));
Notes:
• billsList could be name of the Arraylist
•
must make a new Bill object to add to the ArrayList.
o Note that the new Bill is anonymous: gets added to ArrayList and doesn’t need a unique name!
•
int totValue() //LOOPS to total all bills in the wallet — returns value in dollars
•
void displayAll() //output each Bill in wallet [could use toString()]
➔implement using a for-each loop
•
int countBySeries(String sn)
//count number of bills with a given series – returns count
// sn can be partial, like “2004” instead of “2004A”
// reminder: use contains() for partial String match
➔implement using a for-each loop
Lab 02-01 rev SP23
1/19/2023 5:51 PM
3. Add class Tester with a main() method to your project that will:
• Instantiate a new Wallet object myMoney
• add at least four Bills to myMoney [vary the data to test functionality]
• display the total value of all the bills in myMoney
• display the count of bills of a given series value:
e.g., how many bills in series 2004A are in the myMoney collection?
Deliverable: Attach zip of Eclipse project, plus a screen shot of output from a trial run (jpg, png or in a
Word doc). Be sure and include Javadoc in Tester, Wallet to acknowledge any help received. In the
submit textbox, be sure and note any known omissions or defects.
Lab 02-01 rev SP23
1/19/2023 5:51 PM