Define a default constructor with no parameters that will


Java Programming Assignment: Objects and Instance Methods

All of your Alice programs have been using objects already. And the predefined function and procedure methods in Alice are equivalent to instance methods for those objects in Java. You also defined your own methods within an Alice class, which had to be applied to a specific object in order to run.

This assignment will apply the same concepts to Java. You will create a new class, and use the new class to create an object in Java. Methods defined within the new class (instance methods, similar to the Alice procedure and function methods) will be called using the dot (.) operator, to send a message to the object.

WARNING: This assignment will be more challenging than the previous assignments, so make sure to start early and allocate enough time to complete it, including time you might need to seek any necessary help.

Problem Summary

Suppose you wanted to modify your Mortgage Calculator from Java programming. You could:

• Store all the previous data about one mortgage loan as data fields within an object
• Add a mortgage loan identifier data field
• Revise the calculation methods to be instance methods within the object's class

o NOTE: This will eliminate the need to pass the loan data into the methods via parameters.

Since you will be modifying your Mortgage Calculator program, make sure you use your instructor's feedback to fix any mistakes.

Overview of Program

This program will contain two classes, in two separate files within your project:

• A new MortgageLoan class to define the data fields and methods for a MortgageLoan object, containing:

o Six data field definitions for a MortgageLoan object
o A constructor method to create a MortgageLoan object
o Four setter methods to set the values for four of the data fields
o Four getter methods to get the values of four of the data fields
o An instance method to compute the monthly property tax.
o An instance method to compute the monthly insurance premium.
o An instance method to compute the monthly principle and interest loan payment.

• The main MortageCalculator class, modified to define only 4 methods, containing:

o A main method to display the program description, create an object, read the inputs from the user, and call the other methods.
o A static method to display a description of what the program will do.
o A static method to display loan details.
o A static method to calculate and display the results of the program.

Since there will be multiple files, the program will be submitted via a .zip file (see last page).

Program Requirements

Modify the program you wrote for Java Assn 3, as follows:

1. Define an additional Java class (File | New File | Java Class) named: MortgageLoan

Within the MortgageLoan class, define the following private data fields to store properties about the mortgage loan:

• loan identifier (String) ← new!
• home value
• down payment (double value that will hold a whole number percent of home value, e.g. 10.0)
• loan amount
• length of loan (in whole years)
• loan annual interest rate (floating point percentage, e.g. 4.5)

Remember that all private data fields defined at the class-level can be accessed by any method within the same class (without parameter passing).

Also within the new MortgageLoan class, you will define instance methods that can be used with an object of the MortgageLoan class, as follows:

• Define a default constructor with no parameters that will create the object with the following initial data values set:

Loan identifier set to "" (an empty String)

Home value, loan amount, and interest rate all set to 0.0 Down payment set to 10%

Loan length set to 30 years

• Create setters for the following data fields:
o Setter for loan identifier

- Input parameters will be two Strings: the home buyer's last name and zip code.
- Use the built-in Java String methods to uppercase and extract the first 4 letters of the last name and concatenate them with the last 3 digits of the zip code to create the loan identifier.
- Set the loan identifier data field to this value.

o Setter for home value

- Input parameter will be home value.
- Set the home value data field to the parameter value.

o Setter for loan amount

- No parameters
- Calculate the loan amount using the home value and the down payment percent data fields. Be sure to convert the down payment from whole number value to a value that can be used in a math formula.
- Set the loan amount data field to the calculated value.

o Setter for loan annual interest rate

- Input parameter will be the annual interest rate.
- Set the loan annual interest rate data field to the parameter value

• Create getters for the following data fields in the MortgageLoan class:

o loan identifier (String)
o loan amount
o length of loan (in years)
o loan annual interest rate (percentage)

Each of the getters should return the data field's current value.

• Move the calculation methods (methods 2 - 4) from Java Assn 3 from the MortgageCalculator class to the MortgageLoan class. Then modify them, so they can be used as instance methods in the new MortgageLoan class, as follows:

o Eliminate the parameter lists from each method (parameters will no longer be necessary).
o Keep all constants previously defined in the methods, except for the number of loan months defined in method 4.

- Use the loan length data field from the object to calculate the number of months in the loan, instead of the previous constant value.

o Modify the formulas to use the object data fields, instead of parameters.

2. Within the original MortgageCalculator class that contains the main method:

• Make sure you deleted the old static calculation methods when you moved them to the MortgageLoan class.
• Modify the main method to perform the following additional tasks:

o After displaying program description, create an object of the new MortgageLoan class type.
o Prompt for (using descriptive prompts) and read:

- the home buyer's last name (you can assume there will be no spaces in the last name and it will contain at least 4 letters).
- the home buyer's zip code

o Same as before, prompt for (using descriptive prompts) and read the home value and the annual interest rate.

Attachment:- morgage_0.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Define a default constructor with no parameters that will
Reference No:- TGS01702373

Now Priced at $40 (50% Discount)

Recommended (91%)

Rated (4.3/5)