hi Guys, I am currently coding for a GUI based program that delivers the amount of time a tutor works in minutes and the amount they go paid total, giving them details on the amount of time work total, and wage per hour and if it is below, minimum, or above minimum wage. I currently have to problems and not sure how to work them out.
1. Program does not let me enter more then one set of hours work and wages paid, and also does not show this within the GUI when I press the Enter button. ( using a two dimensional array to store that info)
2. Im not sure how to change the IF statement regarding the minimum wage to reflect,
if average wages per hour is < minimum wage, then below average
- if average wages per hour is ≥ minimum wage AND ≤ minimum wage × 2.00,
then average
- if average wages per hour is > minimum wage × 2.00, then above average
Please see my code below thanks in advance
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Tutorhelp 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;
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 [] tutorMin = new double [2];
double [] tutorWage = new double [2];
public Tutorhelp()
{
setTitle("Tutor Earnings");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildPanel();
add(panel);
setVisible(true);
}
private void buildPanel()
{
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 EnterButtonListener());
runReportsButton = new JButton("Run Reports");
runReportsButton.addActionListener(new 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
{
public void actionPerformed(ActionEvent e)
{
int count = 0;
double num1 = 0;
double num2 = 0;
double m = Double.parseDouble(timeField.getText());
double w = Double.parseDouble(wageField.getText());
num1 = m ;
num2 = w ;
if (num1 <=0)
{
JOptionPane.showMessageDialog(null, "Please enter a time larger than 0", "Error",
JOptionPane.ERROR_MESSAGE);
}else if (num1 > 240)
{
JOptionPane.showMessageDialog(null, "You have worked to many mintues this week", "Error",
JOptionPane.ERROR_MESSAGE);
}else{
}
for(double i = 0; i< 3; i++)
{
}
if(num2 < 0)
{
JOptionPane.showMessageDialog(null, "Please enter a wage", "Error",
JOptionPane.ERROR_MESSAGE);
}
for(int i = 0; i < 3; i++)
{
for(count = 1; count <=3; count++){
}
tutorMin[0] = m;
tutorWage[1] = w;
timeField.setText("");
wageField.setText("");
wageField.requestFocus();
timeField.requestFocus();
}
}
}
private class runReportsButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double average = 0.00d;
double num1 = 0.00d;
double num2 = 0.00d;
double totalMin = 0.0d;
double totalEarnings = 0.0d;
final double MIN_WAGE = 7.25;
double totalWage = 0.0d;
String wage = "";
for (int i = 0; i < tutorMin.length; i++)
{
totalMin += tutorMin[i];
}
for (int j = 0; j < tutorWage.length; j++)
{
totalEarnings +=tutorWage[j];
}
for (int j = 0; j < tutorWage.length; j++)
{
totalWage +=j;
average = totalEarnings /60;
}
if (average > MIN_WAGE)
{
wage = "Above Minimum Wage";
}else if ((average < MIN_WAGE)&&(average > MIN_WAGE))
{
wage = "Equal to Minimum Wage";
}else if (average < MIN_WAGE)
{
wage = "Below Minimum Wage";
}
String a = "Total mintues are " +totalMin +"\n";
a+=("Average Earnings are:" + average + "\n");
a+=("Minimum wage is: " +wage + "\n");
textArea.setText(a);
}}
private class quitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main (String[] args)
{
Tutorhelp th = new Tutorhelp();
}
}