6A
Complete the class, HomeLoanProcessor
, an application for a home loan that will be used by a loan officer. Below are some made-up criteria to determine if the loan is granted. These qualifications are for some fictitious place - not the Bay Area!
A loan is granted based on the amount of the loan, annual household income, and the number of years a person has lived at the current address. The loan is granted if
Hint: it will simplify your code if you set a boolean variable granted to false and only change it to true if a set of conditions is true.
HomeLoanProcessor
has a constructor that takes the loan amount, annual household income, and the number of years a person has lived at the current address
public HomeLoanProcessor(double loanAmount, double annualIncome, int yearsAtCurrentAddress)
The parameters must be positive. If only one of them is not positive, set all 3 to 0.
It has these methods
public double getAnnualIncome()
gets the annual household income of the applicantpublic void setAnnualIncome( double income)
sets a new annual income. If less than or equal to 0, set loan amount, annual income, and years at current address to 0.public void setLoanAmount(double amount)
sets a new annual income for this applicant. If less than or equal to 0, set loan amount, annual income, and years at current address to 0.public boolean loanGranted()
returns true if application meets the stated requirements. Otherwise falsepublic double getLoanAmount()
providedpublic double getYearsAtCurrentAddress()
providedProvide Javadoc
Use nested ifs for loanGranted
. There are other ways to do this, but I want you to use nested ifs. You should have 3 outer if clauses (if / else if / else)
For the draft, provide the constructor, and implement the getAnnualIncome()
and setAnnualIncome()
methods. Implement setLoanAmount
and loanGranted
as stubs. Note that a stub with return type boolean returns false. Provide the Javadoc. The Javadoc should document the code that will do in the final not what it does in the draft.
6B
Write an application called LoopsAndMore
which gets valid input
Instructions updated Oct 6 to match Codecheck
Requirement for one loop removed Oct 7
For the draft: Do the first two steps
6C
Complete the class StringsAndLoops
which has a constructor that takes a String of text. Implement the following methods.
public String getText()
returns the textpublic int getUpperCaseCount()
gets the number of the uppercase letters in the text. You can use charAt to get each letter and then use Character's
isUpperCase
method.public int getACount()
gets the number of a's in the String, either upper or lower case. Do not change the instance variablepublic String firsts()
gets a string consisting of the first character of every word in the string. If the string is the empty string, return the empty String. indexOf (" ", fromIndex)
to determine where a new word starts. The next character will be the first letter of a word. indexOf
returns -1 if the space is not in the search string so tit can be used as control the loop to tell when to stop.Provide Javadoc
For the draft, provide the instance variable, constructor, getText() and getUpperCaseCount() methods along with the necessary Javadoc