
-----------------------------------
supahsain08
Wed Feb 13, 2008 8:04 pm

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


class work
{
    public static void main(String

the problem is i don't know how to put interest and principle in a for loop too
any hints will be appreciated

-----------------------------------
HeavenAgain
Wed Feb 13, 2008 8:37 pm

RE:Need help with my first program
-----------------------------------
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...

-----------------------------------
supahsain08
Thu Feb 14, 2008 3:52 pm

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.
http://i32.tinypic.com/20gcf4m.jpg

Here's my code

import java.text.*; 
public class asn1
{
    public static void main(String[] args) 
      {
      	
      	

        double interestrate, principal, interest, time, total;
        int month;
        String pattern1 = "#.##";
        String pattern2 = "###.##";
        DecimalFormat x = new DecimalFormat(pattern1);
        DecimalFormat y = new DecimalFormat(pattern2);
      	 
	interestrate = 0.12;
	principal = 100;
	time = 0.0833;
        interest = interestrate * principal * time ;

        System.out.println ("Initial Principle = " + principal);
        System.out.println ("Interest Rate = " + interestrate);

        for (month = 1; month 