#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0

    Having problem with outputting this table!


    I am having trouble with the table outputting it is saying I am getting errors..

    view my source code here:
    Code:
    commission = rate * salary; 
    pay = commission + salary; 
    JOptionPane.showMessageDialog(null, "Commission rate is " + 
    percent.format(rate) + ". The amount of pay is $" + dollar.format(pay)); 
    
    if (sales >=(.80 * sales) & sales<=45000) 
    incentive = (.1 * sales); 
    else if (sales >45000) 
    incentive = (2.25 * .1 * sales); 
    
    JOptionPane.showMessageDialog (null, 
    "n" + "Total Sales" + "Total Compensation" + "/n" + 
    "n" + ( dollar.format(sales) + (dollar.format(sales) + dollar.format(incentive) )) + "/n" + 
    "n" + (( dollar.format(sales) + 5000)) + (dollar.format(sales) + dollar.format(incentive) )) + "/n"; 
    
    System.exit(0); //Exits 
    } 
    }
    The error says "n" + ( dollar.format(sales) + (dollar.format(sales) + dollar.format(incentive) )) + "/n" +
    "n" + (( dollar.format(sales) + 5000)) + (dollar.format(sales) + dollar.format(incentive) )) + "/n";"

    is not valid statement





    The assignment is done but I am just having trouble with the table.

    The application should also display a table of potential total annual compensation that the salesperson could have earned, in $5000 increments above the salespersonís annual sales, until it reaches 50% above the salespersonís annual sales.


    That is instructions for table. Let me know what else is needed.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    Can you copy and paste the full text of the error message with a ^ under where the error is?

    Otherwise try breaking that huge compound statement up into smaller statements and build the final statement by concatenating them with the + operator.
    Either you will find the error when you do that
    or the error will be in a much shorter statement and easier to find.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0
    compilation info
    Main.java:44: error: not a statement
    "n" + (( dollar.format(sales) + 5000)) + (dollar.format(sales) + dollar.format(incentive) )) + "/n";
    ^
    1 error
    stdout
    Standard output is empty
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0
    This line is giving issues as well

    Code:
    JOptionPane.showMessageDialog (null,

    Code:
    JOptionPane.showMessageDialog (null,
       "n" + "Total Sales"    +    "Total Compensation" + "/n" +
       "n" + ( dollar.format(sales) + (dollar.format(sales) + dollar.format(incentive) )) + "/n" +
       "n" + (( dollar.format(sales) + 5000)) + (dollar.format(sales) + dollar.format(incentive) )) + "/n";
  8. #5
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    The position of the ^ might have moved when the message was posted as text.
    If so, wrap the text in code tags to preserve its position.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    6
    Rep Power
    0
    Here is my full project code:

    Code:
    package calculatorpart2;
     
    import java.text.DecimalFormat; //Imports decimal formatting that is used 
    import javax.swing.JOptionPane; //Imports OptionPane used to output
     
    /**
     * @author Darin M.
     */
    public class CalculatorPart2 {
     //public class is CalculatorPart2
        
        public static void main(String[] args) 
        {
           String input; //User input
           double salary; //Annual salary
           double rate; //Rate for commission
           double commission; //Amount of commission
           double sales; //Annual sales
           double pay; //Persons pay
           double incentive = 0; //Sum for incentive
     
           DecimalFormat dollar = new DecimalFormat("#,##0.00"); //Dollars
           DecimalFormat percent = new DecimalFormat("##0.0%"); //Percent
           input = JOptionPane.showInputDialog("Input annual salary"); //User inputs salary
           salary = Double.parseDouble(input);
           input = JOptionPane.showInputDialog("Input commission rate"); //User inputs commission rate
           rate = Double.parseDouble (input);
           input = JOptionPane.showInputDialog("Input sales target"); //User inputs sales target
           sales = Double.parseDouble (input);
     
          commission = rate * salary; //Formula for commission
           pay = commission + salary; //Formula for pay
           JOptionPane.showMessageDialog(null, "Commission rate is " +
            percent.format(rate) + ". The amount of pay is $" + dollar.format(pay));
     
              if (sales >=(.80 * sales) & sales<=45000)
                incentive = (.1 * sales);
              else if (sales >45000)
                incentive = (2.25 * .1 * sales);
             //Logic for incentive formula
        double tempTotal = sales;
        double stopTotal = sales * 1.5; //Sales multipled by the rate
        System.out.println("Total Sales   -   Total Compensation"); //Output to user
        while(tempTotal < sales * 1.5){ //Formula used
        System.out.println(tempTotal + "\t\t" + ((commission + tempTotal) * rate));
        tempTotal += 5000;
              
              System.exit(0); //Exits
    }
        }
    Apparently I am missing a bracket(s), the program does not need to ask for the annual salary since it is given, and the table don't work. I got a horrible grade on this assignment and it is very frustrating! I want to learn this so I need your guys' help to figure out what I did wrong so I can learn from it.

    Here is error report:
    Code:
     stdin copy
    Standard input is empty
     compilation info
    Main.java:50: error: reached end of file while parsing
        }
         ^
    1 error
      stdout
    Standard output is empty
    Thanks for any help.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    One way to keep from losing ending }s is to type it in immediately on the next line after typing in the beginning }
    Code:
      if(some condition here) {
    
      }
    Then go back and add the code inside the {}s.

    Also it helps if the } is directly below the start of the statement with the matching }. Your code does not do that.

    Some editors will find the matching bracket when you put the cursor just before one bracket and press some key combo (Ctrl and ] on mine), it will move the cursor to the matching bracket.
    Last edited by NormR; November 16th, 2013 at 07:23 PM.

IMN logo majestic logo threadwatch logo seochat tools logo