CIS 636 Spring 2004     

Assignment 4 – Exception Handling, plus OOP in Java – Bringing Together Some Pieces  

100 points

Assigned: 02/19/2004

Due: 03/11/2003 at the start of class 

 

You may work individually or in pairs for this assignment. But all work must be the work of the person/people whose name is on the code! If working in pairs, the individual contributions should be relatively equal. One possibility is to work together tonight, then finish separately (to avoid communication difficulties).

 

Main Assignment:

We are building more pieces of the EZ Pass program. The next pieces to create are a Customer class, and a driver that provides a simulation of customers’ travels.   I encourage you to write Customer’s main as a simple test of the Customer class, and have a separate class whose main purpose is to drive the simulation (that way, you’ve tested the customer class before trying to put everything together.  Your Customer class will also throw an exception on at least one method; I will provide the definition of the exception class to throw (InsufficientFundsNonCreditException), you will throw it, and in the driver, catch it.

               A Customer class should be able to keep track of a customer ID (I encourage you to take the simple way out, and make this an integer, instead of say using my ID class. There are plenty of challenges in this assignment), customer  name (for simplicity, just use a single string), a current balance, their “replenishment amount” – the amount that needs to be added to their account when they use up their balance, and whether the customer is a credit card customer or not (a boolean). Note that you could create a general customer class, with subclasses for CreditCustomer and CheckCustomer. That would be more elegant, but it would be more work. I only encourage you to do that if you are coasting in this class. 

               The Customer class should provide a variety of constructors, allowing users a variety of ways to create an EzPass Customer.  ). It should provide all necessary accessors – inspectors and mutators, so that data can all be declared as private. Mutators should protect against bad data getting into objects (e.g. negative replenishment amount (NOTE: balance may occasionally have to go negative)).  The class should support versions of equals and toString appropriate to the class.

               The Customer class should also provide significant capabilities:

·        Decrease balance (given an amount).  More controlled than just setting the balance (in fact that method should probably be private so all decreases by “outsiders” will be done through this method. Decrease balance needs to check if the Customer has a large enough balance (decreasing it).

o       If the balance is not sufficient but the customer is a credit card customer, replenish the account (see below), post a credit card charge (see below), and reduce the balance. 

o       If the balance is not sufficient and the customer is NOT a credit card customer,

§        the balance should still be reduced – by the amount, and a $10 penalty,

§        but a bill needs to be sent (see below)  (for replenishment amount + $10) (don’t use this method to try to reduce the balance or we loop! – this method is an insider and can directly access the private instance variables),

§        and lastly an exception should be thrown.

·        Replenish Account (needs NO parameters).  Another controlled way of updating balance – adds the Customer’s replenishment amount to the Customer’s balance

·        Post a Credit Card Charge (given an amount). For this assignment, all it does it display a message saying which account  is being charged how much.

·        Send a Bill (given an amount). For this assignment, all it does it display a message saying which account  is being billed, and for how much.

·        Accept a Check Payment (given an amount).  Another controlled way of updating balance – adds the amount to the Customer’s balance.

               The driver program should (see sample interaction below):

·        Carry out set up, including creating an array of 10 customers, an array of 5 bridges, and another array of 6 interchanges (including setting up prices in each direction between each interchange). This set up can be specifically coded in your driver’s main. My sample interaction below uses a certain set of bridges and interchanges; you may use a different set – to save you tedious coding – you might want to reuse setup code from Assignment 3.

·        Display all customers, bridges, and interchanges

·        Loop until user requests to quit

o       Ask user for which customer to deal with

o       Loop until user says customer is done traveling for now

§        For that customer, ask if they are going over a bridge or the turnpike or paying bill, or quitting

§        If paying bill, find out amount and accept a check payment

§        If bridge, ask user which bridge they are going over, and process

§        If  turnpike, ask user starting and ending interchange, and process

§        (processing involves finding out the price, then decreasing the balance). If an exception is thrown, catch it, and stop the customer now

§        display customer status

·        Display all customer’s status

 

Hand in:

 

To avoid needless long waits, I recommend working on this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Miscellaneous:

·        MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors).  Your program needs to be able to handle any valid inputs, and catch invalid values. 

·        Make your Customer class as robust as possible in preparation for any possible future re-use.

·        If the user specifies the same starting and ending interchanges, your Interchange findToll (or whatever) method will not find a correct price.  It should have some way of defending itself and reporting a not found, but here the driver should probably cut off that possibility instead of putting the Interchange class to the test.

·        In your driver, I encourage you to use my RedmondMsgInBasic and RedmondMsgOut classes.  I wouldn’t use the robust versions in RedmondMsgIn just yet, you would get more than your fill of try and catch blocks.

·        Put YOUR NAME, and e-mail address, date, AND where to mount filesystem in the IDE,  in comments at the beginning of the program.

·        Also, comment any significant code to document it (each method, each loop, each if, and each significant calculation should have a comment. In particular, each method needs to have a JAVADOC compatible comment).

·        Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line).  The IDE should handle this if you hit ENTER and move on to the next line (If you make changes, you may need to TAB to make things right).

·        Name your variables meaningfully, to describe their use in the program.

·        There is a fair amount to this assignment.  A good strategy for working on a challenging program is to build and test it in parts (e.g. get the setup working, then add next capability and test that, etc)

·        Note that this assignment is not due until 3/11.  However, part of the reason for the far-out date is Spring Break – and I will be at a conference out of state for 4 days over Spring Break (Mar 3-6), during which time I will be barely accessible (attending talks most of the day, a line to access the computers, a time limit on using them).  Try to work steadily over the time you have.

  

Sample Interaction:


Bridges:

    Name: Betsy Ross  City: Pennsauken  State: NJ  Highway: NJ 90  Direction: East   Lanes: 3  Price: 2.7

    Name: Tacony Palmyra  City: Palmyra  State: NJ  Highway: NJ 73  Direction: East   Lanes: 2  Price: 2.0

    Name: George Washington  City: Newark  State: NJ  Highway: I-278  Direction: West   Lanes: 4  Price: 4.0

    Name: Delaware Memorial  City: DuPontville  State: NJ  Highway: I-295  Direction: East   Lanes: 4  Price: 3.0

    Name: Walt Whitman  City: Camden  State: NJ  Highway: NJ 38  Direction: East   Lanes: 2  Price: 2.7

Interchanges:

   Name: Ex0  City: City0  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex1: 0.6 Ex2: 1.2 Ex3: 1.8 Ex4: 2.4 Ex5: 3

   Name: Ex1  City: City1  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 0.5 Ex2: 0.6 Ex3: 1.2 Ex4: 1.8 Ex5: 2.4

   Name: Ex2  City: City2  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 1 Ex1: 0.5 Ex3: 0.6 Ex4: 1.2 Ex5: 1.8

   Name: Ex3  City: City3  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 1.5 Ex1: 1 Ex2: 0.5 Ex4: 0.6 Ex5: 1.2

   Name: Ex4  City: City4  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 2 Ex1: 1.5 Ex2: 1 Ex3: 0.5 Ex5: 0.6

   Name: Ex5  City: City5  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 2.5 Ex1: 2 Ex2: 1.5 Ex3: 1 Ex4: 0.5

Customers:

    ID: 111  Name: Alice Cooper  Balance: 5.0  Cred: false  Replenish: 10.0

    ID: 222  Name: Bruce Springsteen  Balance: 10.0  Cred: true  Replenish: 20.0

    ID: 333  Name: Chrissie Hynde  Balance: 15.0  Cred: false  Replenish: 30.0

    ID: 444  Name: David Bowie  Balance: 20.0  Cred: false  Replenish: 20.0

    ID: 555  Name: Edgar Winter  Balance: 25.0  Cred: true  Replenish: 40.0

    ID: 666  Name: Frank Zappa  Balance: 5.0  Cred: true  Replenish: 20.0

    ID: 777  Name: Gary Neuman  Balance: 10.0  Cred: false  Replenish: 50.0

    ID: 888  Name: Harry Nilson  Balance: 15.0  Cred: false  Replenish: 20.0

    ID: 999  Name: Jackson Browne  Balance: 20.0  Cred: true  Replenish: 60.0

    ID: 121  Name: Kurt Cobain  Balance: 25.0  Cred: false  Replenish: 20.0

Choose Customer by Number Shown

0: Alice Cooper

1: Bruce Springsteen

2: Chrissie Hynde

3: David Bowie

4: Edgar Winter

5: Frank Zappa

6: Gary Neuman

7: Harry Nilson

8: Jackson Browne

9: Kurt Cobain

0

Now working with: ID: 111  Name: Alice Cooper  Balance: 5.0  Cred: false  Replenish: 10.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

1

Choose Bridge by Number Shown

0: Betsy Ross

1: Tacony Palmyra

2: George Washington

3: Delaware Memorial

4: Walt Whitman

2

Now working with:  Name: George Washington  City: Newark  State: NJ  Highway: I-278  Direction: West   Lanes: 4  Price: 4.0

Customer has been updated: ID: 111  Name: Alice Cooper  Balance: 1.0  Cred: false  Replenish: 10.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

2

Choose Starting Interchange by Number Shown

0: Ex0

1: Ex1

2: Ex2

3: Ex3

4: Ex4

5: Ex5

5

Starting at:  Name: Ex5  City: City5  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here -    

      Price List for starting at:

           Ex0: 2.5 Ex1: 2 Ex2: 1.5 Ex3: 1 Ex4: 0.5

Choose Ending Interchange by Number Shown

(Choosing same exit will result in no travel, no toll)

0: Ex0

1: Ex1

2: Ex2

3: Ex3

4: Ex4

5: Ex5

0

Ending at:  Name: Ex0  City: City0  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex1: 0.6 Ex2: 1.2 Ex3: 1.8 Ex4: 2.4 Ex5: 3

You owe 20.0 we know where you live ID: 111  Name: Alice Cooper  Balance: -12.0  Cred: false  Replenish: 10.0

Handled Problem - Customer: ID: 111  Name: Alice Cooper  Balance: -12.0  Cred: false  Replenish: 10.0 couldn't pay 3.0 toll. Ending this customer.

Done with Customer: ID: 111  Name: Alice Cooper  Balance: -12.0  Cred: false  Replenish: 10.0

Are you done working with customers?

n

Choose Customer by Number Shown

0: Alice Cooper

1: Bruce Springsteen

2: Chrissie Hynde

3: David Bowie

4: Edgar Winter

5: Frank Zappa

6: Gary Neuman

7: Harry Nilson

8: Jackson Browne

9: Kurt Cobain

5

Now working with: ID: 666  Name: Frank Zappa  Balance: 5.0  Cred: true  Replenish: 20.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

1

Choose Bridge by Number Shown

0: Betsy Ross

1: Tacony Palmyra

2: George Washington

3: Delaware Memorial

4: Walt Whitman

0

Now working with:  Name: Betsy Ross  City: Pennsauken  State: NJ  Highway: NJ 90  Direction: East   Lanes: 3  Price: 2.7

Customer has been updated: ID: 666  Name: Frank Zappa  Balance: 2.3  Cred: true  Replenish: 20.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

2

Choose Starting Interchange by Number Shown

0: Ex0

1: Ex1

2: Ex2

3: Ex3

4: Ex4

5: Ex5

1

Starting at:  Name: Ex1  City: City1  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 0.5 Ex2: 0.6 Ex3: 1.2 Ex4: 1.8 Ex5: 2.4

Choose Ending Interchange by Number Shown

(Choosing same exit will result in no travel, no toll)

0: Ex0

1: Ex1

2: Ex2

3: Ex3

4: Ex4

5: Ex5

4

Ending at:  Name: Ex4  City: City4  State: NJ  Highway: NJ Turnpike  Direction: North  Lanes: 2  Ending here –

      Price List for starting at:

           Ex0: 2 Ex1: 1.5 Ex2: 1 Ex3: 0.5 Ex5: 0.6

Customer has been updated: ID: 666  Name: Frank Zappa  Balance: 0.7999999999999998  Cred: true  Replenish: 20.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

1

Choose Bridge by Number Shown

0: Betsy Ross

1: Tacony Palmyra

2: George Washington

3: Delaware Memorial

4: Walt Whitman

1

Now working with:  Name: Tacony Palmyra  City: Palmyra  State: NJ  Highway: NJ 73  Direction: East   Lanes: 2  Price: 2.0

Debit of 20.0 to credit card account for ID: 666  Name: Frank Zappa  Balance: 18.8  Cred: true  Replenish: 20.0

Customer has been updated: ID: 666  Name: Frank Zappa  Balance: 18.8  Cred: true  Replenish: 20.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

4

Done with Customer: ID: 666  Name: Frank Zappa  Balance: 18.8  Cred: true  Replenish: 20.0

Are you done working with customers?

n

Choose Customer by Number Shown

0: Alice Cooper

1: Bruce Springsteen

2: Chrissie Hynde

3: David Bowie

4: Edgar Winter

5: Frank Zappa

6: Gary Neuman

7: Harry Nilson

8: Jackson Browne

9: Kurt Cobain

0

Now working with: ID: 111  Name: Alice Cooper  Balance: -12.0  Cred: false  Replenish: 10.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

3

How much was paid?  $

20

Customer has been updated: ID: 111  Name: Alice Cooper  Balance: 8.0  Cred: false  Replenish: 10.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

1

Choose Bridge by Number Shown

0: Betsy Ross

1: Tacony Palmyra

2: George Washington

3: Delaware Memorial

4: Walt Whitman

1

Now working with:  Name: Tacony Palmyra  City: Palmyra  State: NJ  Highway: NJ 73  Direction: East   Lanes: 2  Price: 2.0

Customer has been updated: ID: 111  Name: Alice Cooper  Balance: 6.0  Cred: false  Replenish: 10.0

Choose:

   1 - Go Over Bridge

   2 - Go on turnpike

   3 - Pay Bill

   4 - Quit this Customer

4

Done with Customer: ID: 111  Name: Alice Cooper  Balance: 6.0  Cred: false  Replenish: 10.0

Are you done working with customers?

y

All Customers:

    ID: 111  Name: Alice Cooper  Balance: 6.0  Cred: false  Replenish: 10.0

    ID: 222  Name: Bruce Springsteen  Balance: 10.0  Cred: true  Replenish: 20.0

    ID: 333  Name: Chrissie Hynde  Balance: 15.0  Cred: false  Replenish: 30.0

    ID: 444  Name: David Bowie  Balance: 20.0  Cred: false  Replenish: 20.0

    ID: 555  Name: Edgar Winter  Balance: 25.0  Cred: true  Replenish: 40.0

    ID: 666  Name: Frank Zappa  Balance: 18.8  Cred: true  Replenish: 20.0

    ID: 777  Name: Gary Neuman  Balance: 10.0  Cred: false  Replenish: 50.0

    ID: 888  Name: Harry Nilson  Balance: 15.0  Cred: false  Replenish: 20.0

    ID: 999  Name: Jackson Browne  Balance: 20.0  Cred: true  Replenish: 60.0

    ID: 121  Name: Kurt Cobain  Balance: 25.0  Cred: false  Replenish: 20.0