Solved

urgent! investment calculation with GUI interface.........

Posted on 2004-10-12
9
488 Views
Last Modified: 2012-08-13
Urgent help needed!
I am having trouble with this project.
The java program requires a created GUI that calculates for an annual rate of return on an investment.  
The specific specs are:
 
I.  By using a GUI:
    Collect user Inputs:
     1. interests rates
     2. initial principle
     3. number of years to stay in fund

II. On the GUI, click evaluate.
    Output should display a table whose columns contain:
     1. year number
     2. principle at the beginning of the year
     3. interests earned
     4. principle at the end of the year

III.Calculate for a given number of years and compound annually for an end result.

I think that once the code is executed, a GUI should appear and have three labels and three text fields that will satisfy the input requirements. The user will click the <<<evaluate>>> button for the compounded annually calculation to occur.

Once the calculation occurs, it should display the results in a GUI (table?) that shows the four output requirements.

Here is my code.

import javax.swing.*;
import Breezy.Swing.*;

public class Mutualfund3 extends GBFrame{
          //variables declared for windows object

          JLabel  principleLabel;
          JLabel  interestsLabel;
          JLabel  investyearsLabel;

          DoubleField interestrateField;
          DoubleField principleField;
          DoubleField yearEndField;
          DoubleField investYearsField;
          JButton calculateButton;
          }

          //constructor
     public Mutualfund3 (){
               //instantiate and  add window objects to the window.

               principleLabel = addlabel ("Principle amount"    ,1,1,1,1);
               interestsLabel = addlabel ("Interests Rate"     ,1,2,1,1);
               investyearsLabel = addlabel ("Years Invested"    ,1,3,1,1);

               principleField = addDoubleField (0,             2,1,1,1);
               interestsField = addDoubleField (0,             2,2,1,1);
               investyearsField = addDoubleField (0,           2,3,1,1);

               calculateButton = addButton ("<<<<Evaluate>>>>",3,1,1,1);
          }

          // respond to button click events
     public void buttonClicked (JButton buttonObj){
          //local variables
               Evaluate eval = new Evaluate();


          }


          // execution begins in the method main as usual.

     public static void main (String[] args) {

               Mutualfund3 theGUI = new Mutualfund3();
               theGUI.setSize (300,150);                //width = 300, height = 150 in pixels
               theGUI.setVisible (true);               //window is visible

          }



I'm having trouble with creating an output GUI format for the requirements as well as calculation help.
Any advice would be appreciated.
thanks, lauren
0
Comment
Question by:Brayn66
  • 6
  • 3
9 Comments
 
LVL 6

Expert Comment

by:expertmb
ID: 12294368
0
 

Author Comment

by:Brayn66
ID: 12294457
Thank you for replying.
I have previously studied those sites but my concern is that  I am using breezySwing for:
1. responding to user events.                                
2. for all the methods for adding window objects to the ui.

I have not been able to apply the information from those sites to my situation because of the differences in Java Swing and Breezy Swing (which I have to use). Is this an issue or am I confused?

I feel like I am missing something simple but important.

Does my code look possible?
I appreciate your help, lauren

0
 
LVL 6

Expert Comment

by:expertmb
ID: 12294639
i dont know about breezy swing, sorry :(
this could help you
http://faculty.cs.wwu.edu/martin/Software%20Packages/BreezySwing/Default.htm
0
 

Author Comment

by:Brayn66
ID: 12294790
Thanks, I'll look over it. lauren
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Brayn66
ID: 12303744
Thanks, it made sense.

I have come a long way since then (i think). :o)
Please look over my code and see if you see the two compile error issues (which are listed after the source code).
my most recent source code is as follows:

import javax.swing.*;
import BreezySwing.*;

  public class Mutualfund6 extends GBFrame{

              // variables for window objects

      private Label         initialprincipleLabel;
      private DoubleField   initialprincipleField;
      private Label              interestRateLabel;
      private IntegerField  interestRateField;
      private Label         yearsFundLabel;
      private DoubleField   yearsFundField;
      private Button              calculateButton;
    private TextArea      output;


               // instance variables
      private double earnedInterest;            // initial principle * interest rate
      private double yearEndPrinciple;    // initial principle + earned interests

               // constructor

  public Mutualfund6(){

                 // table header's line

  String  header = Format.justify('l', "Year", 12) +
                           Format.justify('r', "Principle", 15) +
                           Format.justify('r', "Interest rate", 18) + "\n";


                 // instantiate window objects


             initialPrincipleLabel = addLabel         ("Enter principle",1,1,1,1);
             initialPrincipleField = addDoubleField   (0,1,2,1,1);
             interestRateLabel     = addLabel         ("Interest Rate",2,1,1,1);
             interestRateField     = addInterestField (0,2,2,1,1);
             yearsFundLabel        = addLabel         ("Years Invested",3,1,1,1);
             yearsFundField        = addIntegerField  (0,3,2,1,1);
             calculateButton       = addButton        ("Calculate",4,1,1,1);
             yearEndPrincipleLabel = addLabel         ("Year end principle",5,1,1,1);
             outputField           = addTextArea      (header,4,1,4,4 );


      output.setEnabled(false);
      initialPrincipleField.requestFocus();
      interestRateField.requestFocus();
      yearsFundField.requestFocus();

      // initialize double fields to zero

      intialPrinciple = 0;
      interestRate = 0;
      yearsFund = 0;

}



  public void buttonClicked (JButton buttonObj){

            if (the calculate button is pressed)  {
                        processInputs()

            } else {
                  displayDashes()
                  displayNumbers (initialPrinciple, interestRate, yearsFund)
            }




      // read the inputs, compute the invest informatiom, display and format the year, principle, interest earned and the year end total


   private void processInputs(){

      //declare local variables

            double initialPrinciple;
            double interestRate;
            int yearsFund;
            double earnedInterest;
            double yearEndPrinciple;

            initialPrinciple = initialPrincipleField.getnumber();
            interestRate = interestRateField.getnumber();
        yearsFund = yearsFundField.getnumber();


        //calculate

        earnedInterest = (initialPrinciple * interestRate);
            yearEndPrinciple = (earnedInterest + initialPrinciple);



            displayNumbers (initialPrinciple, interestRate, yearsFund);


 }
   private void displayNumbers (double num1, double num2, int num3){
                        String dashLine = Format.justify('l', num1, 12) +
                                                     Format.justify('r', num2, 15, 2) +
                                                     Format.justify('r', num3, 18, 2) + "\n";
                                    output.append (numberLine + "\n");
}




      public static void main(String[] args){

                  Mutualfund6 theGUI = new Mutualfund6 ();
                  theGUI.setSize (200,300);            //width = 300, height = 300 in pixels
                  theGUI.setVisible (true);            //window is visible

      }
}






My compile errors are:    ..............................

C:\ex\Mutualfund6.java:64: ')' expected
            if (the calculate button is pressed)  {
                        ^
C:\ex\Mutualfund6.java:121: illegal start of expression
}



thanks for any and all help! lauren
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12305825
if (the calculate button is pressed)  {

should be
if (buttonObj instanceof calculateButton)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12305847
public void buttonClicked (JButton buttonObj){

         if (buttonObj instanceof calculateButton)  {
                    processInputs();

          } else {
               displayDashes();
               displayNumbers (initialPrinciple, interestRate, yearsFund);
          }
}
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12307491
you have posted same problem as another question

here is the code

import java.awt.*;
import javax.swing.*;

import BreezyGUI.*;

  public class Mutualfund6 extends GBFrame{

             // variables for window objects

     private Label         initialprincipleLabel;
     private DoubleField   initialprincipleField;
     private Label            interestRateLabel;
     private IntegerField  interestRateField;
     private Label         yearsFundLabel;
     private DoubleField   yearsFundField;
     private Button            calculateButton;
     private Button            myButton;
    private TextArea      output;
    private Label yearEndPrincipleLabel;


              // instance variables
     private double earnedInterest;          // initial principle * interest rate
     private double yearEndPrinciple;    // initial principle + earned interests

              // constructor

     private double intialPrinciple = 0;
     private double interestRate = 0;
     private double yearsFund = 0;


  public Mutualfund6(){

               // table header's line

  String  header = Format.justify('l', "Year", 12) +
                        Format.justify('r', "Principle", 15) +
                       Format.justify('r', "Interest rate", 18) + "\n";


               // instantiate window objects


           initialprincipleLabel = addLabel         ("Enter principle",1,1,1,1);
           initialprincipleField = addDoubleField   (0,1,2,1,1);
           interestRateLabel     = addLabel         ("Interest Rate",2,1,1,1);
           interestRateField     = addIntegerField (0,2,2,1,1);
           yearsFundLabel        = addLabel         ("Years Invested",3,1,1,1);
           yearsFundField        = addDoubleField  (0,3,2,1,1);
           calculateButton       = addButton        ("Calculate",4,1,1,1);
           yearEndPrincipleLabel = addLabel         ("Year end principle",5,1,1,1);
           output           = addTextArea      (header,4,1,4,4 );
           myButton       = addButton        ("My Button",6,1,1,1);


     output.setEnabled(false);
     initialprincipleField.requestFocus();
     interestRateField.requestFocus();
     yearsFundField.requestFocus();

     // initialize double fields to zero

     intialPrinciple = 0;
     interestRate = 0;
     yearsFund = 0;

//     calculateButton.addActionListener(new GBFrameButtonListener(this));

}



  public void buttonClicked (Button buttonObj){

          if (buttonObj.equals(calculateButton)){
                    System.out.println("calculate button clicked :" );
            }else if(buttonObj.equals(myButton)){
                  System.out.println("my button clicked :");
            }
          /*if (buttonObj == calculateButton)  {
                    processInputs();

          } else {
               //displayDashes();
               //displayNumbers (initialPrinciple, interestRate, yearsFund);
          }*/
          processInputs();
      System.out.println("button clicked :" + buttonObj);
}


     // read the inputs, compute the invest informatiom, display and format the year, principle, interest earned and the year end total


   private void processInputs(){

     //declare local variables

          double initialPrinciple;
          double interestRate;
          double yearsFund;
          double earnedInterest;
          double yearEndPrinciple;

          initialPrinciple = initialprincipleField.getNumber();
          interestRate = interestRateField.getNumber();
        yearsFund = yearsFundField.getNumber();


        //calculate

        earnedInterest = (initialPrinciple * interestRate);
          yearEndPrinciple = (earnedInterest + initialPrinciple);



          displayNumbers (initialPrinciple, interestRate, yearsFund);


 }
   private void displayNumbers (double num1, double num2, double num3){
                    String dashLine = Format.justify('l', num1, 12, 2) +
                                              Format.justify('r', num2, 15, 2) +
                                             Format.justify('r', num3, 18, 2) + "\n";
                              output.append (dashLine + "\n");
}




     public static void main(String[] args){

               Mutualfund6 theGUI = new Mutualfund6 ();
               theGUI.setSize (200,300);          //width = 300, height = 300 in pixels
               theGUI.setVisible (true);          //window is visible

     }
}
0
 
LVL 6

Accepted Solution

by:
expertmb earned 500 total points
ID: 12307613
>>differences in Java Swing and Breezy Swing
Breezy swing is derived from the java.awt. classes,
GBFrame extends the java.awt.Frame
GBDialog extends teh java.awt.Dialg;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now