my dog learned polymorphism*
The moose likes Beginning Java and the fly likes monolithic form to object oriented abstraction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "monolithic form to object oriented abstraction" Watch "monolithic form to object oriented abstraction" New topic
Author

monolithic form to object oriented abstraction

Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
Hi, I just found this great place to learn Java I have some problems with the object oriented stuff that needs some help. I'm trying to convert this program into an object oriented abstraction form, but I just can't figure it out how to start with. So could anyone give me some hints or suggestions? Thx a lot in advance! Here's the code:



[ October 26, 2005: Message edited by: Ash Lin ]

[ October 26, 2005: Message edited by: Ash Lin ]
[ October 26, 2005: Message edited by: Ash Lin ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
The very first thing I'd do is notice that the checkId and checkAmount of one check belong more strongly together than all the ids of all checks, for example. Your code doesn't reflect that. It could by introducing a new Class, maybe called Check, with id and amount as fields. Then you only need one Check array.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
Thx so much for your advice
However, I got some problems after entering the info for the second account..it seems that the program will automatically include the previous account's Check ID and Check Amount in the second account...dunno what's wrong with it ><
can anyone help a little bit?
Thanks very much in advance!
Here's the codes:



Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I'm not sure what you mean. Can you give an example of what you do, what output you expect, and where the actual output differs?
Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
Hi,
This program displays the account info entered from the user. Here's the result:
==========================================================
Name: Alex
Account ID: asbestos
Your Current Balance is 300.0
Check ID: 100 Check Amount: 500.0
Check ID: 101 Check Amount: 200.0
==========================================================
==========================================================
Name: Melody
Acct ID: meo
Your Current Balance is 900.0
Check ID: 100 Check Amount: 500.0
Check ID: 101 Check Amount: 200.0
Check ID: 200 Check Amount: 100.0
Check ID: 201 Check Amount: 300.0
==========================================================
My problem is that in the second account, the program also prints out the first account's Check ID and Check Amount, and i don't want that to happen. There's something wrong with the calculation method for the balance, too; it seems that it also adds the first account's balance to the second one. I don't know which part goes wrong...
Thanks a lot for any suggestion in advance.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
How do you start a new account? I don't see any code that would do something remotely associated to such a task - not even a menu entry...
Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
I was gonna do a screen-shot and then paste it here, but i don't know how to do that(paste the image here)...so i skipped the menu part and only pasted the result
Actually the menu will be shown on the command prompt once you run it, it looks something like this:

Enter Commands Below, Stop To Quit.
==========================================================
Menu............
Set Name
Set Account ID
Post Check
Make Deposit
Show Balance
Stop
==========================================================

And at the same time, the JOptionPane will keep prompting the user to enter a command. After you type in "Show Balance", the program will print out the info entered from the user(that's the result) on the screen, and that's the end of one account. The JOptionPane will keep prompting the user to enter a command(ex. entering a new name or account ID) until the user entered "Stop".
Hope this will make sense
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Yes, sorry for not being more clear. I did see the menu in the code. I don't see an option in the menu to start a new account. What action would I be supposed to perform to start a new account (other than terminating and restarting the program)?
Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
Hi,
I didn't run the original program(Bank.java) when I first got it; but after I ran it today, I found that it also has the same situation as the BankAccount.java one. That is, in the second account, the program also prints out the first account's Check ID and Check Amount. So I guess the program was originally designed in that way or I didn't really understand the way it works...
I'm very sorry about this
Thank you very much for all these helps!!
(Maybe next time I'll try to modify this program a little bit so it won't be such confusing )
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I still don't understand what you mean by "second account". Perhaps you are misinterpreting the "set account id" menu item? It just changes the id of the account, it doesn't create a new one.
Ash Lin
Greenhorn

Joined: Oct 26, 2005
Posts: 6
Yeah, cuz there's the "Set Name" option on the menu, so I thought that if I click on that, it'll set up or create another account...
Anyway, thanks a lot for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: monolithic form to object oriented abstraction
 
Similar Threads
Just Can't figure it out and it's due today
Bank program class or switch problem
Need help with username and password validation
Suppressing proceeding statements after if statement fails
SubClass Blues!