我的程序不会调用我的方法

时间:2017-02-11 22:18:22

标签: java

我刚刚开始编程,我发现我的大部分资源都非常无益。希望你们能帮忙!

我的程序运行直到它到达显示方法,然后它就停止了。没有错误,也没有构建成功。它只是继续用户输入。有任何想法吗?

以下是所有程序。我也为对象创建了一个单独的类。如果您认为问题可能存在,请告诉我。谢谢!

import java.util.Scanner;

public class HernandezMortgageCalculator {

    public static void main(String[] args) {
        programDescription();
        System.out.println();

        MortgageLoan mortgageLoan1 = new MortgageLoan();

        Scanner userInput = new Scanner(System.in);
        System.out.println();
        System.out.println("Please enter the home buyer's last name: ");
        String lastName = userInput.nextLine();
        System.out.println("Please enter the home's zip code: ");
        String zipCode = userInput.nextLine();
        System.out.println("Please enter the home value: ");  
        double homeValue = userInput.nextDouble();
        System.out.println("Please enter the annual interest rate: ");
        double annualInterestRate = userInput.nextDouble();

        mortgageLoan1.setLoanIdentifier(mortgageLoan1.getLoanIdentifier());
        mortgageLoan1.setHomeValue(userInput.nextDouble());
        mortgageLoan1.setLoanAmount();
        mortgageLoan1.setAnnualInterestRate(userInput.nextDouble());

        System.out.println();
        System.out.println();

        displayLoanDetails(mortgageLoan1);
        displayMortgageResults(mortgageLoan1); 

    }
public static void programDescription() {
    System.out.println("This program implements a Mortgage Calulator");
    System.out.println();
    System.out.println("Given a home's purchase price and loan's annual" +
                       "interest rate, it will compute the monthly" +
                       "mortgage payment, which includes taxes, " +
                       "insurance principle and interest.");
}
public static void displayLoanDetails(MortgageLoan mortgageLoan1){
    System.out.println();
    System.out.println("Loan Details");
    System.out.printf("  Loan identifier             %f "
                      + mortgageLoan1.getLoanIdentifier());
    System.out.println();
    System.out.printf("  Loan amount                 %.2f "
                      + mortgageLoan1.getLoanAmount() );
    System.out.println();
    System.out.printf("  Loan length                 %f "
                      + mortgageLoan1.getLengthOfLoan() + " years");
    System.out.println();
    System.out.printf("  Annual Interest Rate        %.3f"
                      + mortgageLoan1.getAnnualInterestRate() + "%");
    System.out.println();
}
public static void displayMortgageResults (MortgageLoan mortgageLoan1) {
   double monthlyPropertyTax = mortgageLoan1.calcMonthlyPropertyTax();
   double monthlyInsurancePremium = 
                               mortgageLoan1.calcMonthlyInsurancePremium();  
   double monthlyPrincipleAndLoan = 
                                mortgageLoan1.calcMonthlyPrincipleAndLoan(); 
   double totalMonthlyMortgage = monthlyPropertyTax + monthlyInsurancePremium
                               + monthlyPrincipleAndLoan;

    System.out.println();
    System.out.println("Monthly Mortgage Payment");
    System.out.printf("  Monthly Taxes                  %.2f",
                      monthlyPropertyTax);
    System.out.println();
    System.out.printf(" Monthly Insurance             %.2f",
                       monthlyInsurancePremium);
    System.out.println();
    System.out.printf("  Monthly Principle & Interest   %.2f",
                      monthlyPrincipleAndLoan);
    System.out.println();
    System.out.println("                               --------");
    System.out.println();
    System.out.printf("  Total Monthly Mortage Payment  %.2f", 
                      totalMonthlyMortgage);
 } 

public class MortgageLoan {
    private String loanIdentifier;
    private double homeValue;
    private double downPayment;
    private double loanAmount;
    private int lengthOfLoan;
    private double annualInterestRate;

    public MortgageLoan() {
       loanIdentifier = "";
       homeValue = 0.0;
       downPayment = 10.0;
       loanAmount = 0.0;
       lengthOfLoan = 30;
       annualInterestRate = 0.0;
    }
    public static char firstFour(String lastName){
       char result = lastName.charAt(0);
       result += lastName.charAt(1);
       result += lastName.charAt(2);
       result += lastName.charAt(3);
       return result;
    }
    public static char firstThree(String zipCode){
      char result = zipCode.charAt(0);
      result += zipCode.charAt(1);
      result += zipCode.charAt(2);
      return result; 
    }

    public static String lastNameZipCode(String lastName, String zipCode) {
       String result = "";
       result = lastName.toUpperCase();
       result += firstFour(lastName);
       result += firstThree(zipCode);
       return result;
}

    void setLoanIdentifier(String lastNameZipCode) {
        loanIdentifier = lastNameZipCode;
    }
    void setHomeValue(double newHomeValue) {
        homeValue = newHomeValue;
    }
    void setLoanAmount() {
        double newLoanAmount = homeValue - homeValue * (downPayment/100);
        loanAmount = newLoanAmount;
    }
    void setAnnualInterestRate(double newAnnualInterestRate) {
        annualInterestRate = newAnnualInterestRate;
    }

    public String getLoanIdentifier() {
    return loanIdentifier;
    }

    public double getLoanAmount(){
        return loanAmount;
    }

    public int getLengthOfLoan(){
        return lengthOfLoan;
    }

    public double getAnnualInterestRate(){
        return annualInterestRate;
    }

public double calcMonthlyPropertyTax() {
    final double HOME_ASSED_VALUE_PERCENTAGE = 0.85;
    final double ANNUAL_PROPERTY_TAXES_PERCENTAGE = 0.0063;
    final double ADMIN_FEE = 35.00;
    double homeAssessedValue = homeValue * HOME_ASSED_VALUE_PERCENTAGE;
    double annualPropertyTaxes = (homeAssessedValue *
                              ANNUAL_PROPERTY_TAXES_PERCENTAGE + ADMIN_FEE);
    double monthlyPropertyTax = annualPropertyTaxes/12;
    return monthlyPropertyTax;
}

public double calcMonthlyInsurancePremium() {
    final double ANNUAL_PREMIUM_PERCENTAGE = .0049;
    double annualInsurancePremium = .0049 * homeValue;
    double monthlyInsurancePremium = Math.round(annualInsurancePremium/12);
    return monthlyInsurancePremium;
}

public double calcMonthlyPrincipleAndLoan(){
    double monthlyInterestRate = annualInterestRate/100/12;
    double Factor = Math.exp((lengthOfLoan*12) * Math.log   
                   (monthlyInterestRate + 1));
    double monthlyPrincipleAndLoan = (Factor * monthlyInterestRate *
                                      loanAmount)/(Factor - 1);
    return monthlyPrincipleAndLoan;

  }
}

0 个答案:

没有答案