Writing this exercise program for my class and I'm a mess. Please help out, any tips appreciated. I can post my codes that has errors if needed. Thanks. I am supposed to write a program that let the user enter loan amount: number of years: interest rate: then the output is payament # interest prncipal balance 1 58.33 806.93 9193.07 2 3 . . . 12 THANKS!! any tip will help.
Well, the first thing that springs to mind is that: numOfYears = paymentNum * 12 is not correct. Instead, you should say:
Note that this is a variation on the for-loop idiom ("for(int index = 0; index < count; index++)"); however, in this case the variation makes more sense. Once you've done that, you should just need to perform the appropriate calculations and display the results. If you have any further questions, just ask. Oh, and, for our sake, when you post code, please place it between [CODE] and [/CODE] tags, it makes it easier for the rest of us to read. Thanks!
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: Oct 02, 2003
//calcualte principal double principal = monthlyInterestRate - interest;
------------ --------------------Configuration: j2sdk1.4.0_03 <Default>-------------------- D:\xxxx\xxx.java:40: variable monthlyInterestRate might not have been initialized double principal = monthlyInterestRate - interest; ^ D:\xxx\xxx.java:40: variable interest might not have been initialized double principal = monthlyInterestRate - interest; ^ 2 errors Process completed. --------------------------- [ October 02, 2003: Message edited by: Gordan Lee ]
In Java, local (method) variables are treated differently from class member variables. Class variables get initialized to default value (0, 0.0, false, null; whichever of these is appropriate for the type). However, method variables do not get assigned a value -- not even null. So, before you can use one in a calculation or anything, you have to assign it a value (usually 0, occassionally somethign else) Instead of:
And I'm just going to drop another reminder about the [CODE] and [/CODE] tags -- it really does make a difference! [ October 02, 2003: Message edited by: Joel McNary ]