Answer to Question #61042 in C# for fredrick senanu

Question #61042
Que)
Sahendrin Commercial Bank updates its customers’ accounts at the end of each month.
The bank offers two types of accounts: savings and current. Every customer must maintain a minimum balance, minimum balance for savings account is GHC 50.00 and current account is GHC 100.00. If a customer’s balance falls below the minimum balance, there is a service charge of GHC 10.00 for savings accounts and GHC 25.00 for current accounts.
If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:
• Savings accounts receive 4% interest.
• Current accounts receive 5% interest.
Write a program that reads a customer’s account number (int type), account type, current balance. The program should then output the account number, account type, current balance, and an appropriate message.
1
Expert's answer
2016-08-01T09:55:03-0400
using System;

namespace SahendrinCommercialBank
{
enum AccountType
{
Savings = 1,
Current
}

class Customer
{
public int AccountNumber { set; get; }
public AccountType AccountType { set; get; }
public double CurrentBalance { set; get; }

public Customer(int number, AccountType type, double balance)
{
AccountNumber = number;
AccountType = type;
CurrentBalance = balance;
}

public override string ToString()
{
string message = string.Empty; // appropriate message

// to calculate new balance and get an appropriate message
switch (AccountType)
{
case AccountType.Current:
if (CurrentBalance >= 100)
{
CurrentBalance += CurrentBalance * 0.05;
message = "The account has received 5% interest.";
}
else
{
CurrentBalance -= 25;
message = "The customer’s balance is below the minimum balance. Service charge of GHC 25.00 has been performed.";
}
break;
case AccountType.Savings:
if (CurrentBalance >= 50)
{
CurrentBalance += CurrentBalance * 0.04;
message = "The account has received 4% interest.";
}
else
{
CurrentBalance -= 10;
message = "The customer’s balance is below the minimum balance. Service charge of GHC 10.00 has been performed.";
}
break;
}

return string.Format("Account number: {0}\nAccount type: {1}\nCurrent balance: GHC {2:F2}\nMessage: {3}",
AccountNumber, AccountType, CurrentBalance, message);
}
}

class Program
{
static void Main(string[] args)
{
int number;
AccountType type;
double balance;

// to get a customer’s account number, account type, current balance.
Console.Write("Enter account number: ");
number = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter account type (\"1\" - Savings account, any number - Current account): ");
int n = Convert.ToInt32(Console.ReadLine());
type = (n == 1) ? AccountType.Savings : AccountType.Current;
Console.Write("Enter current balance: ");
balance = Convert.ToDouble(Console.ReadLine());

// to create customer's account
Customer customer = new Customer(number, type, balance);

Console.WriteLine();

// to output the account number, account type, current balance, and an appropriate message
Console.WriteLine(customer);

Console.ReadKey();
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS