Java Reference
In-Depth Information
Table 3-20
Inputs and Outputs for Income to Debt Ratio Calculator
INPUTS
OUTPUTS
amount of monthly income
Income to Debt Ratio
amount of mortgage or rent (or zero)
amount of auto loan (or zero)
amount of other debt (or zero)
Perform the following steps.
1. Start TextPad. Save the new document as a Java source code file on the Data
Disk. Name the file DebtRatio.
2. Begin your code by typing a block comment with the Programming
Assignment number, your name, the current date, and the program name,
DebtRatio.java. Write a description or purpose comment.
3. Type a statement to import the javax.swing package.
4. Type the class header and main() method header.
5. Declare the following variables to be Strings: strMonthlyIncome,
strMortgage, strAutoLoan, and strOtherDebt.
6. Declare the following variables to be doubles: monthlyIncome, mortgage,
autoLoan, otherDebt, and ratio.
7. Create an input section beginning with an appropriate line comment. In
order to accept user input, enter showInputDialog() methods to display the
prompts and accept user input for monthly income, mortgage, auto loan,
and other debt.
8. Create a conversion section, beginning with an appropriate line comment, to
parse each of the inputted values.
9. Create a calculation section, beginning with an appropriate line comment,
to calculate the income to debt ratio using the following formula: ratio =
(mortgage + autoLoan + otherDebt) / monthlyIncome.
10. Create an output section, beginning with an appropriate line comment. Use
concatenation to print a message and the variable, ratio, in a JOptionPane
dialog or message box.
11. Close both the main() and class methods with closing braces.
12. Compile your program by clicking Tools on the menu bar and then clicking
Compile Java.
13. If no compilation errors occur, execute the program by clicking Tools on the
menu bar and then clicking Run Java Application. Run the program again
with your own personal data.
14. In the TextPad window, use the Print command on the File menu to print a
copy of the source code for your instructor.
15. Quit TextPad.
 
Search WWH ::




Custom Search