Topics Discussed: Using java to compute simple calculations, such as bank interest.
Homework: Write a ‘financial goal’ calculator, this calculator can take in a variety of inputs so long as it provides the unknown inputs via equation / logic. Example: allow input for Time invested / rate / how much money you want in the end — determine starting amount of money. Or Starting money, rate, and goal money, determine how long it would take. Etc. If you need help with this formula, or with posting your code to ideone, please let me know.
A compound operation is any time where we’re doing in one statement what might have otherwise taken more than one operation to state. There are actually 3 operations in this lesson that I would consider to be compound operations for varying reasons, lets take a look at each of them.
double principle = input.nextDouble();
- rate /= 100;
System.out.println("\nThe total amount of money in the account after: " + Time + " years is: " + (principle * (1+rate*Time)));
The reason that I consider this to be a compound operation is because it would be more basic to have this as two statements, stated something like this:
double principle; principle = input.nextDouble();
But as you can see, we are able to declare this in one statement.
The reason this is a compound operator is because of the special /= arithmetic operator. There are actually a few of those as follows:
+=, -=, /=, *=,
All of these are handled in the same way. When you append them to a variable they have this basic syntax: “variable =variable(operation) number;”
The reason why this is a compound operation should be pretty apparent. Rather than using a variable named “total” to store the total amount of money, we’re actually computing it using math in the println statement.