Java Programming Tutorial – 23 – Compound Interest Program

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






41 responses to “Java Programming Tutorial – 23 – Compound Interest Program”

  1. Toxic Avatar

    Paused the video at 50 seconds in after i had an idea of what the tutorial would consist of and gave it a crack without watching it; my math formulas are awful but ill work on that:


    import java.util.Scanner;

    public class Main {
    public static void main (String args []) {
    double totalCash, monthlyInterest, saveMonthly;
    int months;

    Scanner userInput = new Scanner (;

    System.out.println("Welcome to the Compound interest calculator");
    System.out.println("Please enter how much money you have to start with (GBP £): ");
    totalCash = userInput.nextDouble();
    System.out.println("Please enter how much money you will save per month (GBP £): ");
    saveMonthly = userInput.nextDouble();
    System.out.println("How many months do you wish to save for? ");
    months = userInput.nextInt();
    System.out.println("What is the interest gained each month (in percentage)");
    monthlyInterest = userInput.nextDouble();

    SecondClass interestMeth = new SecondClass();
    interestMeth.setValues(totalCash, saveMonthly, monthlyInterest);

    for (int i =1; i<=months;i++) {


    System.out.println("After " + months + " months of saving you have: " + interestMeth.getValue());
    System.out.println("You saved £" + saveMonthly + "GBP per month with " + monthlyInterest +"% added monthly interest");




    public class SecondClass {
    public double total2;
    private double saveMonthly2, totalCash2, monthlyInterest2;
    private int tempMonth = 0;

    public void setValues (double totalCash, double saveMonthly, double monthlyInterest) {
    totalCash2 = totalCash;
    monthlyInterest2 = monthlyInterest;
    saveMonthly2 = saveMonthly;

    public double getValue() {
    total2 = totalCash2;
    return total2;

    public void sum () {
    totalCash2 = saveMonthly2+totalCash2;
    double temp = totalCash2/100;
    double interestValue = temp * monthlyInterest2;
    totalCash2 = totalCash2+interestValue;
    System.out.println("Total saved including interest at end of month " + tempMonth+ ":");
    System.out.println( "£" + totalCash2);

  2. staffy35 Avatar

    His tutorials are good but you have to wonder if he questions his sanity when he programs classes under the names apples and tuna. Especially when he makes variables representing his old girlfriends…

  3. AJay Gupta Avatar

    Now its around 1.6M

  4. Just Roy Avatar

    this are you subs today 1.70626515758521888E17

  5. Power Vacum Avatar

    After 10000 you have infinity

  6. theo brucker Avatar

    god damn this program wouldve been nice in math class last year
    Bucky where were you:(

  7. ganesh edwat Avatar

    Why is it day + " " + amount ?

  8. David Foss Avatar

    according to your equation, you should have 9.3921300068076464E16 subscribers by now….

  9. victoria agyin Avatar

    Soo I've been writing all of this stuff down in a notebook. I have a Google Chromebook and I'm not sure what to use to code on this thing. Help anyone?

  10. MendrixMC Avatar

    This is just math class.

  11. Anil Neupane Avatar

    damn u made this when u had 10k subs ..u have come a long way sir

  12. Carlos Padilla Avatar

    I'm not a quitter but I'm a about to give up.

  13. Mark Bono Avatar

    I am absolutely a fan of the site. For fun I ran the one percent growth for the 2685 days – excluding leap years -since you posted the video and you should have 4 quintillion and some change. That said 1.6 million is a well deserved set of followers. Looking forward to your other playlists.

  14. Michael OLear Avatar

    You should have 230,491,190,344,953 subscribers today.
    Program broken. Unsub.

  15. Zzzzzz... Avatar

    I am that half subscriber…

  16. Stalin Avatar

    Compound interest in terms of price to CPI inflation is given a simple equation, being P2 = (P1 + R)^A-B (target years, increased price between them, and P2 = future price, P1 = present price) or (P1 * (R+100%))^A-B, but A=P(1+R)^n still applies, where R = inflation rate.

  17. Fight Reacts Avatar

    So what is on line 8? What do they call that? is that a method or what?

    I'm new to programming.

  18. Clash with A Square Avatar

    10000subs?? > 1.5m subs

  19. ColesContent Avatar

    these tutorials are awesome because bucky sucks at typing lol

  20. DiamondCrafter Avatar

    You would teach in MIT better than they do

  21. Samyak Singh Avatar

    He made th8s when he had 10 k subs now he has over a million great job m8

  22. DLZ Avatar

    Lol you taught us using variables defined on fewer lines at the start of the playlist and I realise you don't even do it LOL

    But I'm following along to the Java easier than I thought, I hope I understand it all at the end of this. I do a few a day.

  23. AmazingCraft0210 Avatar

    Every single tutorial bucky always starts it with sup guys

  24. andrew lost Avatar

    Holly Molly… more than a lot now JESUS

  25. RumikXxeno Avatar

    I figured out bit different attitude to this (I'll always try to figure out it myself and then watch solution by Bucky). And here it is! Hope, you'll enjoy that!!

    import java.util.Scanner;

    public class blabla {
    public static void main(String args[]){
    Scanner input = new Scanner(;
    int counter, numberOfDays;
    double subscribers = 10000;

    System.out.println("Enter number of days for this calculation: ");
    numberOfDays = input.nextInt();
    for(counter = 1; counter <= numberOfDays; counter++){
    subscribers += subscribers * 0.01;
    System.out.printf("You'll have %.2f subscribers after %d days.n", subscribers, counter);


  26. xanny boi Avatar

    congrats on your million .

  27. Abdul Maajith Avatar


  28. RJ Aki Avatar

    Lemme break down my analogy for freq++[1+ rand.nextInt(6)];

    It simply increments the array position specified by 1.

    [1+ rand.nextInt(6)];
    This code is simply selecting a number between 1 – 6. Normally it will select a number between 0 – 5 because computers always start counting from 0, so by adding one to this range, each number selected in 0 – 5 will be +1, so essentially the range is 1 -6.
    0 +1 1
    1 +1 2
    2 +1 3
    3 +1 4
    4 +1 5
    5 +1 6

    freq[1+ rand.nextInt(6)];
    This code now is simply selecting a random number in the range 1-6 (as specified in brackets) so if number was 2, it would be freq[2]; <- This is basically position 3 in the array, again because computers count starts from 0. So essentially this code is selecting the array position.

    ++freq[1+ rand.nextInt(6)];
    The code now adds one to the array position specified by the brackets. So we have freq[2] from earlier but now because of the ++ the value of freq[2[ becomes 1 e.g. freq[2] =1;

    Note: ++freq is adding one to the array position specified by the code freq[1+ rand.nextInt(6)];
    For this reason freq[1+ rand.nextInt(6)]++; should work also.


  29. Kami Avatar

    you should have around 8 quadrillion subs now xD

  30. Deven Grovenstein Avatar

    Why do you add a 1+ after Math.pow?

  31. Manu Anand Avatar

    ERROR: "day cannot be resolved to a variable."

    Also, aren't we supposed to use mathematical operators such as +, – etc. for the variables of the same type.

    The line which is giving this error has an "int" variable added to a "double" variable type.

    Please help!

    Source code:

    public class compoundInterest {

    public static void main(String[] args) {

    double amount;
    double principle = 10000;
    double rate = .01;

    for (int day=1; day<=20; day++)

    amount = principle*Math.pow(1 + rate, day);

    //Eclipse gives the error for the following line:
    System.out.println(day + " " + amount);



  32. N.A ClaSHer yt Avatar

    Is there something wrong with video or youtube

  33. Syazwan Razak Avatar

    You deserved that 1.4 million suscribers dude, thanks a lot! May God bless you

  34. RatedRR _Chelsea Avatar

    nearly 1.4M subscribers 🙂

  35. Donald.V Thomas Avatar

    I see Mr Bucky here is also very good at math

  36. Noura As Avatar

    do you have examples i can practise on ?

  37. TheMinecrafter52 Avatar

    did some math. According to his formula he should have 6.397247808284771 * 10^15 subscribers as of today. (Which is a couple quadrillion more that the 1.3 million he has now) XD

  38. newmagicfilms Avatar

    >10000 subs

    try 1.4 million

Leave a Reply

Your email address will not be published. Required fields are marked *