Brayn66
asked on
urgent! investment calculation with GUI interface.........
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
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,
}
// 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
ASKER
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
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
i dont know about breezy swing, sorry :(
this could help you
http://faculty.cs.wwu.edu/martin/Software%20Packages/BreezySwing/Default.htm
this could help you
http://faculty.cs.wwu.edu/martin/Software%20Packages/BreezySwing/Default.htm
ASKER
Thanks, I'll look over it. lauren
ASKER
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.requ estFocus() ;
interestRateField.requestF ocus();
yearsFundField.requestFocu s();
// 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.getn umber();
interestRate = interestRateField.getnumbe r();
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
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.requ
interestRateField.requestF
yearsFundField.requestFocu
// 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.getn
interestRate = interestRateField.getnumbe
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:
if (the calculate button is pressed) {
^
C:\ex\Mutualfund6.java:121
}
thanks for any and all help! lauren
if (the calculate button is pressed) {
should be
if (buttonObj instanceof calculateButton)
should be
if (buttonObj instanceof calculateButton)
public void buttonClicked (JButton buttonObj){
if (buttonObj instanceof calculateButton) {
processInputs();
} else {
displayDashes();
displayNumbers (initialPrinciple, interestRate, yearsFund);
}
}
if (buttonObj instanceof calculateButton) {
processInputs();
} else {
displayDashes();
displayNumbers (initialPrinciple, interestRate, yearsFund);
}
}
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.requ estFocus() ;
interestRateField.requestF ocus();
yearsFundField.requestFocu s();
// initialize double fields to zero
intialPrinciple = 0;
interestRate = 0;
yearsFund = 0;
// calculateButton.addActionL istener(ne w GBFrameButtonListener(this ));
}
public void buttonClicked (Button buttonObj){
if (buttonObj.equals(calculat eButton)){
System.out.println("calcul ate button clicked :" );
}else if(buttonObj.equals(myButt on)){
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.getN umber();
interestRate = interestRateField.getNumbe r();
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
}
}
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.requ
interestRateField.requestF
yearsFundField.requestFocu
// initialize double fields to zero
intialPrinciple = 0;
interestRate = 0;
yearsFund = 0;
// calculateButton.addActionL
}
public void buttonClicked (Button buttonObj){
if (buttonObj.equals(calculat
System.out.println("calcul
}else if(buttonObj.equals(myButt
System.out.println("my button clicked :");
}
/*if (buttonObj == calculateButton) {
processInputs();
} else {
//displayDashes();
//displayNumbers (initialPrinciple, interestRate, yearsFund);
}*/
processInputs();
System.out.println("button
}
// 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.getN
interestRate = interestRateField.getNumbe
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
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://java.sun.com/docs/books/tutorial/uiswing/
for event handling
http://java.sun.com/docs/books/tutorial/uiswing/events/index.html