Question: I need some C# prograaming help I wrote 3 files for the original assignment ( Below is the code ) PROGRAM.cs using ConsoleApp 6 ;

I need some C# prograaming help
I wrote 3 files for the original assignment (Below is the code)
PROGRAM.cs
using ConsoleApp6;
class Program
{
public static double loanAmount;
public static double years;
public static double interest;
static void Main(string[]args, double loanAmount)
{
Console.Write("Enter loan amount: ");
double loanAmount = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter number of years: ");
double years = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter interest rate (in decimal form, e.g.,0.05 for 5%): ");
double interestRate = Convert.ToDouble(Console.ReadLine());
C1 loanInfo = new C1(loanAmount, years, interestRate);
double totalInterests = loanInfo.PayInterests();
Console.WriteLine($"Total interest to be paid: {totalInterests:C}");
string message = loanInfo.iMessage();
Console.WriteLine(message);
}
private static void CheckLoanAmount(double loanAmount)
{
throw new NotImplementedException();
}
}
IMYInterface.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
interface IMyInterface
{
string iMessage();
}
}
C1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp6
{
class C1 : IMyInterface
{
private double loanAmount =0.0;
private double years =0.0;
private double interestRate =0.0;
private double interests =0.0;
public C1(double loanAmount, double years, double interestRate)
{
this.loanAmount = loanAmount;
this.years = years;
this.interestRate = interestRate;
}
public double PayInterests()
{
interests = loanAmount * interestRate * years;
return interests;
}
public string iMessage()
{
return "Be Ready!";
}
public double LoanAmount
{
get { return loanAmount; }
set { loanAmount = value; }
}
public double Years
{
get { return years; }
set { years = value; }
}
public double InterestRate
{
get { return interestRate; }
set { interestRate = value; }
}
}
}
Here is the second part that I need help with.
1. Create a class "MyRangeException.cs"(similar to example code).(20%)
2. In "Program.cs", in main(), Add Exception Handling (20%)
class Program
{
public static double loanAmount;
public static double years;
public static double interest;
static void Main(string[] args)
{
.....
//for loanAmount
do {
try
{
Console.Write("Please enter the loan amount: $");
loanAmount = Convert.ToDouble(Console.ReadLine());
CheckLoanAmount (loanAmount);
continueLoop = false;
}
catch ( FormatException formatException )
{
Console.WriteLine("
"+ formatException.Message );
Console.WriteLine( "Please enter a double value.
");
}// end catch
catch (MyRangeException negativeNumberException )
{
Console.WriteLine("
"+ negativeNumberException.Message );
//Console.WriteLine( "Please enter a non-negative value.
");
}// end catch
} while (continueLoop);
.....
//for years
do {
}while ( continueLoop );
.....
//for interest
do {
}while ( continueLoop );
}
.....
}
Requirement (similar to the example): Add methods to check the value
=====================
- loanAmount (20%)
- must be a number, threw FormatException if not
- must be greater than 50000, throw Exception if not
- Create a method CheckLoanAmount(double la)
throw new MyRangeException("Loan Amount must be $50,000 or more.");
-public static void CheckLoanAmount(double la)
{
if (la <50000)
throw new MyRangeException( "Loan Amount must be $50,000 or more.");
}
- loanInterest (20%)
- must be a number, threw FormatException if not
- must be greater than 1%, throw Exception if not
- Create a method CheckLoanInterest

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!