Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ArgumentException is an existing class that derives from Exception; you use it w

ID: 3847272 • Letter: A

Question

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 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 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

import java.util.Scanner;

public class MortgageApplication {
String name;//to store name
int credit_score;//to store credit score
private void setName(String nm){//function to set name of applicants
name=nm;
}
private void setScore(int sc){//function to set the credit score
try{
if( sc <= 300 || sc >= 850) {//condition to check that the creidt score is within range
throw new IllegalArgumentException("Credit score is not valid");//generating custom exception
}
credit_score=sc;//assigning credit score
}catch(IllegalArgumentException ill){
System.out.println(ill.getMessage());
}
}
public static void main(String args[]){
MortgageApplication m=new MortgageApplication();//creating object
Scanner input=new Scanner(System.in);
System.out.print("Enter name: ");
m.setName(input.next());
System.out.print("Enter credit score: ");
m.setScore(input.nextInt());
System.out.println("Name is: "+m.name);
System.out.println("Credit score is: "+m.credit_score);
if(m.credit_score>650){//checking whether credit score is acceptable
System.out.println("Application is accepted");
}else{
System.out.println("Credit is low, application is rejected");
}
}
}

Output:

Enter name: xyz
Enter credit score: 12
Credit score is not valid
Name is: xyz
Credit score is: 0
Credit is low, application is rejected

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote