Quiz for investment calculation - Java Language Basics

Java examples for Language Basics:float

Introduction

Create a program that calculates

  • how much a $14,000 investment would be worth if it increased in value by 40% during the first year,
  • lost $1,500 in value the second year, and
  • increased 12% in the third year.

Demo Code


public class Main {
    public static void main(String[] arguments) {
        float total = 14000;
        System.out.println("Original investment: $" + total);
        // Inceases by 40 percent the first year
        total = total + (total * .4F);//from  w w  w.  ja  v  a 2 s.c  o  m
        System.out.println("After one year: $" + total);
        // Loses $1,500 the second year
        total = total - 1500F;
        System.out.println("After two years: $" + total);
        // Increases by 12 percent the third year
        total = total + (total * .12F);
        System.out.println("After three years: $" + total);
    }
}

Result


Related Tutorials