need help in JAVA

Started by
8 comments, last by Trihex 14 years, 6 months ago
i have the code for this program in java which i cant get it to do the calculations:
// 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();

    }

}
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
l jsym l
Advertisement
You need to import java.Math.
alright i'll give it a try. for some reason i thought that the class math was within "java.lang.*"
l jsym l
alright i'll give it a try. for some reason i thought that the class math was within "java.lang.*"
l jsym l
yah the same error message still shows up
l jsym l
Is that all the error message says?

Try importing java.lang.Math.*;
"All you have to decide is what to do with the time that is given to you." - Gandalf
yeah. still the same error message. I have no idea what i could be doing wrong
l jsym l
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:

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.
Eric ArmstrongTrihex Softwarewww.trihex.com

This topic is closed to new replies.

Advertisement