Question

In: Computer Science

/* my calculator is messed up. I need to display interest rate + initial investment. I...

/* my calculator is messed up. I need to display interest rate + initial investment. I keep getting huge numbers, 
Just need to fix my calculator thats all.


import java.util.Scanner;//Import java scanner class
public class InterestCalculator1 {
    //create fields / variables
    private double initialInvestment;
    private double annualInterestRate;
    private double numberOfYears;
    private double investmentReturn;
    private double finalAmount;
    Scanner input = new Scanner(System.in);//create new scanner object

    //constructor
    public InterestCalculator1(double initialInvestment, double annualInterestRate, double numberOfYears){
        super();
        this.initialInvestment = initialInvestment;
        this.annualInterestRate = annualInterestRate;
        this.numberOfYears = numberOfYears;
       // this.finalAmount = finalAmount;
    }
    //setters and getters
    public double getInitialInvestment() {
        return initialInvestment;
    }
    public void setInitialInvestment(double initialInvestment) {
        this.initialInvestment = initialInvestment;
    }
    public double getAnnualInterestRate() {
        return annualInterestRate;
    }
    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
    public double getNumberOfYears() {
        return numberOfYears;
    }
    public void setNumberOfYears(double numberOfYears) {
        this.numberOfYears = numberOfYears;

    }//end setters and getters


    //begin userPrompt method
    public void promptUser() {
        System.out.println("Enter initial investment amount: ");//prompt user for initial investment amount
        setInitialInvestment(input.nextDouble());//sets initial investment
        System.out.println("Enter monthly interest rate: ");//prompt user for monthly interest rate
        setAnnualInterestRate(input.nextDouble() * 0.01);//converts input double into a decimal percentage rate and sets to annualInterestRate
        System.out.println("Enter number of years you are planing to leave initial investment in account: "); //prompt user for number of years planing to leave initial investment in account
        setNumberOfYears(input.nextDouble());//sets number of years planning on leaving investment in account
    }//ends prompt user method

    //begin investment calculator method
    public void investmentCalculator() {
        investmentReturn = getInitialInvestment() * Math.pow(1 + getAnnualInterestRate(), getNumberOfYears() * 12);//calculates investment return
        finalAmount = investmentReturn + getInitialInvestment();//final amount equal investment return + initial amount
    }//ends investment calculator method
    //begin toString


    @Override
    public String toString() {
        return
                "With an initial investment of: $" + getInitialInvestment() + "\n" +
                "at a monthly interest rate of: %" + getAnnualInterestRate() + "\n" +
                "Left in the account for: " + getNumberOfYears() + " years " + "\n" +
                "Will provide a return of: $" + String.format("%.02f", investmentReturn )+ "\n" +
                "and your final amount of: $" + getInitialInvestment() +  " plus $" + String.format("%.02f",investmentReturn) + "\n" +
                "Equals: $" + String.format("%.02f", finalAmount);
    }
}

Solutions

Expert Solution

NOTE:-- If you are stuck somehwere feel free to ask in the comments but do not give negative rating to the question as it affects my answering rights...i will try to help you

Note:->>Check The formula that you provided in the calculateInterest function..if it is fine than i guess the following output is correct...Also when you are using getters and setters to set the data using the prompt function then no need of parametrized constructor...it is just adding of unnecessary code to the program.....the other things are kept almost the same

import java.util.Scanner;//Import java scanner class
import java.io.*;
public class InterestCalculator1 {
    //create fields / variables
    private double initialInvestment;
    private double annualInterestRate;
    private double numberOfYears;
    private double investmentReturn;
    private double finalAmount;
    Scanner input = new Scanner(System.in);//create new scanner object

    //setters and getters
    public double getInitialInvestment() {
        return initialInvestment;
    }
    public void setInitialInvestment(double initialInvestment) {
        this.initialInvestment = initialInvestment;
    }
    public double getAnnualInterestRate() {
        return annualInterestRate;
    }
    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
    public double getNumberOfYears() {
        return numberOfYears;
    }
    public void setNumberOfYears(double numberOfYears) {
        this.numberOfYears = numberOfYears;

    }//end setters and getters


    //begin userPrompt method
    public void promptUser() {
        System.out.println("Enter initial investment amount: ");//prompt user for initial investment amount
        this.setInitialInvestment(input.nextDouble());//sets initial investment
        System.out.println("Enter monthly interest rate: ");//prompt user for monthly interest rate
        this.setAnnualInterestRate(input.nextDouble() * 0.01);//converts input double into a decimal percentage rate and sets to annualInterestRate
        System.out.println("Enter number of years you are planing to leave initial investment in account: "); //prompt user for number of years planing to leave initial investment in account
        this.setNumberOfYears(input.nextDouble());//sets number of years planning on leaving investment in account
    }//ends prompt user method

    //begin investment calculator method
    public void investmentCalculator() {
        investmentReturn = getInitialInvestment() * Math.pow(1 + getAnnualInterestRate(), getNumberOfYears() * 12);//calculates investment return
        finalAmount = investmentReturn + getInitialInvestment();//final amount equal investment return + initial amount
    }//ends investment calculator method
    //begin toString


    @Override
    public String toString() {
        return
                "With an initial investment of: $" + getInitialInvestment() + "\n" +
                "at a monthly interest rate of: %" + getAnnualInterestRate() + "\n" +
                "Left in the account for: " + getNumberOfYears() + " years " + "\n" +
                "Will provide a return of: $" + String.format("%.02f", investmentReturn )+ "\n" +
                "and your final amount of: $" + getInitialInvestment() +  " plus $" + String.format("%.02f",investmentReturn) + "\n" +
                "Equals: $" + String.format("%.02f", finalAmount);
    }
    public static void main(String []args)throws IOException{
        InterestCalculator1 obj = new InterestCalculator1();
        obj.promptUser();
        obj.investmentCalculator();
        System.out.println(obj);
    }
}

Output-->

  ->


Related Solutions

An investment with an initial deposit of $12,993 is growing at an interest rate of 3.22%...
An investment with an initial deposit of $12,993 is growing at an interest rate of 3.22% compounded quarterly. Round all answers to two decimal places if necessary. 1. Find the accumulated amount of the investment at the end of 3 years. 2. The interest rate changes to 4.85% compounded monthly after the first 3 years. Calculate the accumulated amount in this investment at the end of year 6. 3. Find the total amount of interest accumulated during the entire 6...
An investment with an initial deposit of $7,474 is growing at an interest rate of 3.91%...
An investment with an initial deposit of $7,474 is growing at an interest rate of 3.91% compounded monthly. Round all answers to two decimal places where necessary. 1. Find the accumulated amount of the investment at the end of 3 years. P/Y = C/Y =    N =    I/Y = % PV = $   PMT = $   FV = $ 2. At the end of the 3 years, the interest rate changes to 8.52% compounded semi-annually. Calculate the accumulated amount in...
The internal rate of return represents the rate of interest that recovers the initial investment outlay....
The internal rate of return represents the rate of interest that recovers the initial investment outlay. Discuss the validity of this statement. paragraph answer:
I need an initial template or introductory paragraph for my I-Care essay in Nursing. Its components...
I need an initial template or introductory paragraph for my I-Care essay in Nursing. Its components or nursing action that contributes to compassion, advocacy, resilience and Evidence Based Practice. Thank you. Subject: Nursing Capstone
A company will invest with an initial investment of $1,000,000. Assuming a market interest rate of...
A company will invest with an initial investment of $1,000,000. Assuming a market interest rate of 5% and cash flow for 5 years is expected in the table below: Year Cash Flow 1 425,000 2 384,000 3 321,500 4 282,500 5 200,000 Calculate the PAYBACK PERIOD and NPV!
Identify a profitable project using initial investment up to $ 50,000. The discount rate must be...
Identify a profitable project using initial investment up to $ 50,000. The discount rate must be bonds. In an excel evaluate the project with VPN, IRR, recovery period, and rate of return. justify the numbers they occupied, the conclusions of the metrics studied in the excel and the reasons why they consider the project as a good option.
I'm using my TI-84 plus calculator trying to figure out the critical value(s). All I need...
I'm using my TI-84 plus calculator trying to figure out the critical value(s). All I need to know is how to do the problem on the calculator. I have tried everything. I did (area/2 and Df= 99) that was wrong) then I tried (1-area and Df= 99) that was wrong to) I tried it other ways and can't seem to get it down. I just need somebody to explain it to me step by step on how they got it....
I need solutions for these practices questions True/False If the interest rate (or discount rate) is...
I need solutions for these practices questions True/False If the interest rate (or discount rate) is positive, the future value of an expected series of payment will always exceed the present value of the same series. If semiannual compounding is used, the effective annual interest rate (EAI) is equal to the nominal annual rate. You are able to buy a stock at $14 where as its intrinsic value (or fair value) is $14.01. You have indeed bought this stock at...
I need this reviewed, reworded and shorten please?! Reading the letter above my initial response would...
I need this reviewed, reworded and shorten please?! Reading the letter above my initial response would be that the language and attitude shown in the letter is very rude and impolite. It focuses more on blaming the customer for the damage than providing with any materialistic solution. Customer satisfaction might drop after receiving such a response from the dealer for her claim. The negative review about the company can spread adversely by word of mouth and diminish the company's image....
Interest rate on an investment
Ken Francis is offered the possibility of investing $2,745 today; in return, he would receive $10,000 after 15 years. What is the annual rate of interest for this investment? (PV of $1, FV of $1, PVA of $1, and FVA of $1) (Use appropriate factor(s) from the tables provided. Round your "PV of a single amount" to 4 decimal places and percentage answer to the nearest whole number.)Present Value/Future Value=p (PV of a Single Amount)Interest Rate/
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT