java - loan payment calculator, how to implement multiple methods. Trouble developing method to interact with main method -


the idea of assignment have multiple methods interact each other. asking user loan amount, interest rate , duration of loan. program supposed have 1 method calculates monthly rate, 1 method calculates , returns monthly payment , method print loan statement (amt borrowed,annual interest rate, number of months, , monthly payment).

i not receiving errors in editor program asks 3 inputs user , not print loan statement. suggestions?

public class carloan {  /**  * @param args command line arguments  */ public static void main(string[] args) {     // declare variables main method     double loanamount;//double value loan amount      double annualinterestrate;//double value interest rate     int numberofmonths;//int value number of months     double monthlypayment;      scanner keyboard = new scanner(system.in);      system.out.println("please enter amount of loan.");     loanamount = keyboard.nextdouble();      system.out.println("please enter annual interest rate decimal. ex. 7.5% = .075");     annualinterestrate = keyboard.nextdouble();      system.out.println("please enter number of months have pay loan.");     numberofmonths = keyboard.nextint();  }  public static double calcmonthlyinterestrate(double annualinterestrate){     double monthlyinterestrate;         monthlyinterestrate = (annualinterestrate/12);         return monthlyinterestrate; }//end method calcmonthlyinterestrate      public static double calcmonthlypayment(double monthlyinterestrate, double loanamount, int            numberofmonths     ){     double monthlypayment;     double calcmonthlypayment;         calcmonthlypayment = (monthlyinterestrate*loanamount)/(1-(1+monthlyinterestrate)-numberofmonths);         return monthlypayment = calcmonthlypayment; }//end method calcmonthlypayment  public static void loanstatment (double loanamount, double annualinterestrate, intnumberofmonths,  double monthlypayment){  system.out.println("your loan amount " +loanamount);  system.out.println(annualinterestrate);  system.out.println(numberofmonths);  system.out.println(monthlypayment);   }   }//end main method   }//end main method 

i not sure if of code still redundant.

since main method static , calcmonthlyinterestrate references main method calcmonthlyinterestrate must static 2 create static reference each other.

at bottom of post see:

}//end main }//end class 

class methods referenced main method must inside same class being static. once start building own classes , objects won't case

 }//end main          public static double calcmonthlyinterestrate(double annualinterestrate) {           double monthlyinterestrate;           monthlyinterestrate = (annualinterestrate/12);           return monthlyinterestrate;        }  }//end class 

to capture double using method call in main method:

double answer = calcmonthlyinterestrate(/*some double variable here*/); //in main 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -