java - Calling a method that only prints out a "loan statement" -
i doing assignment class , started making our own methods , thought seemed easy enough has become extremely frustration , hoping can me wrap head around it.
first things first , assignment trying complete this: make modular program calculate monthly payments, seems easy few restrictions on question follows
the main method should:
ask user
- the loan amount
- the annual interest rate ( decimal, 7.5% 0.075 )
- the number of months
and
- call method calculate , return monthly interest rate (annual rate/12)
- call method calculate , return monthly payment
- call method print loan statement showing amount borrowed, annual interest rate, number of months, , monthly payment.
i have gotten end of printing out loan statement cant life of me proper way call it, , make show once run program :/ if can me understand how done appreciate it.
(i realize there other mistakes in code right rather focus on need done) import java.util.scanner; public class loanpayment {
/** * main method declares variables in program while getting user * info of amount loaned, interest rate of loan, , loans duration. * * main method calls other methods calculate monthly interest * monthly payments , output of loan statement */ public static void main(string[] args) { // declare variables double interest; // interest attributed loan double minterest; // loans interest divided 12 int time; // how long loan taken out double principle; // amount borrowed double mpayment; // how paid each month double loan; // initate new scanner class scanner keyboard = new scanner(system.in); // user input/information system.out.println("hi, please enter loan amount here:"); principle = keyboard.nextdouble(); system.out.println("thanks, annual interest rate in decimal notation" + "(example: 7.5% 0.075:"); interest = keyboard.nextdouble(); system.out.println("now please put in number of months loan taken out for"); time = keyboard.nextint(); // call method calculate , return monthly interest rate minterest = calcminterest( interest ); // call method calculate , return monthly payment mpayment = calcmpayment (minterest, principle, time); // call method print loan statement } // end main () /******************************************************************************/ // class calculates , returns monthly interest on loan public static double calcminterest( double interest ) { double minterest; minterest = (interest / 12); return minterest; } // end calcminterest /******************************************************************************/ // class calculates , returns monthly payment public static double calcmpayment (double minterest, double principle, int time) { double mpayment; mpayment = (minterest * principle) / (1-(1+ math.pow(minterest,-time))); return mpayment; } // end calcmpayment /******************************************************************************/ // class prints loan statement showing amount borrowed // , amount borrowed, annual interest rate, number of months // , monthly payment public static void loanstatement(double principle, double interest, int time, double mpayment) { system.out.println(" principle is" + principle);
if // call method print loan statement
have left do, need on line below it:
loanstatement(principle, interest, time, mpayment);
and should work fine.
your other methods have non-void return types, put somevariable = yourmethod(yourarguments)
in order accept return value. however, loanstatement
has void
return type. don't need this. can call showed above , execute code in method.
though, personal preference change loanstatement
string
return type , put print statement in main
, print return of loanstatement
. methods return strings
, more flexible future use (for example, if wanted allow program write file, need 2 loanstatement
methods, or rework loanstatement
).
Comments
Post a Comment