* BasicMethodsLab.java * * Created on February 8, 2007, 9:56 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package lab03; import javax.swing.*; public class BasicMethodsLab { public static void main( String args[] ) { String propertyCostStr; // Value entered by user; string type String downPaymentStr; // Value entered by user; string type String numberOfYearsStr; // Value entered by user; string type String propertyStr; // Letter entered by user; string type char propertyType; // Storing the letter chosen by the user double propertyCost; // The double form of the user-entered property cost double downPayment = 0; // The double form of the user-entered down payment double loanAmount = 0; // The calculated price of the loan amount double monthlyPayment; //The monthly loan payment double annualInterestRate = 7.5; //The annual interest rate int response = 0; // The user's response as to whether to continue int numberOfYears = 0; //integer form of the user-entered down payment // Initialize the output string to the empty string String outputStr = ""; while (true) { // Read in item price from user as a string propertyCostStr = JOptionPane.showInputDialog("Enter property cost"); // Convert from type String to type double propertyCost = Double.parseDouble(propertyCostStr); // Read in number ordered from user as a string downPaymentStr = JOptionPane.showInputDialog("Enter down payment"); // Convert from type String to type double downPayment = Double.parseDouble(downPaymentStr); //Read in category from user as a number propertyStr = JOptionPane.showInputDialog("Choose the letter that best corresponds with your" + "property type" + "\nR Residential " +"\n C Commercial \n A Argricultural"); propertyType = 'R'; propertyType = 'C'; propertyType = 'A'; // Read in number of years from user as a string numberOfYearsStr = JOptionPane.showInputDialog("Enter number of years for loan:"); // Convert from type String to type integer numberOfYears = Integer.parseInt(numberOfYearsStr); // Echo print the entered values outputStr = outputStr + "Property Cost: " + propertyCost + ", "; outputStr = outputStr + "Down Payment: " + downPayment + ", "; // Calculate loan amount for the property loanAmount = propertyCost - downPayment; // Calculate monthly payment // Change the annual interest rate to a decimal (/100) and a monthly rate (/12) monthlyPayment = loanAmount * (annualInterestRate/1200) / (1 - 1 / Math.pow(1 + (annualInterestRate/1200), numberOfYears * 12)); // Print the monthly payment outputStr = outputStr + ", " + "Monthly Payment: " + monthlyPayment + "\n"; //Print the number of years for the loan // Determine whether the user wants to continue the loop response = JOptionPane.showConfirmDialog(null, outputStr + "\nContinue?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.NO_OPTION) break; } // Display final output to the user JOptionPane.showMessageDialog( null, outputStr, "Property Loan Amounts", JOptionPane.INFORMATION_MESSAGE); System.exit( 0 ); // Terminate the program } }