diff --git a/src/currentCustomerAccountBalance.h b/src/currentCustomerAccountBalance.h index dc39493..36bb66e 100644 --- a/src/currentCustomerAccountBalance.h +++ b/src/currentCustomerAccountBalance.h @@ -1,5 +1,5 @@ -#ifndef CURRENTCUSTOMERACCOUNTBALANCE_H_ -#define CURRENTCUSTOMERACCOUNTBALANCE_H_ +#ifndef CurrentCustomerAccountBalance_H +#define CurrentCustomerAccountBalance_H #include diff --git a/src/displayDisclaimer.c b/src/displayDisclaimer.c new file mode 100644 index 0000000..a324e93 --- /dev/null +++ b/src/displayDisclaimer.c @@ -0,0 +1,20 @@ +#include "displayDisclaimer.h" + +void displayDisclaimer(){ + printf(" W E L C O M E T O \n"); + printf(" .______ .___ ___. _______.\n"); + printf(" | _ \\ | \\/ | / |\n"); + printf(" | |_) | | \\ / | | (----`\n"); + printf(" | _ < | |\\/| | \\ \\ \n"); + printf(" | |_) | | | | | .----) | \n"); + printf(" |______/ |__| |__| |_______/ \n"); + printf(" \n"); + printf("B A N K M A N A G E M E N T S Y S T E M\n"); + printf(":.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:.:\n"); + printf("Created by Atharva, Can, Haytham, Julius, Shivam, and Yahya for AI1001.\n"); +} + +// int main(){ +// displayDisclaimer(); +// return 1; +// } \ No newline at end of file diff --git a/src/displayDisclaimer.h b/src/displayDisclaimer.h new file mode 100644 index 0000000..7043974 --- /dev/null +++ b/src/displayDisclaimer.h @@ -0,0 +1,7 @@ +#ifndef DISPLAYDISCLAIMER_H_ +#define DISPLAYDISCLAIMER_H_ +#include + +void displayDisclaimer(); + +#endif \ No newline at end of file diff --git a/src/interestCalculator.c b/src/interestCalculator.c index d9c2cce..9964047 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -14,9 +14,40 @@ void troubleshoot(int errorCode){ case 2: printf("Duration not valid. Make sure it is a valid number over the value of zero."); break; + case 3: + printf("Invalid option. Aborting."); + break; + case 4: + printf("Your goal cannot be smaller than your principal funds. Aborting."); + break; + } +} + +void askForSavingGoal(float principalAmount, float accInterestPerYear) { + char c; + float goal; + float timeForGoal; + + printf("\nWould you like to set a saving goal? [y/n]: "); + scanf(" %c", &c); + + if (c != 'y' && c != 'Y') { + return; + } + + printf("\nPlease enter your goal amount in €: "); + scanf("%f", &goal); + + if (goal < principalAmount) { + troubleshoot(4); + return; } + + timeForGoal = (goal - principalAmount) / accInterestPerYear; + printf("\nIn %.1f years you will reach your goal of %.2f.\n", timeForGoal, goal); } + float initiateInterest(float principalAmount, float interest, float time){ return principalAmount*(1+(interest*time)); } @@ -25,6 +56,7 @@ void calculateYearlyInterest(){ float principalAmount; float interestPerYear; float timeInYears; + int choice; printf("Please enter the principal amount:"); if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) { @@ -37,17 +69,33 @@ void calculateYearlyInterest(){ troubleshoot(0); return; } - - printf("\nPlease enter interest time in years:"); - if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + printf("\nWould you like to enter the time in [1]months or in [2]years?\n"); + scanf("%d",&choice); + if(choice==1){ + printf("\nPlease enter interest time in months:"); + if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + troubleshoot(2); + return; + } + timeInYears=timeInYears/12; + + }else if(choice==2){ + printf("\nPlease enter interest time in years:"); + if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + troubleshoot(2); + return; + } + }else{ troubleshoot(2); - return; } + + float interestDecimal=interestPerYear/100; float result= initiateInterest(principalAmount,interestDecimal,timeInYears); printf("\nAmount with the interest is %.2f€.",result); + askForSavingGoal(principalAmount,principalAmount*interestDecimal); } void calculateMonthlyInterest(){ float principalAmount; @@ -78,32 +126,35 @@ void calculateMonthlyInterest(){ printf("\nAmount with the interest is %.2f€.",result); } -void initiateCalculator(){ - +void initiateCalculator() { int input; char c; - printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n[2]Calculate monthly interest\n"); + + printf("Welcome to the interest calculator. Please select an option:\n" + "[1] Calculate yearly interest\n" + "[2] Calculate monthly interest\n"); scanf("%d", &input); - switch(input){ + switch (input) { case 1: - calculateYearlyInterest(); - break; + calculateYearlyInterest(); + break; case 2: - calculateMonthlyInterest(); - break; + calculateMonthlyInterest(); + break; default: - break; + break; } - printf("\nThank you for using our services. Would you like to do another calculation? [y]Yes [any]No\n"); + + printf("\nThank you for using our services. Would you like to do another calculation? [y/n]: "); scanf(" %c", &c); - if(c=='y'||c=='Y'){ + + if (c == 'y' || c == 'Y') { initiateCalculator(); - }else{ - return; } } + // int main(){ // initiateCalculator(); diff --git a/src/interestCalculator.h b/src/interestCalculator.h index 9dfb731..0c9c3b9 100644 --- a/src/interestCalculator.h +++ b/src/interestCalculator.h @@ -5,6 +5,7 @@ void calculateYearlyInterest(); void calculateMonthlyInterest(); +void askForSavingGoal(float principalAmount, float accInterestPerYear); float initiateInterest(float principalAmount, float interest, float time); void troubleshoot(int errorCode); #endif \ No newline at end of file diff --git a/src/sendmoney.c b/src/sendMoney.c similarity index 94% rename from src/sendmoney.c rename to src/sendMoney.c index 7324077..f597ac8 100644 --- a/src/sendmoney.c +++ b/src/sendMoney.c @@ -1,7 +1,11 @@ #include "sendMoney.h" -#include "depositMoney.c" -#include "withdrawMoney.c" -#include "currencyExchange.c" +#include "depositMoney.h" +#include "withdrawMoney.h" +#include "currencyExchange.h" +#include "currentCustomerAccountBalance.h" +#include "updateCustomerAccountBalance.h" + + void showBalance(int customerID){ float balance=getAvailableAccountBalance(customerID); @@ -115,7 +119,7 @@ bool sendMoney(int customerID){ return false; } -// int main(){ -// sendMoney(1234); -// return 0; -// } \ No newline at end of file +int main(){ + sendMoney(1234); + return 0; +} \ No newline at end of file diff --git a/src/sendmoney.h b/src/sendMoney.h similarity index 100% rename from src/sendmoney.h rename to src/sendMoney.h diff --git a/src/updateCustomerAccountBalance.h b/src/updateCustomerAccountBalance.h index 17f34ae..5b056f4 100644 --- a/src/updateCustomerAccountBalance.h +++ b/src/updateCustomerAccountBalance.h @@ -1,5 +1,5 @@ -#ifndef UPDATECUSTOMERACCOUNTBALANCE_H_ -#define UPDATECUSTOMERACCOUNTBALANCE_H_ +#ifndef UpdateCustomerAccountBalance_H +#define UpdateCustomerAccountBalance_H #include #include diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c index 4bd3eaf..65e23b2 100644 --- a/src/withdrawMoney.c +++ b/src/withdrawMoney.c @@ -1,6 +1,7 @@ #include "withdrawMoney.h" -#include "updateCustomerAccountBalance.c" -#include "currentCustomerAccountBalance.c" +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.h" + void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) { char c; @@ -51,12 +52,11 @@ bool withdraw(int user_id) { updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance); if( updateSuccess ) { notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id); - return true; } else { printf("Some error occured! Sorry for the inconvenience caused.\n"); - return false; } + return updateSuccess; } else { diff --git a/tests/test_depositMoney.c b/tests/test_depositMoney.c new file mode 100644 index 0000000..39a8b33 --- /dev/null +++ b/tests/test_depositMoney.c @@ -0,0 +1,39 @@ +#ifdef TEST + +#include "unity.h" +#include "depositMoney.h" + +void setUp(void) +{ +} + +void tearDown(void) +{ +} + +void test_depositSpecificAmount(void) { + + /* Arrange */ + + int length = 5; + int userIDs[] = {1234,1235,1236,1237,1238}; + float amountToDeposit[] = {200.5, 340, 244.5, 340, 1200}; + + bool result[length]; + + /* Act */ + + for (int i = 0; i < length; i++) { + result[i] = depositSpecificAmount( userIDs[i], amountToDeposit[i] ); + } + + /* Assert */ + + for (int i = 0; i < length; i++) { + TEST_ASSERT_TRUE(result[i]); + } + +} + + +#endif // TEST diff --git a/tests/test_updateCustomerAccountBalance.c b/tests/test_updateCustomerAccountBalance.c index 5b5454b..833c9fc 100644 --- a/tests/test_updateCustomerAccountBalance.c +++ b/tests/test_updateCustomerAccountBalance.c @@ -54,5 +54,14 @@ void test_updateAvailableAccountBalanceSuccess(void){ TEST_ASSERT_TRUE(result[i]); } +} +void test_failOpenFile(void) { + + /* Act and assert */ + + FILE *file = fopen("false_file_name", "r"); + + TEST_ASSERT_FALSE(file); + } #endif