This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Class Design

 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Timmy Marks
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
...
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic