Hello,
I am trying to build a GUI with 2 textfields (1 for tutoring time & 1 for payment for session), a textarea (display the inputs in 2-D array & show report), and a few buttons (ENTER, RUN REPORT & QUIT). The two textfields are for the user to enter in random numbers (one number in each textfield). I then want the person to be able to hit a enter button that will then take these two values, put them into a two-dimensional array, and then display those values inside the textarea. The person should then be able to enter in two more values, hit the button, those two new values go into the array with the others and the textarea should then display all the values like this (see between the 2 lines):
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:
__________________________
**************************
Raw Tutoring Earnings Data
Minutes Earnings
60.0 10.0
120.0 40.0
90.0 15.0
**************************
__________________________
The person should then be able to hit the run report button in the textarea from the values entered from textfields to the textarea with 2-D arrays. The textarea should then display all the values like this (see between the 2 lines):
__________________________________
**********************************
Minutes: 60.0 Earnings: $10.0
Minutes: 120.0 Earnings: $40.0
Minutes: 90.0 Earnings: $15.0
**********************************
Report or your wages to Date:
Total Minutes Spent Tutoring= 270.0
Total Earnings= $65.0
Average Per Hour Wage= $14.44
Minimum Wage is currently= $6.55
Your average wages per hour are above average
**********************************
__________________________________
Here the rules:
1. Throw an exception values less or equal to zero in the textfields.
2. Tutors should not tutor for more than 4 hours per day (input values in minutes).
3. Earnings should be dollars and cents.
4. Wage analysis, following logic:
-if average wages per hour is < minimum wage, then below average
-if average wages per hour is > minimum w2age AND < minimum wage x 2.00, then average
-if average wages per hour is > minimum wage x 22.00, then above average
Here is the code that I am having trouble with in getting:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// exception for minutes entered less than or equal to 0 <strong class="highlight">and</strong> not greater than 240
double jTextField1 = 0;
try {
jTextField1 = Double.parseDouble(
this.jTextField1.getText());
if (jTextField1 <= 0 || jTextField1 > 240){
throw new Exception();
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid input. Minutes can't be less than 0 or more than 240. Please try again",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
double jTextField2 = 0;
try {
jTextField2 = Double.parseDouble(
this.jTextField2.getText());
if (jTextField2 <=0) {
throw new Exception();
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid input. Earnings must be greater than zero. Please try again"
, "Error", JOptionPane.ERROR_MESSAGE);
return;
}
double[][] earnings = new double[10][2];
for (int i = 0; i <earnings.length; i++){
for (int j = 0; j < earnings[i].length; j++){
earnings[i][j]=2; //example
System.out.println(earnings[i][j]);
}
}
jTextArea1.append("\n Minutes Earnings\n *************************");
// separates detail from report <strong class="highlight">and</strong> lists all minutes <strong class="highlight">and</strong> earnings in <strong class="highlight">array</strong>
}
more codes:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JButton2 button2 = new JButton2("Click me");
//Displays in text area report title
jTextArea1.append("Report of your wages to Date:");
jTextArea1.append("\n"); //start a new line
//add total minutes tutoring <strong class="highlight">and</strong> display in text area
int totalmin = 0;
int[] data = null;
for (int jTextField1 : data)
{
totalmin = totalmin + jTextField1;
jTextArea1.append("Total Minutes Spent Tutoring =" + totalmin);
}
//add total earnings <strong class="highlight">and</strong> display in text area
int totalearn = 0;
for (int jTextField2 : data)
{
totalearn = totalearn + jTextField2;
jTextArea1.append("Total Earnings= " + totalearn);
}
//calculates average per hour wage
int average = 0;
{
average = totalearn / (totalmin / 60);
jTextArea1.append("Average Per Hour Wage= " + average);
jTextArea1.append("%\n"); //add a break between lines
//notes in text area the minimum wage
jTextArea1.append("Minimum Wage is currently = $6.55");
}
//wage analysis based on average <strong class="highlight">and</strong> current minimum wage
if (average < 6.55)
{
jTextArea1.append("Your average wages per hour are below average");
}
else if (average >= 6.55 && average <= 6.55*2)
{
jTextArea1.append("Your average wages per hour are then average");
}
else
{
jTextArea1.append("Your average wages per hour are above average");
}
}
Also, what I have to put in the main class for them tu run? or should I leave it blank?
There is probably an easy solution to fix this mess, but as a beginner at Java I am having trouble figuring this out. Right now, I don’t have the head to figure out the fix of these codes and I need to see what it is wrong and what is the fix(es) for this GUI, what to take out or put in?. Please help with comments on codes.
I'm very new at Java and any help would be greatly appreciated!!!!
Thanks in advance!