Hi Everyone, I'm still working on my subclass assigment and only getting more confused from my last posted question. So I'm going to try again cause I need help badly. In my first assigment I had to write a class named "Account" to model accounts, then a client program to test the account class. I did this all in one file as you will see below. Now I'm being asked to use that program and write two subclasses "Savings Account" and "Chequing Account" and test programs to go with to test them. The difference of the two accounts is that the chequing account has an overdraft allowance and the savings account does not so, if the user withdraws too much "Insufficient" funds will display. So here is my problem, I'm working on my savings account subclass and I'm lost. In my original account class the user didn't input the amounts to withdraw or deposit, so now I would like to change that and have the user input it. Is this possible without changing the Account class but modifying things in the subclasses and testprograms? Can someone please let me know cause I don't want to have to change everything in my account class. I would like to work with what I have already written so I can learn from it. So if you can help my account class code and the beginning of my Savings Account subclass code are below. Thanks in advance.
I would like to change that and have the user input it. Is this possible without changing the Account class but modifying things in the subclasses and testprograms? Yes. You can make some small changes to your TestAccountClass class to change it to query the user for the values that it is currently using. You'll likely want to get input using the system console or a simple pop-up input dialog, such as appears when using JOptionPane.showInputDialog(). I'd recommend the JOptionPane as it's a little bit easier to implement. Have you used a JOptionPane to get input before? [ February 25, 2004: Message edited by: Dirk Schreckmann ]
Hi, I have used JOptionPane before. So what your saying is I need to change my TestAccountClass for the user to input then move one to my savings and chequing account subclasses or in the test programs for the subclasses can I have the user input? Stacey
That is what I would suggest, too. The Account class (and it's subclasses) don't "know" where the data comes from for the amount to deposit or withdraw. They are passed as parameters to the appropriate functions. This is a clean design since you can easily change the source of the data by changing your test classes. You can probably imagine different ways to obtain the data such as user input, a file, or a database. In each case you could just write a different test class that gets the data from the appropriate source.
Okay so I've established that I can change to user input in my test programs. I don't want to change my TestAccountClass, it's fine the way it is, I have to write a TestSavingsAccount program but my first steps are to get the subclass right. That is what I need help with right now. Can anyone help me out I'm lost as my text doesn't eplain anything when it comes to doing user input. I need some direction. Please help!! Stacey
You have a class (Account), which is a base class, and you want to create another class (SavingsAccount), derived from the base class. It seems to me you're looking at this from the wrong angle. A bit like having a cake recipe, and a chocolate cake recipe - you seem to be using the cake recipe to bake the cake, then trying to turn it into a chocolate cake, instead of using the chocolate cake recipe (does this make sense?) Here's a modified version of your code, hopefully this might make more sense. (needs error handling)
Originally posted by Stacey Johnson: I'm lost as my text doesn't eplain anything when it comes to doing user input.
As a side-note, I often find it necessary when learning something new that it helps to have multiple resources to leverage. It just helps me to learn to see the same concept presented in slightly different ways. Each resource helps reinforce what the other is saying, and fills in any gaps, like the one you are mentioning your textbook has. However since you are a student, I know that money may not be in great abundance (been there, done that ). Fortunately there are some good free online resources you can leverage (like JavaRanch). Three of my other favorites (which are more reference based) are:
www.JavaAlmanac.com � this site has tons of little sample code snippets/examples that are well indexed by package and searchable.
Sun�s The Java Tutorial � it has some nice introductory lessons (with downloadable examples) on most topics � you can either view it online or download a copy and unzip it on your PC (great for a laptop when you don�t have internet access).
The first two of those four are pretty robust and detailed; the last one presents some short treaties on some core concepts, so it can work well as a quick "second point of view". Lastly, I've found JDK 1.4 Tutorial by Gregory M. Travis to be a good book, and you can purchase an electronic copy (pdf) at the publisher�s website for only $17.50. I hope that some of these can help you as you progress in your studies (plus they�re great reading for those boring Sunday Afternoons when you�re doing laundry )
And then the entire population worshiped me like unto a god. Well, me and this tiny ad: