CMSC 206 (Introduction to Computing)
Assignment#1
Part A Due: September 07, 2011
11:59:59pm
Part B Due: September 19, 2011
11:59:59pm
Part B Due: September 21, 2011
11:59:59pm
The goal of this assignment is to
develop your ability to do object-oriented programming, focusing
specifically on inheritance.
To begin, download these two
files: Assignment1Skeleton.java
and CS206Assignment1.jar.
The first (java) file is skeleton version of the program; start with
this file and fill in the parts marked as "FIXME" to complete the
assignment. The second (jar) file is a completed version of the
assignment that you can study. To run this completed program, use
the command java -jar CS206Assignment1.jar
Introduction
You will write a program that allows a
user to repeatedly create new credit accounts from three possible
types: a standard account, a gold account, or a last-chance account.
- A standard credit account has an annual interest rate of 15%, and
an upper limit of $4,000.
- A gold account has an annual interest rate of 10% and an upper
limit of $100,000. In addition, gold card holders earn 2% cashback on
every purchase.
- A last-chance account is for people with a bad credit history.
The annual interest rate is 25% and there is a $1,000 charge limit.
However, a last chance card holder can get a better deal by
consistently paying off the entire balance. If a last chance card
holder pays off the balance three times in a row, then their interest
rate drops to 20% and their limit increases to $1,500. However,
if they miss a payment (noted by a payment of 0), their interest rate
will increase to 27%.
Program
Requirements
Starting
with the skeleton file provided above, you will modify the two parts
marked as "FIXME" to complete the assignment.
- Complete the userMenu() function to properly display the options
for interacting with a single account, following the menu format given
below in the example trace. The
skeleton file already provides examples of several menus that you can
model to complete this task. Your function should use proper
error checking on the inputs, especially when prompting the user for
charge/payment amounts. Experiment with the demo program given in
the jar file above, trying different inputs to see how the program
behaves.
- Implement
an abstract class CreditAccount that includes
the following attributes and methods at a minimum (you can add others of
your own design):
- Private
Variables: accountNumber, accountBalance, creditLimit,
interestRate.
- Accessors
and setters for all private variables needed outside the class with
appropriate public/protected access levels.
- A
toString() function that outputs a textual description of the account,
which is used in the provided code.
- The
following two abstract functions:
- void
charge(double amount) which takes in an amount to charge against the
account and throws an exception if this amount would push the balance
over the credit limit. This exception should be properly handled
in the calling code.
- void
makePayment(double amount) which reduces the balance by the specified
amount. You can assume that this function is called only once at
the end of each month, and so it is also responsible for assessing
interest on the balance if it is not paid in full. Note that this
interest should be assessed against the balance prior to the amount
being paid off. For example, if the balance is $200 and the user
pays $50, the interest would be assessed against $200. The
interest
rates listed above are annual rates, so you should divide them by 12 to
get
the monthly rate used to compute the interest in the makePayment()
function.
- Implement
classes for each of the three account types that extend the
CreditAccount and implement the appropriate behavior for each type of
account. These subclasses should reuse as much as possible from
the base CreditAccount class. If functionality is shared between
all three account types, then it should be included in the
CreditAccount class (i.e., don't implement the same thing three times
in the subclasses, implement it once
in the CreditAccount class).
- Be
sure to do error checking on the inputs. Negative payments and
charges are not allowed, although the user can carry a minimum balance.
- Although
most credit cards usually have a minimum payment due, we will ignore
this aspect for this assignment.
- Since
we're working with money, all decimals need to be rounded off to two
decimal places. You can achieve this by multiplying a decimal by
100, rounding using Math.round(), and then dividing the result by
100.0. I suggest making a function to do this, since you will
need to do it a lot.
- All
of the provided code can be used as-is, except where noted explicitly
in the file. In other words, you should not need to change
anything in main, in any of the menu functions other than userMenu(),
and the utility functions.
- While
you are free to be creative with some of the messages, you program must
follow the same menu structure, the ordering of the options, and the
effects of each button press. In other words, if I close my eyes
at the main menu and then choose option 2, enter account number 0, then
option 2, and then type 300, your program should do the exact same
thing (charge the account $300) as the sample program. You can
improve the look of the menu system, the wording of the messages, the
formatting of the amounts (for example, make all dollar amounts be
outputted to two decimal places), and the output details; just don't
change the program functionality. If you do wish to add new
features, you can add additional
items to the end of any menu.
Part
A
For part A of this assignment, you should complete the userMenu()
method to make a functioning menu system. However, to simply
things, instead of actually acting on the accounts, simply print out
the action the program
would
have taken if it were complete. You should not need to modify any
code outside of the userMenu() function to accomplish this.
This part is only to have you do some basic coding, compile the
program, and submit it. Don't worry about doing it wrong.
So long as you have some form of a functional user menu, you will get
full credit for completing this part. However, here is an example
trace to give you an idea of what I'm looking for:
Welcome
to CS206 Fall'11 Credit Company
MAIN MENU
1.) Create a new account
2.) Log into an existing account
3.) Exit the banking system
Please enter your selection: 1
CHOOSE THE TYPE FOR THE NEW ACCOUNT
1.) Standard credit account
2.) Gold credit account
3.) Last-chance credit account
Please enter your selection: 1
Created new standard credit account #0 with a credit limit of $4000.0
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 2
TODO: CHARGE THE CREDIT ACCOUNT
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 3
TODO: MAKE A PAYMENT TO THE ACCOUNT
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 1
TODO: PRINT THE BALANCE ON THE ACCOUNT
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 4
Goodbye!
Part
B
This second part is simply to complete the rest of the assignment, as
described in the Introduction and Program Requirements listed
above. Here's an example trace of the program running once Part B
is complete.
Welcome to CS206 Fall'11 Credit
Company
MAIN MENU
1.) Create a new account
2.) Log into an existing account
3.) Exit the banking system
Please enter your selection: 1
CHOOSE THE TYPE FOR THE NEW ACCOUNT
1.) Standard credit account
2.) Gold credit account
3.) Last-chance credit account
Please enter your selection: 1
Created new standard credit account #0 with a credit limit of $4000.0
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 2
Enter charge amount: 1000
Charged $1000.0 New balance $1000.0
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 3
Enter payment amount: 100
Charged interest $12.5
Received payment $100.0 New
balance $912.5
STANDARD CREDIT ACCOUNT #0 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 4
Goodbye!
MAIN MENU
1.) Create a new account
2.) Log into an existing account
3.) Exit the banking system
Please enter your selection: 1
CHOOSE THE TYPE FOR THE NEW ACCOUNT
1.) Standard credit account
2.) Gold credit account
3.) Last-chance credit account
Please enter your selection: 2
Created new gold credit account #1 with a credit limit of $100000.0
GOLD CREDIT ACCOUNT #1 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 2
Enter charge amount: 1000
Received cashback reward of $20.0
Charged $1000.0 New balance $980.0
GOLD CREDIT ACCOUNT #1 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 4
Goodbye!
MAIN MENU
1.) Create a new account
2.) Log into an existing account
3.) Exit the banking system
Please enter your selection: 1
CHOOSE THE TYPE FOR THE NEW ACCOUNT
1.) Standard credit account
2.) Gold credit account
3.) Last-chance credit account
Please enter your selection: 3
Created new last-chance credit account #2 with a credit limit of $1000.0
LAST-CHANCE CREDIT ACCOUNT #2 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 2
Enter charge amount: 1000
Charged $1000.0 New balance $1000.0
LAST-CHANCE CREDIT ACCOUNT #2 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 3
Enter payment amount: 0
Charged interest $20.83
Missed payment. Increasing interest rate to 27%.
Received payment $0.0 New balance
$1020.83
LAST-CHANCE CREDIT ACCOUNT #2 MENU
1.) Get a balance on your account
2.) Charge your account
3.) Make a payment
4.) Log out
Please enter your selection: 4
Goodbye!
MAIN MENU
1.) Create a new account
2.) Log into an existing account
3.) Exit the banking system
Please enter your selection: 3
Exiting Banking System
Implementation
Hints
- Start by compiling and running the provided java file. It
currently skips over the user menu, which you'll need to implement in
Part A.
- Also experiment with the provided demo in the jar file, noting
how the menus work, how the program functions, and how input errors are
handled.
- Read over the java file in detail several times to ensure that you
know how each line in the file works and what it does.
- Next, implement the user menu as described in the requirements
for Part A above.
- Implement the abstract CreditAccount class and then create the
class for the standard card. Get the standard card class working
correctly before moving on to the two other account types.
- Develop the CreditAccount and Standard account class
incrementally, slowing adding in functionality and then also
integrating that functionality into the user menu. Do not try to
build all functionality at once. Build one part, get it working,
and then move on to the next.
- Use good object-oriented design throughout the assignment,
focusing especially on code re-use. Always try to place common
functionality in the superclass, keeping the subclasses as minimal as
possible.
Submitting
the Assignment
Copy all your .java files for the project into a folder called
Assignment01-PartA or Assignment01-PartB in dropbox before the
deadlines. I will provide more detailed descriptions on
submitting files via dropbox shortly.
Acknowledgement: This assignment was adapted from a lab
assignment and materials provided by Andrew Danner. All code was
written by Eric Eaton.