0

I am new to Java and I am having trouble knowing if my array is populating when I click the enter button and printing out the data into the text area when I click the run reports button. When I put data in the text boxes the boxes are being reset for new data entry but when I press the run reports I get nothing. Any advice is greatly appreciated. Here is my code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

public class TutorHelp extends JFrame
{
	private JPanel panel; //reference to the panel
	private JLabel TutorTimeLabel; //tutoring time label
	private JTextField timeField; //tutoring time text field
	private JLabel TutorWageLabel; //tutoring wage label
	private JTextField wageField; //tutoring wage text field
	private JTextArea textArea; // tutoring text area
	private JButton enterButton; // Enter button
	private JButton runReportsButton; // run reports button
	private JButton quitButton; // quit button
	final int WINDOW_WIDTH = 500; //window width
	final int WINDOW_HEIGHT = 600; // window height
	double [] tutorMin = new double [2];
	double [] tutorWage = new double [2];


public TutorHelp()
{
setTitle("Tutor Earnings"); // Window title
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);// Window size
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // SET DEFAULT CLOSE OPERATION
buildPanel(); //build the panel
add(panel); // add to the panel
setVisible(true); // makes the window visible

}

private void buildPanel()
{
	TutorTimeLabel = new JLabel("Tutor Time"); //Tutoring label
	timeField = new JTextField(10); // time text field
	TutorWageLabel = new JLabel("Tutor Earnings"); // tutor wage label
	wageField = new JTextField(10); //wage text field
	textArea = new JTextArea(25,50); // window text area
	enterButton = new JButton("Enter"); // create an enter button
	enterButton.addActionListener(new EnterButtonListener()); // add a enter button action listener
	runReportsButton = new JButton("Run Reports"); //create a run reports button
	runReportsButton.addActionListener(new runReportsButtonListener()); // add a run reports action listener
	quitButton = new JButton("Quit"); // create a quit button
	quitButton.addActionListener(new quitButtonListener()); // add a quit button action listener
	panel = new JPanel(); //create a panel
	panel.add(TutorTimeLabel); // add tutor time label
	panel.add(timeField); // add time field 
	panel.add(TutorWageLabel); // add tutor time label
	panel.add(wageField); // add wage field 
	panel.add(textArea); // add text area
	panel.add(enterButton); // add enter button
	panel.add(runReportsButton); // add the run reports button
	panel.add(quitButton); // add a quit button
}

private class EnterButtonListener implements ActionListener  // enter button class listener
{
	public void actionPerformed(ActionEvent e) // action event
	{
		
		int count = 0; // counter variable
		double num1 = 0; // time array variable
		double num2 =0; // wage array variable
		double m = Double.parseDouble(timeField.getText()); // get input from the time text field
		double w = Double.parseDouble(wageField.getText()); // get input from the wage text field
		num1 = m ; // parse the input from the time field
		num2 = w ; // parse the input from the wage field
		
		
		
		if (num1 <= 0) // error check for tutor time
		{
			JOptionPane.showMessageDialog(null, "Please enter a time larger than 0", "Error", JOptionPane.ERROR_MESSAGE); // error message if you enter the wrong number	
		}else if (num1 > 240)
		{
			JOptionPane.showMessageDialog(null, "You have worked to many minutes this week", "Error", JOptionPane.ERROR_MESSAGE); // error if you work to many minutes
		}else{
			
		}
			
			for(double i = 0;  i< 3; i++)  //loop for num1
			{ 
				
				 
			}
			if(num2 < 0) 
			{
				JOptionPane.showMessageDialog(null, "Please enter a wage", "Error", JOptionPane.ERROR_MESSAGE); //error message for the wage field
			}
			for(int i = 0; i < 3; i++)
			{
				
						
					for(count = 1; count <=3; count++){ //counter for the enter button
				}
					tutorMin[0] = m;
					tutorWage[1]= w;
					
			timeField.setText("");
			wageField.setText("");
			wageField.requestFocus();
			timeField.requestFocus();
			
		}
	}
}

private class runReportsButtonListener implements ActionListener  // enter run reports class listener
{
	public void actionPerformed(ActionEvent e)
	{
		double average = 0 ; // run reports variables
		Double num1 = 0.0d;
		Double num2 = 0.0d;
		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++)  //loop to total the minutes
		{
			totalMin += i;
		}
		for (int j = 0; j < tutorWage.length; j++) //loop to total the earnings
		{	
			totalEarnings += j; 
	     }
		for (int j = 0; j < tutorWage.length; j++) // loop to find average wage
		{
			
			totalWage += j;
			average = totalEarnings / 60;
		}
		if (average > MIN_WAGE)  // statement to find if above average wage
		{
			wage = "Above Minimum Wage";
		}else if ((average < MIN_WAGE)&&(average > MIN_WAGE)) // statement to find if equal to average wage
		{
			wage = "Equal to Minimum Wage";
		}else if (average < MIN_WAGE)   // statement to find if below average wage
		{
			wage = "Below Minimum Wage";
		}
		
		textArea.append("Total minutes are: " +totalMin+"\n"); // prints out data
		textArea.append("Average Earnings are: " +average+"\n");
		textArea.append("Minimum wage is: " +wage+"\n" );
		textArea.setText("");
}}

private class quitButtonListener implements ActionListener  // quit button class listener
{
	public void actionPerformed(ActionEvent e)
	{
	System.exit(0);	// closes window
	}
}	
	public static void main (String[] args) // the main
	{
	TutorHelp th = new TutorHelp(); 
}}
2
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by fmnajp
0
textArea.append("Total minutes are: " +totalMin+"\n"); // prints out data
textArea.append("Average Earnings are: " +average+"\n");
textArea.append("Minimum wage is: " +wage+"\n" );
textArea.setText("");

what did you expect this to do? you're setting the textArea with "", meaning basicly, no text.
try this:

String a = new String("Total minutes are: " + totalMin +"\n");
a+=("Average Earnings are: " + average + "\n");
a+=("Minimum wage is: " + wage + "\n");
textArea.setText(a);
0

From what I had read I thought that the code was going to print the text data into the text area. I will try your suggestion. Thanks

textArea.append("Total minutes are: " +totalMin+"\n"); // prints out data
textArea.append("Average Earnings are: " +average+"\n");
textArea.append("Minimum wage is: " +wage+"\n" );
textArea.setText("");

what did you expect this to do? you're setting the textArea with "", meaning basicly, no text.
try this:

String a = new String("Total minutes are: " + totalMin +"\n");
a+=("Average Earnings are: " + average + "\n");
a+=("Minimum wage is: " + wage + "\n");
textArea.setText(a);
0

Thank you stultuske, I now get a print out in the text field but it prints out the default information in the run reports button. The data I am inputting in the text boxes is either not going into the array or I am not retrieving it properly.

0

well..

I just read this between things, and after my hours, so don't be surprised I don't read every line.

what is:

1. the input you give
2. the output you expect for it
3. the output you actually get

?

0

1. The input I give: the time and payment inputed in the two text fields.

2. Expected out put: the total minutes, the average wage per hour and if that average wage is above equal to or below average wage.

3. Actual output: Total minutes are: 1.0
Average Earnings are: 0.016666666666666666
Minimum wage is: Below Minimum Wage
I get these numbers no matter what numbers are inputed

0

just give the exact input (numbers) and output.
I know what it's supposed to return, but it's the values that could be of help.

0

The user should be able to enter any numbers for the minutes and the wages. For example I put in 45 in the tutor time field and 90 in tutor wage field. I would click the enter button then enter 25 in the tutor time field and 50 in the tutor wage field and click enter. I would enter 40 in the tutor time field and 80 in the tutor wage field click enter. Then I would click the run reports button to get the total minutes, average wage per hour and above, equal or below minimum wage

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.