I need help setting up this code for an assignment
I am just trying to get this work done, I need help with the first few steps of the code.
11 Replies
Here is what I have so far...
For now, I am focusing on completing:
-Create SavingsAccount class with static variable annualInterestRate and private instance variables savingsBalance (double) and savingsAccountName (string).
-Create a mutator method to set the savingsAccountName. Call this method
setSavingsAccountName. The method should take a string argument and return void.
-Create an accessor method to retrieve the savingsAccountName. Call this method
getSavingsAccountName. The method should take no arguments and return a string (i.e. the
savingsAccountName).
How am I doing so far? It's bad I know but this is me attempting it without much knowledge of C#
You have no mutator methods here
Your code will not compile
Whoever gave you the assignment is mentally stuck with 1999 Java, but it really doesn't seem like they want you to use properties
Rather, they want you to create getter and setter methods
Also, no need for
System.String
, just the string
alias worksA mutator method is just setter right?
It's a method that mutates the state of the class
Normally, in sane circumstances, you would use a property with a setter indeed
But the assignment clearly states you need a method
What would a mutator method look like then?
A method
That changes the value of the field
There's nothing special about it
Just a regular ol' method
Ohh so it's those lines that have public static void at the top right??
and using is never going to work is it?
Is this better?
think about what happens when you try to get the value of SavingsBalance here
you're telling it to look at SavingsBalance, which needs to look at SavingsBalance, which needs to look at SavingsBalance...
you need a backing field that actually stores the value to avoid infinite recursion
you can either do that explicitly or if you don't have any special logic just use an auto-property like
So like this...?
That is still a property
Oh ok
thank you guys