Im making a program that takes the savings of saver1 and saver2. both start at 2000 and 3000.
annnualInterestRate is suposed to store the interest. SavingsBalance is to show current balance in deposit. MonthlyInterest is multiplying the savings by the interest /12
the interest should be added to savingsBalance.
I thought my class was ok but it says i dont have a constructor after i try to Console.Writeline my class is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace savingsAcct
{
internal class savings
{
public static double annualInterestRate { get;set; }
private double _savingsBalance;
public double Savings(double beginningBalance)
{
_savingsBalance = beginningBalance;
}
public double SavingsBalance
{
get
{
return _savingsBalance;
}
set
{
_savingsBalance = value CalculateMonthlyInterest(value);
}
}
public double CalculateMonthlyInterest(double value)
{
return value * (annualInterestRate / 12);
}
public static void ModifyInterest(double rate)
{
annualInterestRate = rate / 100;
}
void DisplaySaver()
{
Console.WriteLine(" The total balance is: " _savingsBalance.ToString("c"));
}
}
}
could someone give me a hand with my class?
CodePudding user response:
Your class is named savings
but the constructor is named Savings
.
Change the class name to internal class Savings
Also your constructor can't have a return type.
Change your constructor to public Savings(double beginningBalance)
CodePudding user response:
Your class no have a a constructor, the constructor syntax should be
public Savings(double beginningBalance)
{
_savingsBalance = beginningBalance;
}
this is different, you have a method called Savings()
who receives a double and returns a double. The constructors not returns anything and must have the exact same name of the class, so you need to set the class name Savings
or the constructor name savings
.