Computer Science Canada Need help with my first program |
Author: | supahsain08 [ Wed Feb 13, 2008 8:04 pm ] | ||
Post subject: | Need help with my first program | ||
Use code (or syntax) tags! - wtd Hello, I started java couple of weeks ago, and i know almost nothing about it My teacher gave us our first java assignment couple of weeks go We are suppose to make a program which calculate and print out the interest for each month for one year (12 months), then add the interest to the principal to get a new total and print out the new total principle. My proggy
the problem is i don't know how to put interest and principle in a for loop too any hints will be appreciated |
Author: | HeavenAgain [ Wed Feb 13, 2008 8:37 pm ] |
Post subject: | RE:Need help with my first program |
Quote: put interest and principle in a for loop just do what you just said, but i dont think "principal" needs to be added in, only the interest and total.........
Ps. your total should only be your interest (for every month) + the initial amount deposit , unless im wrong... |
Author: | supahsain08 [ Thu Feb 14, 2008 3:52 pm ] | ||
Post subject: | Re: Need help with my first program | ||
That's my Assignment This following requirements must be met by the program you write: Your program should do the following: * create some variables named interestrate, principal, interest, time, and total (all numbers should be doubles). * Set the values of the variables interestrate, and principal, to some appropriate numbers (interestrate should be between 0.0 and 1.0) * Use a for loop to calculate and print out the interest for each month for one year (12 months), then add the interest to the principal to get a new total and print out the new total principle. ![]() Here's my code
This is what i don't understand, how am i suppose to calculate the interest each month, i know how to calculate for first month I = 0.083 * 100 * .12 = 0.996 how do you find the interest for second and third month, what's the formula [/syntax] |
Author: | HeavenAgain [ Thu Feb 14, 2008 5:34 pm ] |
Post subject: | RE:Need help with my first program |
what's the formula? your teacher just gaved it to you. "interest = principal x rate x time" in your case, "interest = interestrate * principal * time" but in your for-loop, you have interest = interest + 0.01; , now what you did is instead of using the equation you have, you just add 0.01 to interest everytime (which is wrong), and after, you have principal = principal + interest; which just says, ok principal just add the interest, which is correct, IF you did your interest correct. im not sure if you learned a runtime table or whatever it is called, where you follow your code line by line, and put the values in a table, it helps alot when you just begin to learn about loops, do that, and you'll see where you are wrong. (learn to read your own code, and follow it) |
Author: | supahsain08 [ Thu Feb 14, 2008 6:08 pm ] | ||
Post subject: | Re: Need help with my first program | ||
K did some more modifications
Output ![]() any mistake? |
Author: | HeavenAgain [ Thu Feb 14, 2008 6:47 pm ] | ||
Post subject: | RE:Need help with my first program | ||
if i were to be picky about it, your output did not exactly match your teacher's output, the Initial Principle = 100.00 you are missing another 0 on the end, so format that properly, and also
|
Author: | syntax_error [ Thu Feb 14, 2008 6:49 pm ] |
Post subject: | RE:Need help with my first program |
instead of asking us; do the math on paper first and think; you will answer your own questions that way; be self aware a bit more. On a side note your class names should have the first letter in CAPS |
Author: | supahsain08 [ Thu Feb 14, 2008 7:01 pm ] |
Post subject: | RE:Need help with my first program |
Thanks HeavenAgain @ syntax_error: I don't have the first letter in caps because my teacher said file name should be "asn1.java" |
Author: | syntax_error [ Thu Feb 14, 2008 7:06 pm ] |
Post subject: | RE:Need help with my first program |
oo well good coding conventions state: have the first letter of your class in CAPS; jsut keep in as reference for work maybe not for your teacher? |