• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to design a class?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to design a class that stores the balance and the number of checks that has been written and 'return' fees. Any idea on how to do this?


 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel that there's a lot more to your requirements than you've told us. Where does it say "enter the number of checks"? It's hard to design something without detailed requirements.
 
Johnny Rojas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"A bank charges $10 per month plus the following check fees for a commercial checking account:
$.10 for each check if less than 10 checks were written
$.05 for each check if more than 10 were written"

"Design a class that stores the ending balance of an account and the number of checks written. It should also have a method that returns the bank’s service fees for the month."
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This meets your requirements but I bet it is not what is expected.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would you want setXXX methods in a bank account class?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Would you want setXXX methods in a bank account class?

Strictly speeking the fields could have been public with no getters and setters according to the "requirements". "numberOfChecks" is expected to change over time so you need some way to change it. The "fees" are hinted at to be "monthly" so the "numberOfChecks" is presumably also "monthly".
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could have designed it as an immutable class but the  requirements are very vague on how the class  will be used.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Could have designed it as an immutable class  . . .

I think the requirements we have been told suggest OP needs mutable objects. In an immutable version you would want methods like this:-. . . and you could use it like this:-
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP

Carey Brown wrote:Could have designed it as an immutable class


Joshua Bloch in his famous Effective Java (Item 17), says, that an Immutable class to be considered truly as such supposed to comply with the next 5 rules:

1. No methods which let modify object's state
2. Class cannot be extended [breach of this rule]
3. All fields final [breach of this rule]
4. All fields private
5. No ability to get references to mutable fields

So after small improvements Carey's version would be great.
 
Liutauras Vilda
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP
Class name "Checking" to me sounds weird.

Does it sound ok to others?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is American for CurrentAccount; the opposite would be Saving. CheckingAccount and SavingAccount would be better names.
 
Johnny Rojas
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to get rid of the keyboard and Scanner, though!
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Johnny Rojas wrote:I don't want to get rid of the keyboard and Scanner, though!

Well, maybe you still need it. However, the requirements you've shown so far don't require it. If you were to keep it then you might want to move it to another "driver" class, one that contains main() and utilizes your CheckingAccount class to keep track of things.
 
reply
    Bookmark Topic Watch Topic
  • New Topic