Results 1 to 6 of 6
Thread: Account manager program in Java
- 03-27-2012, 08:00 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 26
- Rep Power
- 0
Account manager program in Java
Alright, I'm supposed to create a program that manages financial accounts. Here is the program requirements:
I know it's asking a lot, but I don't need someone to program this for me (I know it might seem like that, and I'm sorry if that's how I come across), I just need some help getting this program started and rolling. If someone could point me to some online Java examples that could help me with parts of this, that would be great.- three classes: a driver class that conducts the user interaction (with a main( ) method),
a class that stores information about a single account, and a class that stores a collection of account
objects (with no limit on the number of accounts in the collection)
- The account class defines a simple object with four fields:
id: a string of four digits
last name: a string
first name: a string
balance: a float or double representing the amount of money in the account
This class should have get( ) and set( ) methods for each of its fields. It should also have a
toString() method that returns a string containing the values of the four fields.
- The account storage class must maintain a collection of account objects in an array. It should
provide the methods necessary to implement the commands of the driver. This includes
methods to add, delete, update, and search for and retrieve information about accounts. You will
need separate search methods for access by id and access by last name. Exceptions should be
thrown for the following operations: a debit operation that would result in a negative balance; an
add operation for an account number that already exists; and a delete operation for an account that
does not exist.
- If any exceptions are thrown by the account storage class during the implementation of an
operation, the driver should print an appropriate message and skip the transaction.
The format for input/output files (for the load and save commands) should be one account per line,
with the values of the four fields separated by whitespace in the following order:
<id> <last name> <first name> <balance>
Don't put dollar signs or commas in the balance string, and limit the fractional part of the balance to
two digits. Example:
2345 Anderson Andrew 224422.79
6733 Johnson Julia 42.16
- The format for the transaction file (for the update command) should be one transaction per line,
with fields separated by white space. The first field is a one-letter transaction code: a, d, or u,
representing the add, delete, or update operations. The second field is the account number, and the
remaining fields (if any) depend on the transaction code. An update is either a credit operation (if
the amount is positive) or a debit operation (if the amount is negative).
a <id> <lastname> <firstname> <amount>
d <id>
u <id> <amount>
- 03-27-2012, 11:49 AM #2
Re: Account manager program in Java
Homework doesn't qualify as 'Advanced' Java.
Moving to New to Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 03-27-2012, 01:23 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
Re: Account manager program in Java
Create an Account class first and play a bit with it and see if it works as it should (implement the getter and setter methods and the toString() method for it). That AccountManager class can come later ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-27-2012, 07:17 PM #4
Member
- Join Date
- Feb 2012
- Posts
- 26
- Rep Power
- 0
Re: Account manager program in Java
Alright, I salvaged some old code for my main class (UserInteraction), and then I created a new class called Account that handles the "add" option in the "run" method of UserInteraction. What I'm stuck on now is calling the Account class from the "run" method in UserInteraction. I'm pretty sure I would use the "inreader.next()" function but I'm not sure how to implement that for multiple variables being entered after the word "add". I will continue to work on it to see if I can get it, but here is what I have so far:
UserInteraction:
AccountJava Code:import java.io.*; import java.util.*; import java.lang.*; public class UserInteraction { Scanner inreader, filereader; File infile; Account account; public UserInteraction() { inreader = new Scanner(System.in); account = new Account(); } public void run() { String command; showMenu(); command = getCommand(); while(!command.equals("quit")) { if (command.equals("load")) { infile = new File(inreader.next()); } else if (command.equals("help")) { showMenu(); } else if (command.equals("add")) { //needs code here } else { System.out.println("Unrecognized command"); showMenu(); } command = getCommand(); } } public void showMenu() { System.out.println("load <filename> // read and store all the accounts from the specified file."); System.out.println("save <filename> // write all accounts from the current account collection to the specified file."); System.out.println("update <filename> // implement all the transactions in the specified file to update the current account collection."); System.out.println("add <id> <lastname> <firstname> <amount> // add a new account to the account collection."); System.out.println("delete <id> // delete the account with the specified id from the account collection."); System.out.println("credit <id> <amount> // add the specified amount to the balance of the specified account in the account collection."); System.out.println("debit <id> <amount> // subtract the specified amount from the balance of the specified account in the account collection."); System.out.println("show <id> // display all fields of the specified account."); System.out.println("show <lastname> // display all fields of all accounts with the specified last name."); System.out.println("show * // display all fields of all accounts."); System.out.println("quit // forfeit all changes and quit the program."); } private String getCommand() { System.out.print("? "); return inreader.next();
EDIT: seems that it cuts some parts off of the code on here, they are unimportant parts though.Java Code:import java.io.*; import java.util.*; import java.lang.*; class Account{ String id; String lastName; String firstName; float balance; public String getId() { return id; } public void setId(String userId) { id = userId; } public String getLastName() { return lastName; } public void setLastName(String userLastName) { lastName = userLastName; } public String getFirstName() { return firstName; } public void setFirstName(String userFirstName) { firstName = userFirstName; } public float getBalance() { return balance; } public void setBalance(float userBalance) { balance = userBalance; } public void accountStatus() { String accountStatus; //String balanceString = balance.toString(); can't use because of "float cannot be dereferenced" error, add float at the end of accoutStatus instead accountStatus = id + " " + lastName + " " + firstName + " " + balance; } }
- 03-27-2012, 09:01 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 26
- Rep Power
- 0
Re: Account manager program in Java
I've been working on this for a while, and I couldn't figure it out. I have no idea how to implement the "add" statement so it calls Account. Someone help?
- 03-29-2012, 04:26 PM #6
Member
- Join Date
- Feb 2012
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
Simple Bank Account Program - Completely Confused
By Interista in forum New To JavaReplies: 4Last Post: 11-02-2011, 02:12 AM -
How to login to gmail account using java
By moizali89 in forum Java ServletReplies: 2Last Post: 02-02-2011, 05:48 PM -
how to make to classes in the bank account program
By buzzing in forum New To JavaReplies: 3Last Post: 11-02-2010, 04:02 AM -
java bank account problem
By awil121 in forum New To JavaReplies: 1Last Post: 10-13-2010, 10:47 PM -
Using java to access internet account
By elgem in forum Advanced JavaReplies: 3Last Post: 01-18-2009, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks