In C# Create a console project. 1. Create an interface \"IMyInterface.cs\" - Add
ID: 3859885 • Letter: I
Question
In C# Create a console project.
1. Create an interface "IMyInterface.cs"
- Add a method "string iMessage()"
2. Create a class named "C1.cs"
- Add 4 private data members, create property for each data member
double loanAmnout=0.0;
double years=0.0;
double interests=0.0;
double interestRate=0.0;
3. - Add a constructor with parameters to assign values to loanAmnout, years,
interestRate with values that user entered.
4. - Add one method “PayInterests()” to return the interests
interests = loanAmnout * interestRate * years
5. - Inheritate "IMyInterface", implement the method " iMessage()",
return string "Be Ready!”
6. In Program.cs, have users to enter loanAmnout, years, interestRate.
- Call method PayInterests() to display total interests.
- Call iMessage() to display "Be Ready!”
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
interface IT1
{
String iMessage();
}
class Test
{
public void iMessage()
{
Console.WriteLine("Be Ready...");
}
}
}
//a class named "C1.cs"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class C1
{
private double loanAmount, years, interests, interestRate; //private data members.
public double PayInterests(double p, double n, double r)
{
double b;
loanAmount = p;
years = n;
interestRate = r;
b = loanAmount * years * interestRate / 100;
return(b);
}
}
}
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Manage Loan Calculatoe ");
Console.WriteLine("------------------------------------------------------------------------");
double a, b, c;
C1 c1 = new C1();
Console.WriteLine("Enter Loan amount : ");
a = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Year :");
b = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Interest Rate :");
c = Convert.ToDouble(Console.ReadLine());
double si = c1.PayInterests(a, b, c);
Console.WriteLine("Total Interest :"+si);
Test t = new Test();
t.iMessage();
Console.ReadKey();
}
}
}