• Post Reply Bookmark Topic Watch Topic
  • New Topic

do not know how to finish this  RSS feed

 
Bob Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Requirements
You will need to make another modification to the Account class where you maintain an ArrayList to record all deposits and withdrawals transacted. Be sure to modify your toString method for this instant variable.

Now to support the class, add two private methods to sum both the deposits and to sum the withdrawals. For example:

Private double sumDeposits() {

}

Private double sumWithdrawals() {

}

In your toString method, provide support for the following format:



Name: ______ Date Opened: _______

Current Balance: __________



Transactions Deposits Withdrawals

1 _______ ________

2 _______ ________

and so on

======= ========

Total: _______ _________ <- put the summed values here



Of course where you see the underline, you place with real data. Be sure to have the equal signs in place. Be sure that there are no print statements in your toString method.



Testing
Create a test client and create three testing methods for example for the first method:

Public static void test1() {

}



For test 1, create an account for “Tiger Woods” with 100.00. Next withdraw 75 and 10 respectively. After, deposit 500. Notice all this with no printing. Now, use the toString method and print the account.



For test 2, create two accounts for “Carlie Sifford” with 50 and “George Baer” with 25. Have Mr. Baer withdraw 100 from his account. Be sure you handle this correctly. Next, transfer 25 from Mr. Sifford’s account to Mr. Baer’s account. Print both accounts.



For test 3, create an account for “Java 2 Class” and put 1000 as the initial startup. Next, create an account for “John Heath” and put 1 dollar in it. Next, transfer 999 into Dr. Heath’s account. Print Dr. Heaths account.









 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice coding homework assignment.

Where are you having trouble?
What have you tried so far?
What is working?
What isn't?

 
Bob Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first,date part. It print out null I do not know why.
Second , I do not know how to use array list to record every deposit and withdraw and print out in to string method
 
Stefan Evans
Bartender
Posts: 1837
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main reason a date would be null is if you haven't set it.
What would set the date value on the account? Have you called that method?

1 - Work out what it should be a list of. Strings? Numbers? Objects?
2 - add an ArrayList attribute to your Account to go along with the name and balance.
3 - The toString method should iterate through the entire list, and print out each entry. A for loop would be appropriate.
4 - Every time you successfully deposit or withdraw funds, add an entry to your list.
 
Bob Lyn
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set date like Date d = new Date(2015-2-16); it still print out null
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob Lyn wrote:I set date like Date d = new Date(2015-2-16); it still print out null


Welcome to the Ranch, Bob.

Assuming that you're passing Date() a string, that form is deprecated. Use the DateFormat below.

Date(String s)
Deprecated.
As of JDK version 1.1, replaced by DateFormat.parse(String s).
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you are literally doing new Date(2015-2-16) then that is doing something completely different than what you think it does.

It will calculate 2015 minus 2 minus 16 = 1997 and then the constructor of class Date is called that expects a number of milliseconds since 01-01-1970, 00:00:00 GMT.

You are passing it 1997 milliseconds since that reference point -> the result is that you get a Date object that is set to 01-01-1970, 00:00:01.997 GMT (1 second and 997 milliseconds past midnight on 1 January 1970 GMT).

And if the only thing you are doing is something like this: Date d = new Date(); then you are just declaring a local variable named d that is set to the current date and time. It's not somehow automatically stored in the Account object that you're working with. You'll have to call a method on the Account object to set its open date. (Look carefully in your Account class which method you'd have to call).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!