INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Print a 2D array to text area

Print a 2D array to text area

(OP)
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!



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");
            }
    }

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close