This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Hi, I have had the same problem for a week right now and I don't seem to be getting the answer I need. I am a beginner in using Java, this is my first exposure to it and I'm taking a course which I am currently now in unit 8. A couple units ago I had to write a class named Account to model an account. I was given certain properites and methods to use. I also had to write a client program to test the account class. Below is both my Account class and client program all in one file. Now two units later I am suppose to use the program and class I wrote and create two subclasses along with two separate test programs to test the subclasses. The two subclasses are savings and chequing account. The savings account which I'm currently working on is suppose to show "Insufficient" funds when someone tries to withdraw too much. As you can see my Account class and testAccountClass program doesn't accept user input. But in my testSavingsClass program can I not have user input without changing my original program and class? I've had people help me by trying to re-write my testaccountclass code to include savings account all in one. I can't do that as my testAccountClass is one assignment that has to be marked separate from my current. I need help with the code, I have no idea how to go about it. I haven't really started on my TestSavingsAccount test program yet because I don't know if I'm even doing my SavingsAccount subclass correct. Can someone please help me I'm ready to give up I just don't know what to do. Below are the code I have so far, starting with my TestAccountClass which is working fine.
And here is the start of my SavingsAccount subclass code (not the test program):
In your TestSavingsAccount file, you may want to pass in a value that comes from user input rather than a hard coded number like you used in TestAccountClass. You don't need to change Account or SavingsAccount to do that. On the other hand, you should realize that you can call a method more than once. So you could withdraw(10), do a System.out.println(result), then withdraw(100), do another print, ... continue to withdraw until you get the message you want.
However, your SavingsAccount class should have a little additional functionality (like having the withdraw() method return "Insufficient" when appropriate. You probably want to have the same methods as the Account class only with slightly different functionality. [ February 27, 2004: Message edited by: Marilyn de Queiroz ]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Jan 11, 2004
Hi, Thanks for your reply. One question I have is how is my SavingsAccount subclass looking I'm not too sure if I'm on the right track with it. I will start working on my SavingsAccountTest program and go from there. My one question is how do I pass a user input value rather than a hard code value in my SavingsAccountTest. My text didn't really show any examples of user input when doing things this way so I don't have anything to use for a guidline. Thanks so much for your help I appreciate it. Maybe I won't go insane afterall. Stacey
I'm not sure I've understood everything. In a recent post, indicated that you figured out how to get user input. (I'd guess with a JOptionPane.showInputDialog() invocation.) But then you went on to say that you didn't want to change your test application to use the input values, since your test application was working as it was. From this post, I'll guess that you do want to change your test application to use some user input values, and that you'd perhaps like to see a simple example of doing such a thing. So, here goes...
[ February 28, 2004: Message edited by: Dirk Schreckmann ]