Browse Source

Merge branch 'feature/balance-operations' of https://gitlab2.informatik.hs-fulda.de/fdai7057/bankmanagement-system into feature/balance-operations

remotes/origin/feature/balance-operations
fdai7207 2 years ago
parent
commit
e65f73824d
  1. 4
      src/currentCustomerAccountBalance.h
  2. 20
      src/displayDisclaimer.c
  3. 7
      src/displayDisclaimer.h
  4. 61
      src/interestCalculator.c
  5. 1
      src/interestCalculator.h
  6. 18
      src/sendMoney.c
  7. 0
      src/sendMoney.h
  8. 4
      src/updateCustomerAccountBalance.h
  9. 8
      src/withdrawMoney.c
  10. 39
      tests/test_depositMoney.c
  11. 9
      tests/test_updateCustomerAccountBalance.c

4
src/currentCustomerAccountBalance.h

@ -1,5 +1,5 @@
#ifndef CURRENTCUSTOMERACCOUNTBALANCE_H_
#define CURRENTCUSTOMERACCOUNTBALANCE_H_
#ifndef CurrentCustomerAccountBalance_H
#define CurrentCustomerAccountBalance_H
#include <stdio.h> #include <stdio.h>

20
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;
// }

7
src/displayDisclaimer.h

@ -0,0 +1,7 @@
#ifndef DISPLAYDISCLAIMER_H_
#define DISPLAYDISCLAIMER_H_
#include <stdio.h>
void displayDisclaimer();
#endif

61
src/interestCalculator.c

@ -14,9 +14,40 @@ void troubleshoot(int errorCode){
case 2: case 2:
printf("Duration not valid. Make sure it is a valid number over the value of zero."); printf("Duration not valid. Make sure it is a valid number over the value of zero.");
break; 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){ float initiateInterest(float principalAmount, float interest, float time){
return principalAmount*(1+(interest*time)); return principalAmount*(1+(interest*time));
} }
@ -25,6 +56,7 @@ void calculateYearlyInterest(){
float principalAmount; float principalAmount;
float interestPerYear; float interestPerYear;
float timeInYears; float timeInYears;
int choice;
printf("Please enter the principal amount:"); printf("Please enter the principal amount:");
if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) { if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) {
@ -37,17 +69,33 @@ void calculateYearlyInterest(){
troubleshoot(0); troubleshoot(0);
return; return;
} }
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:"); printf("\nPlease enter interest time in years:");
if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) {
troubleshoot(2); troubleshoot(2);
return; return;
} }
}else{
troubleshoot(2);
}
float interestDecimal=interestPerYear/100; float interestDecimal=interestPerYear/100;
float result= initiateInterest(principalAmount,interestDecimal,timeInYears); float result= initiateInterest(principalAmount,interestDecimal,timeInYears);
printf("\nAmount with the interest is %.2f€.",result); printf("\nAmount with the interest is %.2f€.",result);
askForSavingGoal(principalAmount,principalAmount*interestDecimal);
} }
void calculateMonthlyInterest(){ void calculateMonthlyInterest(){
float principalAmount; float principalAmount;
@ -79,10 +127,12 @@ void calculateMonthlyInterest(){
} }
void initiateCalculator() { void initiateCalculator() {
int input; int input;
char c; 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); scanf("%d", &input);
switch (input) { switch (input) {
@ -95,15 +145,16 @@ void initiateCalculator(){
default: 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); scanf(" %c", &c);
if (c == 'y' || c == 'Y') { if (c == 'y' || c == 'Y') {
initiateCalculator(); initiateCalculator();
}else{
return;
} }
} }
// int main(){ // int main(){
// initiateCalculator(); // initiateCalculator();

1
src/interestCalculator.h

@ -5,6 +5,7 @@
void calculateYearlyInterest(); void calculateYearlyInterest();
void calculateMonthlyInterest(); void calculateMonthlyInterest();
void askForSavingGoal(float principalAmount, float accInterestPerYear);
float initiateInterest(float principalAmount, float interest, float time); float initiateInterest(float principalAmount, float interest, float time);
void troubleshoot(int errorCode); void troubleshoot(int errorCode);
#endif #endif

18
src/sendmoney.c → src/sendMoney.c

@ -1,7 +1,11 @@
#include "sendMoney.h" #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){ void showBalance(int customerID){
float balance=getAvailableAccountBalance(customerID); float balance=getAvailableAccountBalance(customerID);
@ -115,7 +119,7 @@ bool sendMoney(int customerID){
return false; return false;
} }
// int main(){
// sendMoney(1234);
// return 0;
// }
int main(){
sendMoney(1234);
return 0;
}

0
src/sendmoney.h → src/sendMoney.h

4
src/updateCustomerAccountBalance.h

@ -1,5 +1,5 @@
#ifndef UPDATECUSTOMERACCOUNTBALANCE_H_
#define UPDATECUSTOMERACCOUNTBALANCE_H_
#ifndef UpdateCustomerAccountBalance_H
#define UpdateCustomerAccountBalance_H
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>

8
src/withdrawMoney.c

@ -1,6 +1,7 @@
#include "withdrawMoney.h" #include "withdrawMoney.h"
#include "updateCustomerAccountBalance.c"
#include "currentCustomerAccountBalance.c"
#include "updateCustomerAccountBalance.h"
#include "currentCustomerAccountBalance.h"
void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) { void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) {
char c; char c;
@ -51,12 +52,11 @@ bool withdraw(int user_id) {
updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance); updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance);
if( updateSuccess ) { if( updateSuccess ) {
notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id); notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id);
return true;
} }
else { else {
printf("Some error occured! Sorry for the inconvenience caused.\n"); printf("Some error occured! Sorry for the inconvenience caused.\n");
return false;
} }
return updateSuccess;
} }
else { else {

39
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

9
tests/test_updateCustomerAccountBalance.c

@ -54,5 +54,14 @@ void test_updateAvailableAccountBalanceSuccess(void){
TEST_ASSERT_TRUE(result[i]); TEST_ASSERT_TRUE(result[i]);
} }
}
void test_failOpenFile(void) {
/* Act and assert */
FILE *file = fopen("false_file_name", "r");
TEST_ASSERT_FALSE(file);
} }
#endif #endif
Loading…
Cancel
Save