// This Java Program computes the amount
// of a certificate of deposit on maturity.
/******************************************
*******************************************/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class Maturity extends JFrame
{
private CalculateButtonHandler cbHandler;
private ExitButtonHandler ebHandler;
private static final int WIDTH = 600;
private static final int HEIGHT = 400;
// put JTextField reference variables here
private JLabel amountDepositedL, durationInYearsL, interestRateL, valueOnMaturityL;
private JTextField amountDepositedTF, durationInYearsTF, interestRateTF, valueOnMaturityTF;
private JButton calculateB, exitB;
public Maturity()
{
// Create labels
amountDepositedL= new JLabel( "Enter the amount deposited: ",
SwingConstants.RIGHT);
durationInYearsL= new JLabel( "Enter the duration in years: ",
SwingConstants.RIGHT);
interestRateL= new JLabel( "Enter the interest rate: ",
SwingConstants.RIGHT);
valueOnMaturityL= new JLabel( "Enter the value on maturity: ",
SwingConstants.RIGHT);
//Create textfields
amountDepositedTF = new JTextField(10);
durationInYearsTF = new JTextField(10);
interestRateTF = new JTextField(10);
valueOnMaturityTF = new JTextField(10);
//create Calculate Button
calculateB = new JButton("Calculate");
cbHandler = new CalculateButtonHandler();
calculateB.addActionListener(ebHandler);
//Create Exit Button
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
//Set the title of the window
setTitle("Certificate of Deposit Maturity");
//Get the container
Container pane = getContentPane();
//Set the layout
pane.setLayout(new GridLayout(5, 2));
//Place the components in the pane
pane.add(amountDepositedL);
pane.add(amountDepositedTF);
pane.add(durationInYearsL);
pane.add(durationInYearsTF);
pane.add(interestRateL);
pane.add(interestRateTF);
pane.add(valueOnMaturityL);
pane.add(valueOnMaturityTF);
pane.add(calculateB);
pane.add(exitB);
//set the size of the window and display it
setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class CalculateButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent e)
{
double amountDeposited, durationInYears, interestRate, valueInMaturity, temp;
amountDeposited = Double.parseDouble(amountDepositedTF.getText());
valueInMaturity = Math.pow(amountDeposited(1 + interestRate/100), durationInYears);
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed( ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
Maturity secConvert = new Maturity();
}
}
need help in JAVA
i have the code for this program in java which i cant get it to do the calculations:
when i do this it gives me the error
location: class Maturity.CalculateButtonHandler
valueInMaturity = Math.pow(amountDeposited(1 + interestRate/100), durationInYears);
^
1 error
and im not for sure how to fix it....if anyone knows please please post back
thanks
alright i'll give it a try. for some reason i thought that the class math was within "java.lang.*"
alright i'll give it a try. for some reason i thought that the class math was within "java.lang.*"
You haven't included the error description, only where it is located. There should be an error description, such as at least a number, or "syntax error", "class not found", or similar.
You write amountDeposited(1 + interestRate/100), which makes the compiler think you are calling a function amountDeposited, and the error description should be 'cant find method amountDeposited' or similar. I assume you mean amountDeposited * (1 + interestRate/100). In addition, you don't initialize interestRate or durationInYears, so you will get warnings on that after fixing the error.
The problem is you are accessing amountDeposited like its a method call. Take a look at the line again:
My guess is you want to multiply the amountDeposited variable by 1 plus the interest rate divided by 100. You are missing the * before the parentheses. You are most likely getting an error that it can't find the method amountDeposited.
valueInMaturity = Math.pow(amountDeposited(1 + interestRate/100), durationInYears);
My guess is you want to multiply the amountDeposited variable by 1 plus the interest rate divided by 100. You are missing the * before the parentheses. You are most likely getting an error that it can't find the method amountDeposited.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement