All pastes #358027 Raw Edit

Mine

public text v1 · immutable
·published 2007-02-16 01:16 UTC
rendered paste body
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.*;
import java.text.*;
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 numberOfYear/*
 * BasicMethodsLab.java
 *
 * sStr;      // 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
        
        DecimalFormat prec2 = new DecimalFormat("$#.00");
        
        
        // 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 number of years from user as a string
            numberOfYearsStr = JOptionPane.showInputDialog("Enter number of years for loan:");
            
            //Read in category from user as a number
            propertyStr = JOptionPane.showInputDialog("Choose the letter that best corresponds with your" +
                    "property type" +
                    "\nR. Residential "
                    +"\nC. Commercial \nA. Argricultural");
            
            propertyType = 'R';
            propertyType = 'C';
            propertyType = 'A';
            
            // Convert from type String to type integer
            numberOfYears = Integer.parseInt(numberOfYearsStr);
            
            // Calculate loan amount for the property
            loanAmount = propertyCost - downPayment;
            
            // Echo print the entered values
            outputStr = outputStr + "Type: " + getPropertyTypeName(propertyType)+ ", ";
            outputStr = outputStr + "Cost: " + prec2.format(propertyCost) + ", ";
            outputStr = outputStr + "Loan Amount: " + prec2.format(loanAmount) + ", ";
            
            // Calculate monthly payment
            // Change the annual interest rate to a decimal (/100) and a monthly rate (/12)
            
            // Print the monthly payment
            outputStr = outputStr + "Monthly Amount: " + prec2.format(calculatePayment(propertyCost, downPayment, 
                    numberOfYears, propertyType, loanAmount)) + ", " + "Number of Years: " + numberOfYears + "\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
    }
    
     static double calculatePayment (double propertyCost, double downPayment, int numberOfYears, 
             char propertyType, double loanAmount){ 
         double annualInterestRate = 7.5;
         double result  = 0;
         double subResult = 0;
         result = loanAmount * (annualInterestRate/1200) / (1 - 1 / Math.pow
                 (1 + (annualInterestRate/1200), numberOfYears * 12));
         return result; //This is a stub function
         switch (calculatePayment){
             case 1: subResult = computeResidentialPayment;
             case 2: subResult = computeCommercialPayment;
             case 3: subResult = computeAgriculturalPayment;
         }
     }
     
     static double computeResidentialPayment (double propertyCost, double downPayment, int numberOfYears) {
         
     }
     
     static String getPropertyTypeName (char propertyType){
         String propertyName;         
          switch (propertyType) {
                case 'R':
                case 'r': propertyName = ("Residential"); break;
                case 'C':
                case 'c': propertyName = ("Commercial"); break;
                case 'A':
                case 'a': propertyName = ("Agricultural"); break;
                default: propertyName = ("Residential"); break;
            }
         return propertyName;
     }
     
       
}