Hi guys, i dont think im using the boolean and break correctly i need it to see the tutormin>=240 and then throw the error and stop without exiting the program. can someone take a look and help me edit it
import java.awt.*; //imports all Java.awt
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*; // Imports all swing
/*
Author James Perkins
* Intro to programming
* Task 1
*
*/
class Tuthelp extends JFrame {
private JPanel panel;
private JLabel TutorTimeLabel; // Time label
private JTextField timeField; // Field for time info
private JLabel TutorWageLabel; //Label for Tutor wages
private JTextField wageField; // Field to enter info for Wage
private JTextArea textArea; // Text where all GUI info will show after report is run
private JButton enterButton; //Enter Button in GUI
private JButton runReportsButton; // Run report in GUI
private JButton quitButton; // Exit program button
final int WINDOW_WIDTH = 600; // Window Width
final int WINDOW_HEIGHT = 600; // Window height
double [][] studentData = new double [3][3]; //
int nextStudent=0;
public Tuthelp()
{
setTitle("Tutor Earnings "); // GUI title
setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //sets the size of the window.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
public void buildPanel(){
//* This part Creates the GUI using labels and Panels described below/*
TutorTimeLabel = new JLabel("Tutor Time");
timeField = new JTextField(10);
TutorWageLabel = new JLabel ("Tutor Earnings");
wageField = new JTextField(10);
textArea = new JTextArea(25,50);
enterButton = new JButton("Enter");
enterButton.addActionListener(new Tuthelp.enterButtonListener());
runReportsButton = new JButton("Run Reports");
runReportsButton.addActionListener(new Tuthelp.runReportsButtonListener());
quitButton = new JButton("Quit");
quitButton.addActionListener(new quitButtonListener());
panel = new JPanel();
panel.add(TutorTimeLabel);
panel.add(timeField);
panel.add(TutorWageLabel);
panel.add(wageField);
panel.add(textArea);
panel.add(enterButton);
panel.add(runReportsButton);
panel.add(quitButton);
}
private class enterButtonListener implements ActionListener // Actions performed when enter is hit are below
{
public void actionPerformed(ActionEvent e)
{
boolean error =false;
double minsIdx = Double.parseDouble(timeField.getText());
double wagesIdx= Double.parseDouble(wageField.getText());
studentData[nextStudent][0] = minsIdx; // Minutes entered
studentData[nextStudent][1] = wagesIdx; // Wages Entered
nextStudent++; // Ready for the next Student entry.
// the following Code below is an IF statement to make sure the user enters the correct information.
time:
if (minsIdx <=0){
JOptionPane.showMessageDialog(null, "Please enter a time larger than 0", "Error",
JOptionPane.ERROR_MESSAGE);
}
else if (minsIdx >= 240)
{
JOptionPane.showMessageDialog(null, "You have Tutored this Person too long", "Error",
JOptionPane.ERROR_MESSAGE);
error = true;
break time;
}else{
if(wagesIdx <= 0) // They must get paid so error if wage is zero.
{
JOptionPane.showMessageDialog(null, "Please enter a wage", "Error",
JOptionPane.ERROR_MESSAGE);
}
timeField.setText("");
wageField.setText("");
wageField.requestFocus();
timeField.requestFocus();
}
}
}
private class quitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0); // When the button is pressed the program will close.
}
}
private class runReportsButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int cols=2;
int rows=studentData[0].length;
double average = 0.00d; // Average time, with two decimal places
double totalMin = 0.00d; // total mintues work with two decimal place.
final double MIN_WAGE = 7.25;// This is the minimum wage interger.
double totalWage = 0.00d; // Total wages, with a two decimal places.
String wage = "";
wage+=
"****************************************************\n\n";
wage+= "Tutoring Earnings Data \n\n"; // This is a heading of the first part of the report
wage+= "\n";
wage+= "Mintues Earnings\n"; // this will show the amount they entered.
for(int i = 0; i< rows;i++){
for(int j =0; j <cols; j++ ){
wage += studentData[i][j];
wage += " ";
if (j == 0) {
totalMin += studentData[i][j];
}
else if (j == 1){
totalWage += studentData[i][j];
}
}
wage+= "\n";
}
if (studentData[0].length >0 ) {
average = totalWage / studentData[0].length; // Shows how we work out the average. total wage divided by the amount of time.
}
wage +=
"************************************************************************\n\n";
wage += "Reports of your wages to Date:\n"; // Displays the top of the report
wage += "_____________________________\n\n"; // Displays a line to keep the gui neet
wage += "Total Mintues spent tutoring = " + totalMin + "\n"; // Shows total of all mintues entered.
wage += "Total Earnings = $" + totalWage + "\n";// Shows total of earnings
wage += "Average Per Hour = $ " + average + "\n"; // Divides the total wage by the mintues entered.
wage += "Minimum wage = $" + MIN_WAGE + "per hour" + "\n";// The State minimum wage
wage += "Your average wage are ";
// The Follow IF statement will decide if the average wage entered is, below, average, or above.
if (average < MIN_WAGE){
wage +=" Below Average";
} else if (average >= MIN_WAGE && average <= MIN_WAGE * 2.00) {
wage += "Average";
} else if (average > MIN_WAGE *2.00){
wage += "Above Average";
}
textArea.setText(wage); // where the report is sent to.
}}
public static void main (String[] args)
{
Tuthelp th = new Tuthelp();
}
}
Thanks in advance