Investment Calculator

I need to build a Investment Calculator with a driver. So far it will print out the initial deposit , rate and years. It will not return the values over a ten year period. I would appreciate any help. Here is the Invest Code:

import java.lang.Math;

/**

* Write a description of class InvestmentCalculator here.

*

* @author (your name)

* @version (a version number or a date)

*/

public class InvestmentCalculator

{

// instance variables - replace the example below with your own

/**

* Constructor for objects of class InvestmentCalculator.

*/

public InvestmentCalculator()

{

}

public class value

{

InvestmentCalculator value = new InvestmentCalculator.InvestmentCalculator ();

}

public value Math (double value)

{

value = InitialDeposit * (1+rate)^10;

return value = 0.0;

}

/**

* An example of a method - replace this comment with your own.

*

* @param ya sample parameter for a method

* @returnthe sum of x and y

*/

public InvestmentCalculator(double aInitialDeposit, int numberOfyears)

{

InitialDeposit = aInitialDeposit;

years = 0;

}

public InvestmentCalculator(float aRate)

{

rate = aRate;

}

public int hasMoreYears( int years)

{

return years;

}

public int advanceToNextYear()

{

return year;

}

public double getBalance()

{

return balance;

}

public void waitForBalance(double targetBalance)

{

while (balance < targetBalance)

{

years ++;

float arate = balance * rate/100;

balance = balance + rate;

}

}

private int year;

private int InitialDeposit;

private float InterestRate;

private int years;

private float balance;

private int rate;

}

Here is the Driver Code:

import java.util.Scanner;

/**

* Write a description of class InvestmentCalculatorDriver here.

*

* @author (your name)

* @version (a version number or a date)

*/

public class InvestmentCalculatorDriver

{

// instance variables - replace the example below with your own

/**

* Constructor for objects of class InvestmentCalculatorDriver.

*/

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

InvestmentCalculator calculator = new InvestmentCalculator();

System.out.print("Enter initial deposit: ");

double aInitialDeposit = in.nextDouble();

System.out.print("Enter Interest rate: ");

float aInterestRate = in.nextFloat();

System.out.print("Enter number of years: ");

int numberOfyears = in.nextInt();

}

}

[2899 byte] By [Gema] at [2007-10-3 8:09:59]
# 1

No, this is wrong, wrong, wrong.

A class named "value"? What are you thinking with that?

This line of code might compile, but it's not doing what you think it's doing:

value = InitialDeposit * (1+rate)^10;

That circumflex is not a power operator; it's doing a bitwise exclusive OR:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html

You want it to look like this:

double n = 10.0;

double value = initialDeposit*Math.pow(1.0+rate, n);

Hardwiring "10"? That's foolish.

You should learn and follow Sun's coding conventions for Java:

http://java.sun.com/docs/codeconv/

%

duffymoa at 2007-7-15 3:14:18 > top of Java-index,Java Essentials,Java Programming...
# 2
Even if you have written this properly, it's not a useful class. You only have a main method. How will another class call your calculator like that?You're writing in a procedural fashion, not object-oriented. Java's not C or FORTRAN.%
duffymoa at 2007-7-15 3:14:18 > top of Java-index,Java Essentials,Java Programming...