From c76a9fb7cfa1cd98a7d89ecd5ee8c740a0bbad6f Mon Sep 17 00:00:00 2001 From: skopczynska Date: Fri, 24 Nov 2023 16:57:15 +0100 Subject: [PATCH] Adds calculation of fee --- 01-CodeReviewEx/Shop-Ex/Account.cs | 14 ++++++++++++++ 01-CodeReviewEx/Shop-Ex/Program.cs | 26 +++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 01-CodeReviewEx/Shop-Ex/Account.cs diff --git a/01-CodeReviewEx/Shop-Ex/Account.cs b/01-CodeReviewEx/Shop-Ex/Account.cs new file mode 100644 index 0000000..4ad16a7 --- /dev/null +++ b/01-CodeReviewEx/Shop-Ex/Account.cs @@ -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; + } +} \ No newline at end of file diff --git a/01-CodeReviewEx/Shop-Ex/Program.cs b/01-CodeReviewEx/Shop-Ex/Program.cs index 1993e75..02a0d26 100644 --- a/01-CodeReviewEx/Shop-Ex/Program.cs +++ b/01-CodeReviewEx/Shop-Ex/Program.cs @@ -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 + account.principal * Math.pow(account.rate, (account.daysActive / 365.25)) - account.principal); // interest-principal + } + return totalFee; } + } -} +} \ No newline at end of file