import java.util.Scanner;
import java.util.*;

public class Interest {

    public static void main(String[]args)
    {
        double
        interest,
        primary,
        period,
        amount,
        yearly,
        monthly,
        daily,
        weekly,
        quaterly,
        bianually,
        time;

    Scanner Scanner = new Scanner(System.in);

    System.out.println(" How much money is the person wanting to loan?");
           primary = Scanner.nextInt();

    System.out.println("Please enter the rate of interest.");
           interest = Scanner.nextInt();

    System.out.println("Over how many years will they pay the loan back?");
           time = Scanner.nextInt();

    System.out.println("Do you wish to have this amount compounded daily, weekly,");
    System.out.println("quaterly, bianually or yearly?");
        period = Scanner.nextInt();



    if
    (period == daily)
    amount = primary*Math.pow(1.0 + interest/365, time*365);

    if
    (period == weekly)
    amount = primary*Math.pow(1.0 + interest/52, time*52);

    if
    (period == quaterly)
    amount = primary*Math.pow(1.0 + interest/4, time*4);

    if
    (period == bianually)
    amount = primary*Math.pow(1.0 + interest/2, time*2);

    if
    (period == yearly)
    amount = primary*Math.pow(1.0 + interest, time);

    System.out.println("Your final amount is R" + amount);

    }
}




// Stuck, Please help

import java.util.Scanner;
import java.util.*;

public class Interest {

    public static void main(String[]args)
    {
        double
        interest,
        primary,
        period,
        amount,
        yearly,
        monthly,
        daily,
        weekly,
        quaterly,
        bianually,
        time;

    Scanner Scanner = new Scanner(System.in);

    System.out.println(" How much money is the person wanting to loan?");
           primary = Scanner.nextInt();

    System.out.println("Please enter the rate of interest.");
           interest = Scanner.nextInt();

    System.out.println("Over how many years will they pay the loan back?");
           time = Scanner.nextInt();

    System.out.println("Do you wish to have this amount compounded daily, weekly,");
    System.out.println("quaterly, bianually or yearly?");
        period = Scanner.nextInt();



    if
    (period == daily)
    amount = primary*Math.pow(1.0 + interest/365, time*365);

    if
    (period == weekly)
    amount = primary*Math.pow(1.0 + interest/52, time*52);

    if
    (period == quaterly)
    amount = primary*Math.pow(1.0 + interest/4, time*4);

    if
    (period == bianually)
    amount = primary*Math.pow(1.0 + interest/2, time*2);

    if
    (period == yearly)
    amount = primary*Math.pow(1.0 + interest, time);

    System.out.println("Your final amount is R" + amount);

    }
}

Recommended Answers

All 3 Replies

"won't work" tells us nothing. Next time post the complete text of your error messages.
Anyway, your variables daily,weekly,quaterly,bianually,yearly are not initialised.

There are a few things wrong with the program.

(Apart from the variables not being initiated)
(1)
line 34: period = Scanner.nextInt();

The scanner expects an integer value. It isn't clear whether you want input to be a String or an integer. If you need the user to enter "daily", then variable period should be a String. In which case line 34 should look like this:

period = Scanner.next();

(2)
Don't use "Scanner", rather change it to "console" or "sc" to avoid confusion:

line 21: Scanner console = new Scanner(System.in);

(3)
Your interest value is going to get entered as a whole number. This is normally a percent, so for example; 7 % should be 0.07 for the calculation.

See if you can find the other mistakes yourself and come back ;-)

  1. Your variables are not initialized.

  2. And even if you think you did, with "double", you used them like "Integers"

    primary = Scanner.nextInt();

And also, you shoud try another name instead of Scanner to avoid confusion.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.