CMSC 206 (Data Structures)
Assignment#2
Part 1 (100 pts) due: September 22, 2013 11:59:59pm
Part 2 (100 pts) due: September 29, 2013
11:59:59pm
The goal of this assignment is
to develop your ability to use control flow statements to make
a user menu and do object-oriented programming,
focusing specifically on inheritance and code reuse.
In this assignment,
you will write a program that allows a user to repeatedly
create and manage express card accounts.
Each express card is like
a debit card, except that it can only be used to purchase
meals. A new express card account starts at a balance of
$0. The user can (1) deposit money to the express card,
increasing the balance (by depositing more money),
(2) purchase meals at a fixed rate,
thus decreasing the balance, and (3) have meals (
each swipe of the card reduces
the remaining number of meals by one).
There are two types of express card accounts:
a student express account or a faculty
express account.
All express account have fields accountNumber, accountBalance, numberOfMeals,
pricePerMeal, baseAmtForBonus and accountTypeName.
The field baseAmtForBonus is used to record the bonus cashback for an account
when making a deposit. This is a base amount
one-time deposit (baseAmtForBonus) to receipt bonus which is
the minimum amount of money for each deposit. For example,
if the baseAmtForBonus for a student is $500 and deposit $499
for a student account will not receive any bonus.
The criteria of receiving bonus for these two types
of express accounts are different:
To begin, download
CS206Assignment2.jar.
This (jar) file is a completed version of the assignment
that you can study.
To run this completed
program, use the command java -jar CS206Assignment2.jar
Here's an example trace of the
program running once the assignment is complete.
Welcome to CS206 Fall'13 Express Account 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.) Student express account
2.) Faculty express account
Please enter your selection: 1
Created new Student Express account #0, balance: $0.0, number of meals: 0
STUDENT EXPRESS ACCOUNT #0, BALANCE: $0.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 1
Enter deposit amount: 600
Received bonus of $6.0
Deposit $600.0 New balance $606.0
STUDENT EXPRESS ACCOUNT #0, BALANCE: $606.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 2
Enter the number of meals you want to purchase: 1
Purchased 1 meals with $10.0 per meal New balance $596.0
STUDENT EXPRESS ACCOUNT #0, BALANCE: $596.0, NUMBER OF MEALS: 1
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 3
STUDENT EXPRESS ACCOUNT #0, BALANCE: $596.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 3
No meals left on your account. Please purchase meals first.
STUDENT EXPRESS ACCOUNT #0, BALANCE: $596.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 1
Enter deposit amount: 0
The deposit must be a positive amount.
STUDENT EXPRESS ACCOUNT #0, BALANCE: $596.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 2
Enter the number of meals you want to purchase: 60
Not enough balance for 60 meals
Purchased 59 meals, New balance $6.0
STUDENT EXPRESS ACCOUNT #0, BALANCE: $6.0, NUMBER OF MEALS: 59
1.) Make a deposit
2.) Purchase meals
3.) Have meal
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 system
Please enter your selection: 1
CHOOSE THE TYPE FOR THE NEW ACCOUNT
1.) Student express account
2.) Faculty express account
Please enter your selection: 2
Created new Faculty Express account #1, balance: $0.0, number of meals: 0
FACULTY EXPRESS ACCOUNT #1, BALANCE: $0.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 1
Enter deposit amount: 80
Received bonus of $0.8
Deposit $80.0 New balance $80.8
FACULTY EXPRESS ACCOUNT #1, BALANCE: $80.8, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 2
Enter the number of meals you want to purchase: 3
Purchased 3 meals with $8.0 per meal New balance $56.8
FACULTY EXPRESS ACCOUNT #1, BALANCE: $56.8, NUMBER OF MEALS: 3
1.) Make a deposit
2.) Purchase meals
3.) Have meal
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 system
Please enter your selection: 3
Exiting the system
In this part, you are going to use control flow statements to make a user menu with only one general express account type. The following is the program requirements for this simplified version of the general express account class.
In this part, you are going to use control flow statements to make a user menu with only one general express account type. This means that the menu is pretty much the same as the final version showed above, except that there is only one type of express accounts. Here's an example trace of the program.
Welcome to CS206 Fall'13 Express Account 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.) Express account
Please enter your selection: 1
Created new Express account #0, balance: $0.0, number of meals: 0
EXPRESS ACCOUNT #0, BALANCE: $0.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 1
Enter deposit amount: 600
Deposit $600.0 New balance $600.0
EXPRESS ACCOUNT #0, BALANCE: $600.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 2
Enter the number of meals you want to purchase: 1
Purchased 1 meals with $10.0 per meal New balance $590.0
EXPRESS ACCOUNT #0, BALANCE: $590.0, NUMBER OF MEALS: 1
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 3
EXPRESS ACCOUNT #0, BALANCE: $590.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 3
No meals left on your account. Please purchase meals first.
EXPRESS ACCOUNT #0, BALANCE: $590.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 1
Enter deposit amount: 0
The deposit must be a positive amount.
EXPRESS ACCOUNT #0, BALANCE: $590.0, NUMBER OF MEALS: 0
1.) Make a deposit
2.) Purchase meals
3.) Have meal
4.) Log out
Please enter your selection: 2
Enter the number of meals you want to purchase: 60
Not enough balance for 60 meals
Purchased 59 meals, New balance $0.0
EXPRESS ACCOUNT #0, BALANCE: $0.0, NUMBER OF MEALS: 59
1.) Make a deposit
2.) Purchase meals
3.) Have meal
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 system
Please enter your selection: 2
EXPRESS ACCOUNT #0, BALANCE: $0.0, NUMBER OF MEALS: 59
1.) Make a deposit
2.) Purchase meals
3.) Have meal
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 system
Please enter your selection: 3
Exiting the system
System.arraycopy
method to increase the size the the original array.
java.util.Scanner
to directly accept input from System.in
or use java.io.BufferedReader
to read text from a character-input stream, buffering characters so as to provide
for the efficient reading. Check Java Doc according to your JDK version for the
usage of these classes.
Question: What about making a deposit, purchasing meals, having meals? Where should these functionalities go?
LastnameFirstname-Assignment2-PartX
.
java Assignment2
is
called from the terminal.LastnameFirstname-Assignment2-PartX
folder as a zip or tar file, and submit it via Dropbox,
as detailed in the assignment
submission instructions.