C# Programming ArgumentException is an existing class that derives from Exceptio
ID: 3686497 • Letter: C
Question
C# Programming
ArgumentException is an existing class that derives from Exception; you use it when one or more of a method's arguments do not fall within an expected range. Create an application for Merrydale Mortgage Company named MortgageApplication containing variables that can hold an applicant's name and credit score. Within the class, create a method that accepts a parameter for the credit score and returns true or false, indicating whether the applicant is eligible for a mortgage. If the score is not between 300 and 850, it is invalid, and the method should throw an ArgumentException. An application is accepted when the credit score is valid and at least 650. In the Main() method, continuously prompt the user for applicant data, pass it to the method, and then display a message indicating whether the applicant is accepted, rejected, or has an invalid score.
Explanation / Answer
ArgumentException. A method can be called with invalid arguments. An ArgumentException may be thrown in this case. Exceptions use derived types to indicate their meaning. But this does not give them extra abilities.
Example. This method receives one formal parameter, a string type with the identifier "argument". In the method A, we perform two checks on the value of the variable argument, detecting when it is null or has zero characters in its buffer.
Constructor. When using the ArgumentNullException constructor, you can pass a string literal that is equal to the variable name that was null. This affects the debug output and will aid debugging.
Example
(1) Create an application for Merrydale Mortgage Company named MortgageApplication
(2) containing variables that can hold a students name, high school grade point average, and entrance examination score.
(3) Within the class, create a method that accepts parameters for the students grade point average and test score and returns true or false indicating weather(whether!) the student is accepted to the college.
[Choose a name for your method, say: IsStudentAccepted(), put the parameters inside the brackets on the method heading]
(4) [Inside the method]
A student is accepted when his grade point average is at least 2.5 and his test score is at least 75. If the grade point average is not between 0.0 ad 4.0 inclusive
[return true or false]
(5) [Inside the method]
or the test score is not between 0 and 100 inclusive, throw an ArgumentException from the method.
[You can leave this until the end if it's too difficult]
(6) In the Main() method, continuously prompt the user for student data.
[That means you'll need a while or do..while loop]
(7) [Still inside the Main() method]
Call the method that determines college acceptance. and then display an appropriate message board on the returned value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.