-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds calculation of fee #20
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shop_Ex | ||
{ | ||
public class Account | ||
{ | ||
public double principal, rate; int daysActive, accountType; | ||
public static const int STANDARD = 0, BUDGET = 1, PREMIUM = 2, PREMIUM_PLUS = 3; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,9 +12,33 @@ static void Main(string[] args) | |
{ | ||
|
||
|
||
Account[] myAccounts = new Account[10]; | ||
Account a = new Account(); | ||
a.principal = 1.0; | ||
a.rate = 0.5; | ||
myAccounts[0] = a; | ||
a = new Account() { principal = 1.5, rate = 0.75 }; | ||
|
||
double fee = calculateFee(myAccounts); | ||
Console.WriteLine(fee); | ||
|
||
} | ||
|
||
public static double calculateFee(Account[] accounts) | ||
{ | ||
double totalFee = 0.0; | ||
Account account; | ||
for (int i = 0; i < accounts.Length; i++) | ||
{ | ||
account = accounts[i]; | ||
if (account.accountType == Account.PREMIUM || account.accountType == Account.PREMIUM_PLUS) totalFee += .0125 * ( // 1.25% broker's fee | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would declare the broker's fee as a const upfront (and then reference the const's name in the function) instead of using a magic number of .0125 with the explanation in comment |
||
account.principal * Math.pow(account.rate, (account.daysActive / 365.25)) - account.principal); // interest-principal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use similar approach for 365.25 days of the year referenced here (even though 365.25 is self-descriptive in a way). Also - what about leap years, do they make a difference from the logic's perspective? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be Math.Pow? (Syntax) |
||
} | ||
return totalFee; | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new values assigned to a (that has been just declared/assigned previously)