I'm working on a program and don't have any java experience, so it's been a bit stressful. Below is my code and it's supposed to record input each time you click the "enter" button and then output the array to a text area when you hit the "run report" button, but I can only get one value of the error to ever output when the "run report" button is clicked.
I'm sure it has something to do with my loop or where I'm declaring the variables, but I haven't figured out what the problem is yet. Any help is appreciated!
I'm sure it has something to do with my loop or where I'm declaring the variables, but I haven't figured out what the problem is yet. Any help is appreciated!
Code:
public TutorReport() {
initComponents();
}
double[][] sessionArray = new double[10][2];
double tutorMinutes = 0;
double tutorCost = 0;
private void cmdEnterTimeActionPerformed(java.awt.event.ActionEvent evt) {
Double.parseDouble(txtSessionMinutes.getText());
Double.parseDouble(txtSessionCost.getText());
//Exceptions for erroneous data
try {
tutorMinutes = Double.parseDouble(
this.txtSessionMinutes.getText());
if (tutorMinutes <= 0 || tutorMinutes> 240) {
throw new Exception();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid Input - Minutes must be greater than 0 and less than 240 - Please Try Again",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
tutorCost = Double.parseDouble(
this.txtSessionCost.getText());
if (tutorCost <= 0) {
throw new Exception();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid Input - Session Earnings must be greater than 0 - Please Try again",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
for (int i = 0; i < sessionArray.length; i++){
for (int j = 0; j < sessionArray[i].length; j++){
double sessionOutput = sessionArray[i][j];
String sessionString = Double.toString(sessionOutput);
sessionArray[j][1] = tutorMinutes;
sessionArray[j][0] = tutorCost;
}
}
JOptionPane.showMessageDialog(this, "Session Information Recorded", "Information", JOptionPane.INFORMATION_MESSAGE );
txtSessionMinutes.setText(" ");
txtSessionCost.setText(" ");
}
private void cmdQuitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void cmdRunReportActionPerformed(java.awt.event.ActionEvent evt) {
double minutesOutput = sessionArray[0][1];
double costOutput = sessionArray[0][0];
double totalCost = sessionArray[0][0];
String minutesString = Double.toString(minutesOutput);
String costString = Double.toString(costOutput);
String totalString = Double.toString(totalCost);
txtAreaReport.append("\n");
txtAreaReport.append("Session Minutes" + " " + minutesOutput + " ");
txtAreaReport.append("\n");
txtAreaReport.append("Session Cost" + " " + costString);
txtAreaReport.append("\n");
txtAreaReport.append("Total Cost" + " " + totalString);
txtAreaReport.append("\n");
txtAreaReport.append("Report of your wages to date:");
txtAreaReport.append("\n");
//Average per hour calculations
double avgPerHour;
{
avgPerHour = costOutput / (minutesOutput/60);
txtAreaReport.append("Average Wage Per Hour = " + avgPerHour);
txtAreaReport.append("\n");
txtAreaReport.append("Minimum Wage is Currently = $7.25");
txtAreaReport.append("\n");
}
//Calculations for minimum wage comparison
if (avgPerHour < 7.25)
{
txtAreaReport.append("Your Average Wages Per Hour are Below Average");
}
else if (avgPerHour >= 7.25 && avgPerHour <= 7.25*2)
{
txtAreaReport.append("Your Average Wages Per Hour are Average");
}
else
{
txtAreaReport.append("Your Average Wages Per Hour are Above Average");
}
}