Click here to Skip to main content
14,870,621 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
In my main program cs file I have this:
C#
using System;

namespace Assignment_11
{
    class Program : MyRangeException
    {
        public static double loanAmount;
        public static double years;
        public static double interest;
        static void Main(string[] args)
        {
            bool continueLoop = true;

            //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("\n" + formatException.Message);
                    Console.WriteLine("Please enter a double value.\n");
                } // end catch
                catch (MyRangeException negativeNumberException)
                {
                    Console.WriteLine("\n" + negativeNumberException.Message);
                    //Console.WriteLine( "Please enter a non-negative value.\n" );
                } // end catch
            } while (continueLoop);

         //for years
         do
            {
                try
                {
                    Console.Write("Please enter the number of years for the loan: ");
                    years = Convert.ToDouble(Console.ReadLine());
                    CheckLoanYears(years);
                    continueLoop = false;
                }
                catch (FormatException formatException)
                {
                    Console.WriteLine("\n" + formatException.Message);
                    Console.WriteLine("Please enter a double value.\n");
                } // end catch
                catch (MyRangeException negativeNumberException)
                {
                    Console.WriteLine("\n" + negativeNumberException.Message);
                    //Console.WriteLine( "Please enter a non-negative value.\n" );
                } // end catch

            } while (continueLoop);

         //for interest
         do
            {
                try
                {
                    Console.Write("Please enter the interest rate for the loan: ");
                    interest = Convert.ToDouble(Console.ReadLine());
                    CheckLoanInterest(interest);
                    continueLoop = false;
                }
                catch (FormatException formatException)
                {
                    Console.WriteLine("\n" + formatException.Message);
                    Console.WriteLine("Please enter a double value.\n");
                } // end catch
                catch (MyRangeException negativeNumberException)
                {
                    Console.WriteLine("\n" + negativeNumberException.Message);
                    //Console.WriteLine( "Please enter a non-negative value.\n" );
                } // end catch

            } while (continueLoop);

        }
    }
}

And in my exception cs I have:
C#
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Assignment_11
{
    class MyRangeException
    {
        public MyRangeException(string? message);
        public static void CheckLoanAmount(double la)
        {
            if (la < 50000)
                throw new MyRangeException("Loan Amount must be $50,000 or more.");
        }
        public static void CheckLoanInterest(double it)
        {
            if (it < 1)
                throw new MyRangeException("Interest Rate must be 1% or more.");
        }
        public static void CheckLoanYears(double yr)
        {
            if (yr < 5)
                throw new MyRangeException("Years must be 5 years or more.");
        }

    }
}

And the instructions are as follows.
Quote:
Continue with Assignment "Loan Program". Read code "SquareRootTest".

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( "\n" + formatException.Message );
Console.WriteLine( "Please enter a double value.\n" );
} // end catch
catch (MyRangeException negativeNumberException )
{
Console.WriteLine( "\n" + negativeNumberException.Message );
//Console.WriteLine( "Please enter a non-negative value.\n" );
} // 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(double it)
throw new MyRangeException("Interest Rate must be 1% or more.");
- public static void CheckLoanInterest(double it)
{......}


- years (20%)
- must be a number, threw FormatException if not
- must be greater than 5, throgh Exception if not
- Create a method CheckLoanYears(double yr)
throw new MyRangeException("Years must be 5 years or more.");
- public static void CheckLoanYears(double yr)
{......}



What I have tried:

I have tried searching for related code and assignments but can not find anything that helps and in my past experience my teacher has been less than helpful and rude when I ask for help.
Posted
Updated 12-Apr-21 11:55am
Comments
SeanChupas 12-Apr-21 16:08pm
   
What is your question?
Sal Monkeyman 13-Apr-21 15:58pm
   
I am just looking to see if someone can help me clarify the instructions up. My teacher does not convey what he wants me to do very well and I was hoping another set of eyes may assist in clearing it up.
SeanChupas 13-Apr-21 16:12pm
   
We have no idea what instructions your teacher gave you. I'm not sure why you thought we could clear this up.

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Few teachers are rude to students without good reason: I'd suggest that you look at how you talked to him about previous problems as he may have a different interpretation of your queries than you do...

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
   
Quote:
The instructions for this assignment are unclear and was not given example code

Since the job of programming is about creating algorithms/programs, your sentence is weird.
It is like saying that you are a cook dying from starvation because you can't find a recipe on internet that match what you have in fridge.
Quote:
I have tried searching for related code and assignments but can not find anything that helps and in my past experience my teacher has been less than helpful and rude when I ask for help.

What do your classmates think about this assignment ?

Obviously, giving you a full blowup solution will defeat the purpose of homework and teaching you programming is out of scope of this forum.
If really you come up with nothing, think about another tutor or think about another job.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900