aspose file tools*
The moose likes Beginning Java and the fly likes Java Class Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Class Design" Watch "Java Class Design" New topic
Author

Java Class Design

Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
Dear all, I have problem designing my program to make it Object-oriented.Hope u guys can help me

I am doing a simple bank program. The program has 100 Customer Records. It can
1) Retrive data from a text file
2) Search & Display the Customer Record according to the id
3) Write data back to text file
4) The program also need to compute the interest of each record.

My initial design is like this...
I have class Customer which contains the id,name etc
then i have Bank class with a main method and static methods performing the 4 operations i mentioned above

for no 1) public static void readFile() etc

instead of using static method, how can i make my program to be OOP.
thanks a lot
Francis Shillitoe
Greenhorn

Joined: Aug 30, 2002
Posts: 22
Here's some suggestions, in pseudo-code.

The BankDatabase class represents an OO view of the file.
The find, update, insert commands result in file read/writes.

class BankDatabase {
-path:File

BankDatabase(File path):void
+findCustomer(id:int): CustomerRecord
+updateCustomer(record:CustomerRecord):void
+insertCustomer(record:CustomerRecord):void
}

The CustomerRecord class contains your getters and setters

class CustomerRecord {
+getName():String
+setName(name:String):void
+getID():int
+setID(id:int):void
...
}


The BankApplication class is your application entry point. From here, you can either create a GUI or CLI (command line interface) and enter an event loop to wait for user input.

class BankApplication {
+main(args:String[]):void
}


hope this gives you some ideas,

Francis


<a href="http://www.shillitoe.com" target="_blank" rel="nofollow">http://www.shillitoe.com</a>
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
A couple of questions to help you (and us) understand what you are trying to do:

1. What data are you reading from the file? Does this file represent your "data store"?

2. When you say you need to compute the interest - is this interest rate specific to the Bank or can each customer account have a different interest rate / algorithm to compute the interest?
Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
thank u Francis Shillitoe for ur reply

hi Timmy Marks,
my data is like this, saved in *.txt file

Account Id = 65
Name = Salma Hayek
Address = 45 Mexican Boulevard, Hotel California, Singapore 467822
DOB = 06-04-73
Phone Number = 790-0000
Account Balance = 2345.00

Account Id = 78
Name = Phua Chu Kang
Address = 50 PCK Avenue, Singapore 639798
DOB = 11-08-64
Phone Number = 345-6780
Account Balance = 0.00

As for the interest, it's as follows

Write a method miniDeposit that reads in the daily interest rate from keyboard and then outputs the necessary minimum deposit to produce 1 cent interest-profit from the deposit. Note that any interest-profit less than 1 cent will not be credit to your account by the bank. The method should also list the accounts that get no interest.

Frankly speaking, I have no idea what the above paragraph is about.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi Mr. Kewl,

Welcome to JavaRanch!

It looks like you didn't read our naming policy on your way in. It requires that you use a full, real (sounding) first and last name for your display name. Joke names and "handles" aren't acceptable here. You can change your display name here. Thanks!


[Jess in Action][AskingGoodQuestions]
Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
hi guys, I need to expand this class to include more functions.
I have 3 accounts. Account1, Account2 and Account 3 which 3 are requrired to be extends frm CustomerRecord. these 3 Accounts contains only 1 member variable which is the double interestin each class.
I need to provide an update() method which make use of polymorhphism to update the interests in the 3 Account classes. How should I approach tt?
My CustomerRecord can only have 100 objects.

Since I will declare Account1, Account2 ,Account 3 separately, how do I know tt my CustomerREcords wun reach more than 100? I need to keep track number of Account1,2,3 individually and sum them together?

Thanks for spending ur time to answer my queries

class BankDatabase {
-path:File

BankDatabase(File path):void
+findCustomer(id:int): CustomerRecord
+updateCustomer(record:CustomerRecord):void
+insertCustomer(record:CustomerRecord):void
}

The CustomerRecord class contains your getters and setters

class CustomerRecord {
+getName():String
+setName(name:String):void
+getID():int
+setID(id:int):void
...
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Class Design