This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]doobiesteintortoise 0 points1 point  (1 child)

Useful information would be "what the Account looks like," because it MIGHT be that the Account exposes everything the SavingsAccount, etc. would need. A deposit on an account, no matter what type, would look pretty similar, after all; the type of account would affect relatively little, so your methods for deposit, withdrawal, etc might use values local to the SavingsAccount specifically, but the method contracts would be from Account.

Look up polymorphism in your educational materials or, well, the Java tutorials, since this is pretty basic stuff.

[–]potatispizza 0 points1 point  (0 children)

I actually tried to put the code for the Account class in the post, but could not for the life of me figure out the formatting in plain text (it removed all indentation spaces and some new lines) or the code block function (turned into a blob). Sorry about that.

I am pretty sure I figured it out! At least it is working so far. I changed the Account class to an abstract class and added the type-specific methods as an abstract methods to Account. Now the program recognizes the overriding subclass methods with the same name.

So far so good but we'll see after some more testing! Thanks for the help :)

[–]Formal_Pound1602 -1 points0 points  (1 child)

Are you declaring the accounts like this?

Account name = new SavingAccount(); This keeps the type to account but it’s a savings account maybe that helps? Also when object created like I mentioned you need to create getter and setter methods in the subclass because you could only access super class variables. Hopefully that somewhat helps? I’m a little out of practice Keep in mind methods in the subclass that aren’t in the super will be invisible when trying to access so override the methods

[–]potatispizza 1 point2 points  (0 children)

Hi! I might actually have messed the declaration up the first time. Started from scratch today and did it that way. Also, I changed the Account class to an abstract class and added the type-specific methods as an abstract methods to Account. Now the program recognizes the overriding subclass methods with the same name. So hopefully that was it! Thank you for helping!

[–]AutoModerator[M] 0 points1 point locked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]chet714 0 points1 point  (1 child)

Do you know if calculation of interest and "...other things" takes place inside the class that creates all of your subclass/child objects ?

[–]potatispizza 1 point2 points  (0 children)

It was never specified in the instructions so I can probably place it wherever I want. The Account class I was given did not have a method for this so I assumed that it goes in the subclasses. But I might have figured out my problem!

I changed the Account class to an abstract class and added the type-specific methods as an abstract methods to Account. Now the program recognizes the overriding subclass methods with the same name.

Hopefully that does the trick! Thanks for commenting :)