Results 1 to 6 of 6
  1. #1
    yyzdslr is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default please help me with this! i'm almost there....

    I am writing a simple (not so simple for me) program for a class...
    A tutor can enter the time (in minutes) and money earned (in dollars)
    the app will input and output the following:

    input:
    minutes per session
    money made per session

    output:
    Total minutes spent tutoring
    Total Earnings
    Average per hour wage

    this is the example, this is how it should be..
    please help me with this! i'm almost there....-screen-shot-2013-04-23-4.54.29-am.png


    my calculations are coming out wrong :-( see:
    please help me with this! i'm almost there....-screen-shot-2013-04-23-5.05.04-am.png


    time and money can be entered over and over again (by entering into text fields) then pressing the "add or enter" button.
    these values have to be stored in an array...

    can someone please tell me what i'm doing wrong?


    Home.java
    Java Code:
    public class Home {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            javax.swing.JFrame myFrame = new javax.swing.JFrame();
            myFrame.add(new USERINTERFACE());
            myFrame.setTitle("Tutoring Calculator");
            myFrame.setSize(600, 550);
            myFrame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
            myFrame.setVisible(true);
            
        }
    }

    Userinterface.java
    Java Code:
    import javax.swing.JOptionPane;
    
    /**
     *
     * 
     */
    public class USERINTERFACE extends javax.swing.JPanel {
    
        int index = 0;
        double MinutesTutoring = 0;
        double DollarPayments = 0;
        double[][] array = new double[10][2];
        
        public USERINTERFACE() {
            initComponents();
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
       private void initComponents() {
    
            MinutesLabel = new javax.swing.JLabel();
            PaymentLabel = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            outputArea = new javax.swing.JTextArea();
            MinutesTutoringText = new javax.swing.JTextField();
            DollarPaymentsText = new javax.swing.JTextField();
            enterButton = new javax.swing.JButton();
            reportButton = new javax.swing.JButton();
            quitButton = new javax.swing.JButton();
    
            MinutesLabel.setText("Tutoring time in minutes:");
    
            PaymentLabel.setText("Payment for session in dollars and cents");
    
    
     //i've deleted a whole bunch of gui jargon from here... 
    
    
        }
        private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
            // the text box values will be checked and if acceptable will assign values to the vars
            
            try {
                MinutesTutoring = Double.parseDouble(
                        this.MinutesTutoringText.getText());
                if (MinutesTutoring <= 0) {
                    throw new Exception();
                }
                
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, 
                        "Please enter a valid value for Minutes ",
                        "Invalid Value Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
    
            try {
                DollarPayments = Double.parseDouble(
                        this.DollarPaymentsText.getText());
                if (DollarPayments <= 0) {
                    throw new Exception();
                }
            } catch (Exception e) {
                 JOptionPane.showMessageDialog(this, 
                        "Please enter a valid value for Payment",
                        "Invalid Value Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            
            //we are now assigning the values to the 2-d array 
    
            array[index][0] = MinutesTutoring;
            array[index][1] = DollarPayments;
            String message = "";
    
            for (int i = 0; i <= index; i++) {
    
                message += "Minutes Tutoring: " + array[i][0] + " " + "Payment Amount: " + array[i][1] + "\n";
                outputArea.setText(message);
    
            }
    
            this.MinutesTutoringText.setText("");
            this.DollarPaymentsText.setText("");
    
            index++;
    
    
        }                                           
    
        private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
            //this will exit out of the application and close the calculator 
            System.exit(0);
    
        }                                          
    
        private void reportButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // this button will generate the reportDisplay and calculations in the outputText area
    
            int valueColumns = 2;
            int valueRows = array[0].length;
            double WageMin = 7.35;
            double valueDollarTotal = 0.00;
            double valueTotalTime = 0.00;
            double WageAvg = 0.00;
            String reportDisplay = new String();
    
            reportDisplay += "****************************************************\n\n";
            reportDisplay += "Raw Tutoring Earnings Data: \n\n";
            reportDisplay += "\n";
            reportDisplay += "Minutes  Payment\n";
    
            for (int i = 0; i < valueRows+1; i++) {
                for (int j = 0; j < valueColumns; j++) {
                    reportDisplay += array[i][j];
                    reportDisplay += "           ";
    
                    if (i == 0) {
                        valueTotalTime += array[i][j];
                    } else if (i == 1) {
                        valueDollarTotal += array[i][j];
                    }
                }
    
                reportDisplay += "\n";
            }
    
            if (array[0].length > 0) {
                WageAvg = valueDollarTotal / array[0].length;
            }
    
            reportDisplay += "******************************\n\n";
            reportDisplay += "Report of your wages to Date:\n";
            reportDisplay += "____________________________\n\n";
            reportDisplay += "Total Minutes Spent Tutoring=   " + valueTotalTime + "\n";
            reportDisplay += "Total Earnings = $" + valueDollarTotal + "\n";
            reportDisplay += "Average Per Hour Wage= $" + WageAvg + "\n";
            reportDisplay += "_____________________________\n\n";
            reportDisplay += "Minimum wage for missouri is= $" + WageMin + " per hour" + "\n";
    
            reportDisplay += "Your average wages per hour are ";
    
            if (WageAvg < WageMin) {
                reportDisplay += "Below Average";
            } else if (WageAvg >= WageMin && WageAvg <= WageMin * 2.00) {
                reportDisplay += "Average";
            } else if (WageAvg > WageMin * 2.00) {
                reportDisplay += "Above Average";
            }
    
            outputArea.append(reportDisplay);
            
        }                                            
        // Variables declaration - do not modify                     
        private javax.swing.JTextField DollarPaymentsText;
        private javax.swing.JLabel MinutesLabel;
        private javax.swing.JTextField MinutesTutoringText;
        private javax.swing.JLabel PaymentLabel;
        private javax.swing.JButton enterButton;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea outputArea;
        private javax.swing.JButton quitButton;
        private javax.swing.JButton reportButton;
        // End of variables declaration                   
    }
    Any help would be greatly appreciated.
    Thanks in advance.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default Re: please help me with this! i'm almost there....

    What is the above not doing that it should be doing?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    yyzdslr is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Re: please help me with this! i'm almost there....

    Quote Originally Posted by Tolls View Post
    What is the above not doing that it should be doing?
    my calculation outputs on the following is wrong:
    total minutes spent tutoring,
    total earnings
    average per hour wage

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default Re: please help me with this! i'm almost there....

    The phrase "blood from a stone" comes to mind.

    Show a run, complete with inputs and outputs.
    Show us what it should be producing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    yyzdslr is offline Member
    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0

    Default Re: please help me with this! i'm almost there....

    Quote Originally Posted by Tolls View Post
    The phrase "blood from a stone" comes to mind.

    Show a run, complete with inputs and outputs.
    Show us what it should be producing.

    I'm sure i'll look back at this and I'll agree with the mentioned quote. :) sorry to be a pain. Its my 3rd day writing code and I'm not used to the dev environment.

    How would you recommend I show the run, with inputs and outputs? Screenshots?
    Or is there a log I can copy and paste running in the bg?

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default Re: please help me with this! i'm almost there....

    Just copy/paste from the console.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •