calculate interest from text file with Java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foleyflint
    New Member
    • Oct 2006
    • 9

    calculate interest from text file with Java

    Hello, I'm trying to calculate the interest from a bankaccount which is displayed in a text file as followed:
    9 2 345
    3 3 300
    etc. (there are 19 lines in total)

    the first number of each line means a day, the second stands for the month and the last for the amount of money on the account.
    so the first line is Februari 9th with an amount of 345.
    I want to make the program read the textfile with a Scanner. Then it should calculate for every time the balance chages the interest of 3% per year. That means we get the formula: (n/365)*(3/100) There are 365 days in a year, the months have their usual days: 31, 28, 31, 30, 31 etc.
    Last, I want to print every period with it's interest and on the last line the total interest earned in that year?
    I'm just a beginning programmer and would like to use arrays to solve this problem, but I don't have the experience with it to just put it in BlueJ. Actually I have no idea hwo to do that. How to make the Scanner object, how to let the program read the number: int, double?? how to calculate the interest! that's a drama for me, because I have no idea how to set this up.
    So if someone could help me... Thank you.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by foleyflint
    Hello, I'm trying to calculate the interest from a bankaccount which is displayed in a text file as followed:
    9 2 345
    3 3 300
    etc. (there are 19 lines in total)

    the first number of each line means a day, the second stands for the month and the last for the amount of money on the account.
    so the first line is Februari 9th with an amount of 345.
    I want to make the program read the textfile with a Scanner. Then it should calculate for every time the balance chages the interest of 3% per year. That means we get the formula: (n/365)*(3/100) There are 365 days in a year, the months have their usual days: 31, 28, 31, 30, 31 etc.
    Last, I want to print every period with it's interest and on the last line the total interest earned in that year?
    I'm just a beginning programmer and would like to use arrays to solve this problem, but I don't have the experience with it to just put it in BlueJ. Actually I have no idea hwo to do that. How to make the Scanner object, how to let the program read the number: int, double?? how to calculate the interest! that's a drama for me, because I have no idea how to set this up.
    So if someone could help me... Thank you.
    There is no point in giving you code to do all of this since you said you are new to programming. I'd suggest you look around for how to use the scanner first. Once you've had a good look at it and some examples of how to use it, you may actually be able to complete this without further help

    Comment

    • foleyflint
      New Member
      • Oct 2006
      • 9

      #3
      I know how to use the Scanner. THis is my code:
      Code:
      try 
              {
              String file = "saldo_overzicht.txt";
              Scanner input = new Scanner(new FileReader (file)); 
      
              int value = 0;
              value = input.nextInt();  /** Read first number from each line: day of month */
          
              while(data_days[countdays] != 31 && data_months[countmonths] != 12)
                  {
                      data_days[countdays] = value;  /** Store day in data_days Array  */
                      countdays ++;
                  
                      value = input.nextInt();            /** Read second number from each line: month */
                      data_months[countmonths] = value;   /** Store month in data_months Array  */
                      countmonths ++;
              
                      value = input.nextInt();            /** Read third number from each line: balance */
                      data_amount[countamount] = value;   /** Store amount in date_amount Array  */
                      countamount ++;
              
                      value = input.nextInt();            /** Read first number from each line. */
                  }
              } 
              catch (Exception e) { }
      I also created the arrays needed to store the numbers read.
      I would like to know how to solve the other problem: calculate interest with months of 31, 28, 31, 30, 31 days etc...

      Comment

      Working...