Topics Discussed: Using java to compute simple calculations, such as bank interest.

Source Code Available Here

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.

Compound operations
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.

  1. double principle = input.nextDouble();
  2. 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.

  3. rate /= 100;
  4. 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;”

  5. System.out.println("\nThe total amount of money in the account after: " + Time + " years is: " + (principle * (1+rate*Time)));
  6. 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.

Difficulty: Easy
Time to solve: <5 min
Video this is covered in: 2

import java.util.Scanner;
public class Jtutorial1 {
    public static void main(String args[]){
    Scanner input = new Scanner(;
    double a=0, b=1, c=2, d=3;
    System.out.println("Enter a value for E: ");
    double e= input.nextDouble();
    System.out.println("Enter a value for F: ");
    double f;
    }//end main
}//end class


Error information:Exception in thread “main” java.lang.RuntimeException: Uncompilable source code – variable f might not have been initialized
at Jtutorial1.main(