Java Reference
In-Depth Information
4. The third command-line argument is the number of years for the
loan. This value needs to be parsed into an int, which can be done
using the Integer.parseInt() method.
5. You now have all the data you need to compute the monthly pay-
ment. Use the following formulas for computing the mortgage, and
display the result using the println() method.
N = years x 12 //Number of payments
R = interest_rate / (12 x 100) //Monthly interest rate
Monthly payment = principal x (R / (1 - (1 + R)^-N))
6. To compute the power of (1 + R) to the -N, use the following Java
function, which computes a to the power b:
Math.pow(a, b)
The return value is a double.
7.
Save, compile, and run the Mortgage program. Be sure to enter the
three command-line arguments. For example, the following state-
ment computes the monthly payment for a $200,000 mortgage at
6.5 percent for 30 years:
java Mortgage 200000 6.5 30
The output should display the monthly payment of the mortgage
information input on the command line.
Summary
The keywords goto and const are reserved words, meaning they have
no implementation in Java. The terms true, false, and null are special
literal values and technically are not Java keywords.
■■
A valid identifier cannot be a keyword; must start with a character,
underscore, or dollar sign; and can contain the digits 0-9 as long as the
identifier does not start with a digit.
■■
Java has eight primitive data types: byte, short, int, long, float, double,
char, and boolean. Their size does not depend on the underlying oper-
ating system or platform. The numeric values are all signed, meaning
that they hold both positive and negative values. The char data type is
16 bits and is unsigned. The size of a boolean is not specified, and it can
only contain the values true or false.
■■
Search WWH ::




Custom Search