I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is:
Week5MortgageGUI.java:151:cannot find symbol
symbol: method allInterest(double,double,double)
Location: class Week5MortgageGUI
Week5MortgageLogic allint = logic.allInterest(amount, term[x], rate[x]);
Week5MortgageGUI.java:152:cannot find symbol
symbol: method allInterest(double,double,double)
Location: class Week5MortgageGUI
textarea.append(logic.calculateMortgage(amount, term[x], rate[x]));
Week5MortgageGUI.java:156:cannot find symbol
symbol: class ApplePie
Location: class Week5MortgageGUI
pie = new ApplePie(2);
Week5MortgageGUI.java:157:cannot find symbol
symbol: method addSlice(java.awt.Color,double)
Location: class java.awt.event.ActionEvent
pie.addSlice(Color.red, allint);
^
Week5MortgageGUI.java:158:cannot find symbol
symbol: method addSlice(java.awt.Color,double)
Location: class java.awt.event.ActionEvent
pie.addSlice(Color.green, amount);
^
Week5MortgageGUI.java:160:cannot find symbol
symbol: method addSlice(java.awt.Color,double)
Location: class java.awt.Container
jpie.getContentPane().add(pie);
^
This is the code that is getting the error. Can anyone help me out? =)
[PHP]import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.DecimalFormat;
import java.net.URL;
import java.awt.event.ActionEvent;
public class Week5MortgageGUI extends JApplet implements ActionListener {
//Declare variables and arrays
int x;
double amount, allint;
String header = ("MONTH \tPAYMENT \tBALANCE \tINTEREST \n");
String[] cases = new String[4];//Empty array
double[] rate = new double[4];//Empty array
double[] term = {7, 15, 30, 0};
DecimalFormat money = new DecimalFormat("$###,###.00");//New DecimalFormat object named 'money'
//Set up JFrame GUI components
JButton cal = new JButton("Calculate!");
JButton ok = new JButton("Ok");
JButton quit = new JButton("Quit");
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
Box box1 = Box.createVerticalBox();
Box box2 = Box.createVerticalBox();
Box myBox = Box.createVerticalBox();
JLabel select = new JLabel("Select loan term & rate:");
JLabel amountlabel = new JLabel("Enter Amount: $");//Create label that directs user to enter his/her name
JLabel termlabel = new JLabel("Enter Term: ");//Create label that directs user to enter his/her name
JLabel ratelabel = new JLabel("Enter Rate: ");//Create label that directs user to enter his/her name
JLabel message = new JLabel("Click Ok to continue:");
JLabel legend = new JLabel("Pie Chart Legend:");
JLabel space = new JLabel("-------------------------");
JLabel allinterest;
JLabel allprincipal;
JTextField amounttext = new JTextField(10);//Create blank text field
JTextField termtext = new JTextField(10);//Create blank text field
JTextField ratetext = new JTextField(10);//Create blank text field
JTextArea textarea = new JTextArea(8, 35);
JScrollPane scroll = new JScrollPane(textarea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JRadioButton radio1 = new JRadioButton();
JRadioButton radio2 = new JRadioButton();
JRadioButton radio3 = new JRadioButton();
JRadioButton radio4 = new JRadioButton();
ButtonGroup group = new ButtonGroup();
Container content_pane = getContentPane();
JFrame jpie;
//Declare init() method for JApplet
public void init() {
setSize(600, 400);//Set JApplet size
FlowLayout flow = new FlowLayout();//Create FlowLayout object called 'nameflow'
content_pane.setLayout(flow);//Set content_pane layout format to 'flow' object
this.readRates("rates.txt");//Populate 'rate' array from the values contained within file "rates.txt" - see method below
cases[0] = "7 year at " + rate[0] + "%";//Populate 'cases' array
cases[1] = "15 year at " + rate[1] + "%";
cases[2] = "30 year at " + rate[2] + "%";
cases[3] = "Enter my own term & rate";
radio1.setText(cases[0]);//Set up radio buttons
radio2.setText(cases[1]);
radio3.setText(cases[2]);
radio4.setText(cases[3]);
amounttext.addActionListener(this);//Add the action listeners
termtext.addActionListener(this);
ratetext.addActionListener(this);
cal.addActionListener(this);
ok.addActionListener(this);
quit.addActionListener(this);
radio1.addActionListener(this);
radio2.addActionListener(this);
radio3.addActionListener(this);
radio4.addActionListener(this);
group.add(radio1);//Add radio buttons to button group
group.add(radio2);
group.add(radio3);
group.add(radio4);
box1.add(select);//Add radio buttons to vertical box #1
box1.add(radio1);
box1.add(radio2);
box1.add(radio3);
box1.add(radio4);
box2.add(termlabel);//Add these GUI components to vertical box #2
box2.add(termtext);
box2.add(ratelabel);
box2.add(ratetext);
panel1.add(amountlabel);//Add GUI components to panel #1
panel1.add(amounttext);
panel1.add(box1);
panel2.add(cal);//Add GUI components to panel #2
panel3.add(scroll);//Add GUI components to panel #3
content_pane.add(panel1);//Add these panels to the content pane
content_pane.add(panel2);
content_pane.add(panel3);
textarea.append(header);
panel4.add(message);//Add GUI components to panel #4 but don't add panel to content pane yet
panel4.add(ok);
panel4.add(quit);
this.setVisible(true);//Make the JFrame visible to the user
}
//Declare actionPerformed method to receive & process ActionListener event (user input)
public void actionPerformed(ActionEvent response) {
Object rspname = response.getSource();//Get response source
try {
//Rearrange display to accept user-defined term & rate if radio4 is selected
if (radio4.isSelected() == true) {
panel1.add(box2);
content_pane.validate();
}
//Remove text labels & fields for user-defined term & rate if radio4 is not selected
if (radio4.isSelected() == false) {
panel1.remove(box2);
content_pane.validate();
}
if (rspname == cal) {
//Obtain user-defined term & rate from termtext & ratetext fields
if (rspname == cal && radio4.isSelected() == true) {
term[3] = Double.parseDouble(termtext.getText());//Parse double from String
rate[3] = Double.parseDouble(ratetext.getText());
x = 3;
}
if (rspname == cal && radio3.isSelected() == true) {
x = 2;
}
if (rspname == cal && radio2.isSelected() == true) {
x = 1;
}
if (rspname == cal && radio1.isSelected() == true) {
x = 0;
}
//Throw this special Exception if the user fails to make a selection
if (radio1.isSelected() == false && radio2.isSelected() == false && radio3.isSelected() == false && radio4.isSelected() == false) {
throw new Exception("SelectionError");
}
amount = Double.parseDouble(amounttext.getText());//pull amount data from amounttext field
Week5MortgageGUI logic = new Week5MortgageGUI();
allint = logic.allInterest(amount, term[x], rate[x]);//Calculate total interest paid over life of loan.
textarea.append(logic.calculateMortgage(amount, term[x], rate[x]));//Obtain the amortization table from the logic class
ActionEvent pie ;
pie = new ApplePie(2);//Create ApplePie object (pie chart)
pie.addSlice(Color.red, allint);//Red pie slice = allint value
pie.addSlice(Color.green, amount);//Green pie slice = amount value
jpie = new JFrame("Interest vs. Principal");//Create JFrame to hold pie chart
jpie.getContentPane().add(pie);//Add pie chart to JFrame
jpie.pack();//Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.
jpie.setSize(250, 250);//Set size of new JFrame window
jpie.setVisible(true);//Make the JFrame visible to the user
allinterest = new JLabel("RED - Total interest paid: " + money.format(allint));//Pie labels
allprincipal = new JLabel("GREEN - Total principal paid: " + money.format(amount));//Pie labels
myBox.add(legend);//Add labels to vertical box
myBox.add(space);
myBox.add(allinterest);
myBox.add(allprincipal);
content_pane.add(myBox);//Add vertical box to content pane
content_pane.add(panel4);//Add panel4 to content pane
content_pane.validate();//Refresh the JPanel
}
if (rspname == quit) {//Selecting Quit disposes of the jpie & current JFrame
jpie.dispose();
jpie.setVisible(false);//Set visible-false to avoid memory leaks
this.setVisible(false);
}
if (rspname == ok) {//Selecting Ok clears the populated fields
jpie.dispose();//Dispose of the jpie JFrame
jpie.setVisible(false);//Set visible-false to avoid memory leaks
textarea.setText("");
amounttext.setText("");
termtext.setText("");
ratetext.setText("");
this.remove(myBox);
this.repaint();
this.validate();
myBox.remove(legend);
myBox.remove(space);
myBox.remove(allinterest);
myBox.remove(allprincipal);
myBox.revalidate();
}
} //Take these actions when an Exception occurs
catch (NumberFormatException e)//Specific Exception
{
textarea.append("Invalid Entry - The amount must be a positive number!\n" + e.toString() + "\n");
} catch (Exception e)//More general exception
{
if (e.getMessage() == "SelectionError") {//Specify exception message
textarea.append("Invalid Entry - Please select term & rate of your loan\n" + e.toString() + "\n");
} else {//Other general exceptions
textarea.append("Invalid Entry - The amount must be a positive number!\n" + e.toString() + "\n");
}
} catch (Throwable e)//Catch everything else
{
textarea.append("Invalid Entry!\n" + e.toString() + "\n");
}
}
private void readRates(String filename) {
try {
URL codeBase = getCodeBase();
URL url = null;
int index = 0;
url = new URL(codeBase, filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = reader.readLine();
while (line != null) {
rate[index] = Double.parseDouble(line);
line = reader.readLine();
index++;
}
} catch (Exception e) {
textarea.append("Could not read from file " + filename);
}
}
//Create an instance of the Week5MortgageGUI (this) class
public static void main(String[] args,Week5MortgageGUI Week5MortgageGUI) {
Week5MortgageGUI = new Week5MortgageGUI();
}
}
[/PHP]