I have been working on this for days!! I dont want to allow negative numbers in my program. I have changed it so many times I cant stand to look at it anymore. I greatly appreciate any help even just an example of what I need to do. I will be forever grateful!!!! THANKS!

    int cols = 2;
    int rows = tutoringSessions[0].length;

    // Initialize a new array with one more row than the existing array
    double[][] newTutoringSessions = new double[2][rows + 1];

    // Add data inputted into new array
try{
    newTutoringSessions[0][rows] = Double.parseDouble(timeSpentTextbox.getText());
    newTutoringSessions[1][rows] = Double.parseDouble(earningsTextbox.getText());
            if(earningsTextbox.getText().isEmpty());
            if(timeSpentTextbox.getText().isEmpty());
            if(earningsTextbox.getText().compareTo("0") == '0' );
            if(timeSpentTextbox.getText().contentEquals("0"));
     }catch(Exception e){
        System.out.println("Please Enter A number");
        JOptionPane.showMessageDialog(null,"Text Fields cannot be empty, please start over");
   }

    // Copy old tutoringSessions data into new array

    if (rows > 0) {
        for (int i = 0; i < cols; i++)                  
        {
            for (int j = 0; j < rows; j++) {
                newTutoringSessions[i][j] = tutoringSessions[i][j];
                }
            }
      }



    // Set tutoringSessions to new array
    tutoringSessions = newTutoringSessions;

    // Clear text fields
    timeSpentTextbox.setText("");
    earningsTextbox.setText("");


}                                     

private void runReportsMouseClicked(java.awt.event.MouseEvent evt) {                                        
    // TODO add your handling code here:
    int cols = 2;
    int rows = tutoringSessions[0].length;
    double timeSpentTotal = 0.00;
    double earningsTotal = 0.00;
    double averageWage = 0.00;
    double minimumWage = 6.55;
    String report = new String();

    report += "****************************************************\n\n";
    report += "Raw Tutoring Earnings Data\n\n";
    report += "\n";
    report += "Minutes      Earnings\n";

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            report += Double.toString(tutoringSessions[j][i]);
            report += "           ";

            if (i == 0) {
                timeSpentTotal += tutoringSessions[j][i];
            } else if (i == 1) {
                earningsTotal += tutoringSessions[j][i];
            }
        }

        report += "\n";
    }

    if (tutoringSessions[0].length > 0) {
        averageWage = earningsTotal / tutoringSessions[0].length;
    }

    report += "****************************************************\n\n";
    report += "Report of your wages to Date:\n";
    report += "____________________________\n\n";
    report += "Total Minutes Spent Tutoring = " + Double.toString(timeSpentTotal) + "\n";
    report += "Total Earnings = $" + Double.toString(earningsTotal) + "\n";
    report += "Average Per Hour Wage = $" + Double.toString(averageWage) + "\n";
    report += "Minimum Wage is currently = $" + Double.toString(minimumWage) + "\n";

    report += "Your average wages per hour are ";

    if (averageWage < minimumWage) {
        report += "Below Average";
    } else if (averageWage >= minimumWage && averageWage <= minimumWage * 2.00) {
        report += "Average";
    } else if (averageWage > minimumWage * 2.00) {
        report += "Above Average";
    }

    itemizedReportTextarea.setText(report);

You need to be more specific about your problem.

You need to be more specific about your problem.

I have a GUI with two text fields that users can insert any number except a negative or 0. My timeSpentTextbox and earningsTextbox values get placed into a 2D array. I want to be able to check to make sure the input is a valid number and not a negative or 0 before the program continues inserting those values into my 2D array. Does this help?? Thanks for looking into this!!

You could use a try catch statement and an if statement to solve it. Something like this...

public boolean isNaturalNumber( String input ) {
   boolean correct = false;
   try {
      int i = Integer.parseInt( input );
      if ( i > 0 ) correct = true;
   }
   catch(Exception e) {}
   return correct;
}

Just call this method from where you want to check for natural numbers and ask for the input again if it returns false;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.