0

I just need help to display my initial value of 25000 when the loop runs and print the years. I need the year 1 to be the initial value without doing the percent first. Also my print format doesnot display the $ and the headers. Any guide to the right direction will helpful.
Thank you.

import java.util.Scanner;

public class EmployeeSalary
{
    public static void main(String[] args) // main method
    {
        final double rate = 5; // 5% raise
        final double initial_balance = 25000; // initial salary
        double balance = initial_balance;

        System.out.print("Enter number of years: "); // employee input
        Scanner in = new Scanner(System.in);
        int nyears = in.nextInt();

        // do the looping
        for (int year = 1; year <= nyears; year++)
        {
            // do the math
            double interest = balance * rate / 100;
            balance = balance + interest;
            // print the result
            System.out.format("%4d %10.2f%n", year, balance);
        }
    }
}
2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by toldav
0

Also my print format doesnot display the $ and the headers.

Take a look at the DecimalFormat class.

I need the year 1 to be the initial value without doing the percent first

Print out the balance before adding the interest to it.

Are you required to use loops?

Edited by mvmalderen

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.