[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –

Java Programming Tutorial – 23 – Compound Interest Program
by
Tags:
Comments
41 responses to “Java Programming Tutorial – 23 – Compound Interest Program”
-
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.in);
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++) {
interestMeth.sum();}
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 () {
tempMonth++;
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);
}
} -
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…
-
Now its around 1.6M
-
this are you subs today 1.70626515758521888E17
-
After 10000 you have infinity
-
god damn this program wouldve been nice in math class last year
Bucky where were you:( -
Why is it day + " " + amount ?
-
principal
-
good video.
-
according to your equation, you should have 9.3921300068076464E16 subscribers by now….
-
now 1.6
-
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?
-
This is just math class.
-
damn u made this when u had 10k subs ..u have come a long way sir
-
I'm not a quitter but I'm a about to give up.
-
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.
-
You should have 230,491,190,344,953 subscribers today.
Program broken. Unsub. -
I am that half subscriber…
-
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.
-
So what is on line 8? What do they call that? is that a method or what?
I'm new to programming.
-
10000subs?? > 1.5m subs
-
these tutorials are awesome because bucky sucks at typing lol
-
You would teach in MIT better than they do
-
He made th8s when he had 10 k subs now he has over a million great job m8
-
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.
-
Every single tutorial bucky always starts it with sup guys
-
Holly Molly… more than a lot now JESUS
-
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(System.in);
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);
}}
} -
congrats on your million .
-
interesting!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
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 6freq[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.Thoughts?
-
you should have around 8 quadrillion subs now xD
-
Why do you add a 1+ after Math.pow?
-
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);}
}
-
Is there something wrong with video or youtube
-
You deserved that 1.4 million suscribers dude, thanks a lot! May God bless you
-
nearly 1.4M subscribers 🙂
-
I see Mr Bucky here is also very good at math
-
do you have examples i can practise on ?
-
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
-
>10000 subs
try 1.4 million
Leave a Reply