Results 1 to 7 of 7
  1. #1
    gtorgers is offline Member
    Join Date
    Mar 2014
    Posts
    7
    Rep Power
    0

    Default Trying to get a compound interest program to work

    /code

    package com.eclipsedistilled.cis125;
    import java.util.Scanner;
    public class HowellBank {

    public static void main(String[] args) {
    //Written by George Torgerson
    //Chapter 4 Link to Logic 7
    //Program that accepts an account number, the account owner's first

    //Declarations

    int accountNumber;
    String name;

    final double interest =0.04;
    int balance;

    double totalBalance=0;
    int deposit=100;
    int year;

    Scanner input = new Scanner(System.in);
    System.out.println("Enter account number"); //user inputs account number
    accountNumber=input.nextInt();
    input.nextLine();
    Scanner input2 = new Scanner(System.in);
    System.out.println("Enter first and last name");//user inputs name
    name=input2.next();
    input2.nextLine();
    System.out.println("Balance");//user inputs balance
    balance=input.nextInt();
    //Display the projected running total balance for each year for the next 20 years
    totalBalance= balance+balance*interest;
    //for(deposit=100; )
    for(year=0; year < 21; year++)

    System.out.println("Year " + totalBalance);


    }

    }







    /code

    This is for college homework. Fictional bank. I would like the year to look like Year 1, Year 2, etc.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Trying to get a compound interest program to work

    Do you have a specific question? Also, your code tags are incorrect. They go inside of square brackets.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    gtorgers is offline Member
    Join Date
    Mar 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trying to get a compound interest program to work

    [/code]
    package com.eclipsedistilled.cis125;
    import java.util.Scanner;
    public class HowellBank {

    public static void main(String[] args) {
    //Written by George Torgerson
    //Chapter 4 Link to Logic 7
    //Program that accepts an account number, the account owner's first

    //Declarations

    int accountNumber;
    String name;

    final double interest =0.04;
    int balance;

    double totalBalance=0;
    int deposit=100;
    int year;

    Scanner input = new Scanner(System.in);
    System.out.println("Enter account number"); //user inputs account number
    accountNumber=input.nextInt();
    input.nextLine();
    Scanner input2 = new Scanner(System.in);
    System.out.println("Enter first and last name");//user inputs name
    name=input2.next();
    input2.nextLine();
    System.out.println("Balance");//user inputs balance
    balance=input.nextInt();
    //Display the projected running total balance for each year for the next 20 years
    totalBalance= balance+balance*interest;
    //for(deposit=100; )
    for(year=0; year < 21; year++)

    System.out.println("Year " + totalBalance);


    }

    }



    [/code]
    Specific question is I would like the year to look like year 1, year 2, etc.

  4. #4
    gtorgers is offline Member
    Join Date
    Mar 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trying to get a compound interest program to work

    Java Code:
    package com.eclipsedistilled.cis125;
     import java.util.Scanner;
     public class HowellBank {
    
     public static void main(String[] args) {
     //Written by George Torgerson
     //Chapter 4 Link to Logic 7
     //Program that accepts an account number, the account owner's first
    
     //Declarations
    
     int accountNumber;
     String name;
    
     final double interest =0.04;
     int balance;
    
     double totalBalance=0;
     int deposit=100;
     int year;
    
     Scanner input = new Scanner(System.in);
     System.out.println("Enter account number"); //user inputs account number
     accountNumber=input.nextInt();
     input.nextLine();
     Scanner input2 = new Scanner(System.in);
     System.out.println("Enter first and last name");//user inputs name
     name=input2.next();
     input2.nextLine();
     System.out.println("Balance");//user inputs balance
     balance=input.nextInt();
     //Display the projected running total balance for each year for the next 20 years
     totalBalance= balance+balance*interest;
     //for(deposit=100; )
     for(year=0; year < 21; year++)
    
     System.out.println("Year " + totalBalance);
    
    
     }
    
     }
    
    
    
    
    
    
    
     /code

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Trying to get a compound interest program to work

    You still haven't explained your problem clearly. But I suspect part of the problem is that you are not doing any calculations inside of your for loop. You just print out the same thing over and over again.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    gtorgers is offline Member
    Join Date
    Mar 2014
    Posts
    7
    Rep Power
    0

    Default Re: Trying to get a compound interest program to work

    Quote Originally Posted by jim829 View Post
    You still haven't explained your problem clearly. But I suspect part of the problem is that you are not doing any calculations inside of your for loop. You just print out the same thing over and over again.

    Regards,
    Jim
    [QUOTE] That is part of the problem. What should my for loop look like with my calculation in it? Also I want my years to look like this Year 1: xxx.00, Year 2: xxx.00, Year 3... etc. If you deposit $100 for two years at 4 percent interest, at the end of one year, you will have $104. At the end of two years, you will have the $104 plus 4 percent of that, or $108.16. Write a program that accepts an account number, the account owner's first and last names, and a balance. Display the projected running total balance for each year for the next 20 years. Execute the program continuously for any number of customers until an appropriate sentinel value is entered.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Trying to get a compound interest program to work

    Well, you start with a balance of $100. Say balance.

    Java Code:
    balance = balance * 1.04; // now you have $104.
    balance = balance * 1.04; // now you have $108.16
    Which is basically what you said. So how do you apply this to your program?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Help Needed. New to Java Compound Interest Program....
    By SubjectJ80 in forum New To Java
    Replies: 7
    Last Post: 11-05-2011, 10:15 AM
  2. Calculating compound interest using ONLY integers.
    By AprilFlowers in forum New To Java
    Replies: 2
    Last Post: 10-21-2009, 07:47 AM
  3. Help with compound interest program pleaze
    By Smirre in forum New To Java
    Replies: 1
    Last Post: 01-19-2009, 10:31 PM
  4. How to use compound property names in Spring
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •