LAB
EXERCISE 10: Loan Qualifier
Goal:
In this exercise, you will learn how to:
1.
Insert the Main Method (Main Entry Point to the Java Program)
2 Import a Java Class Library
3. Declare Variables
4. Create a Constructor (Special Method)
5. Create a Method and accept arguments
6. Create an Object from the Class
7. Use Nested If-Then-Else statements
9. Use Relational and Logical Operators to test a condition and execute code
8. Call a Method and pass arguments
Program
Specifications:
Description:
This program checks to see whether a bank customer qualifies for a special
loan. The customer must meet one of the
following qualifications.
1. Earns more than
$30,000 per year and have worked in his or her current job for more than 2
years
2. Have worked at
his or her current job for more than 5 years
Use a nested If-Then-Else statement to check the condition
and execute code to display the corresponding message on the screen.
A. Pre-requisites:
1.
Create a folder on your desktop Exercise-10
2. Launch Java EE- Eclipse
Note: You will need to use the Java
Perspective Workbench for this exercise
3. Setup your Eclipse Workspace to point to the Exercise-10
folder
a. Select File-> Switch Workspace
b. Browse and select your Exercie-10 folder as your Workspace.
B. Requirements:
1. Create
a Java Project and name it as LoanQualifier
2. Create
the first Class that will have the Main Method
a.
Name the Class as MainApp
b.
Choose the main method to insert into the
class
3. Create
the second Class that will have the Constructor and Methods
a.
Name the Class as Loan
b.
Do not select the main method stub
C. Requirements
for the Loan Class:
1. Insert
the import java.util.Scanner class
which will allow data to be inputted from the console.
2. a.
Declare the variable- annualSalary
using the double data type
b. Declare the variable- yearsOnJob
using the integer data type
c. Declare the msgLoanApplicant
using the String data type
3. Create
the Constructor (special method) called Loan() that
will prompt the user to input the data
a. Declare
the scanner input class objects
b. Prompt
the user to input the data.
c. Assign
the inputted data to the variable
d. Close
the scanner input class object
Below is the code you can copy and paste
//
declare the scanner object used to input the customer salary from the console //
close scanner input objects |
4. Create
the Method called getApplicantMessage with
a return data type of String
a. This
method should accept the argument parameters (double
salary, int years)
b. Use a nested if-then-else statement
to test the following conditions. If one
of this condition is met
1. Earns more than $30,000 per year and
have worked in his or her current job for more than 2 years
2. Have worked at his or her current job
for more than 5 years
If one of this
condition is met, display the message- “The customer qualifies for the loan”
If either one is not met, display the message- “The customer does not qualify
for the loan”
D. Requirements for the MainApp Class:
1. Add
comments (documentation)– Program Description, Author and Date
2. Create
the instance of object called customer from the Loan class
3. a.
Declare salary variable as double and assign the
value from the customer.annualSalary object’s variable
b. Declare years
variable as integer and assign the value from the customer.yearsOnJob object’s variable
4. Declare
the loanMessage variable
as a String and assign the return value from the called object method - customer.getApplicantMessage(salary,
years). Pass the salary and years
values as arguments.
5. Display
the returned result on the console.
Below is the code you can copy and paste.
//
display the loan message output on the console |
E. Test:
1. Save your Java code
2. Compile and run your Java program.
3. Verify there is no syntax, logical or run-time
errors.
4. Use the following set of test data to
determine if the application is calculating properly:
Annual Salary Years on the Job Loan
Applicant Message
30000 4 The customer does not qualify for the loan
35000 3 The
customer qualifies for the loan
25000 3 The customer does not qualify for the loan
29000 10 The customer qualifies for the loan
F. Submit your exercise in the Canvas Lab
Exercise #10 Drop Box.
1. Submit the screen shot of the Eclipse
Workbench window showing the Console output screen.
You can use Paint (save as JPG) or Word to paste the screenshot.
2. Zip up and submit the compressed LoanQualifier subfolder that is in the Exercise-10
folder.
NOTE: Right click on the subfolder and select
Send to “Compress Folder”. The file will
have a file extension of .zip.