Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Sales Commission

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sales Commission

    This is my program and I am not getting the right output, it shows I do not have errors in the program what when I run it, it asks for the right information but it does not give the right results. This is what comes up in my output
    run:
    Enter Name and annual sales of first salesman: Rick, 92,000
     

    Exception in thread "main" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65) this is line 65, /**
    at java.lang.Integer.parseInt(Integer.java:504) this is line 504, throw NumberFormatException.forInputString(s);
    at java.lang.Integer.parseInt(Integer.java:527) this is line 527, return parseInt(s,10);
    at sales.commission.week.pkg4.SalesCommissionWeek4.ma in(SalesCommissionWeek4.java:73) this is line 73, /**
    Java Result: 1
    BUILD SUCCESSFUL (total time: 47 seconds)




    This is my program
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package sales.commission.week.pkg4;
    import java.io.IOException;
    import java.util.Scanner;
     
    /**
     *
     * @author reco
     */
    public class SalesCommissionWeek4 {
     
         Calculator obj1;
        Calculator obj2;
        float deficit;
        /*CommissionCalculator()*/{
            obj1 = new Calculator();
            obj2 = new Calculator();
     
        }
        public void setAttributes(int i, String s, int j, String l){
            obj1.setName(s);
            obj1.setAnnualSales(i);
            obj2.setName(l);
            obj2.setAnnualSales(j);
        }
        public void compare()
        {
            if(obj1.getTotalCompensation()<obj2.getTotalCompensation()){
     
                deficit = obj2.getTotalCompensation()-obj1.getTotalCompensation();
                if(obj1.getAnnualSales()<=120000){
                    System.out.print(obj1.getName()+" should increase his annual sales by "
                            + obj2.getCommission()/0.05);
                }
                if(obj1.getAnnualSales()>120000) {
                    System.out.print(obj1.getName()+" should increase his annual sales by "
                            + obj2.getCommission()/0.065);
                }
            }
     
            else if(obj2.getTotalCompensation()<obj1.getTotalCompensation()){
                deficit = obj1.getTotalCompensation()-obj2.getTotalCompensation();
     
                if(obj2.getAnnualSales()<=120000) {
                    System.out.print(obj2.getName()+" should increase his annual sales by "
                            + obj1.getCommission()/0.05);
                }
     
                if(obj2.getAnnualSales()>=120000) {
                    System.out.print(obj2.getName()+" should increase his annual sales by "
                            + obj1.getCommission()/0.065);
                }
            }
            else{
                System.out.print("Compensations are equal.");
                System.exit(0);
            }
        }
     
        public static void main(String[] args) throws IOException {
     
            Scanner read = new Scanner(System.in);
            String t1,t2;
            int i=0,j=0;
            Calculator obj = new Calculator();
     
            System.out.print("Enter Name and annual sales of first salesman: ");
            t1 = read.nextLine();
            String temp1 = read.nextLine();
            i=Integer.parseInt(temp1);
     
            System.out.print("Enter Name and annual sales of second salesman: ");
            t2 = read.nextLine();
     
            String temp2 = read.nextLine();
            j=Integer.parseInt(temp2);
     
            obj.setAttributes(i, t1, j, t2);
            obj.compare();
        }
    }
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package sales.commission.week.pkg4;
     
    /**
     *
     * @author reco
     */
    final class Calculator {
          private int income;
        private int annualSales;
        private float commission;
        private float totalCompensation;
        private String name;
        Calculator
                //</editor-fold>
    ()
        {
            annualSales=0;
            income=40000;
            commission=0;
            totalCompensation=0;
        }
        Calculator(int i, String s)
        {
            annualSales=i;
            income=40000;
            commission=0;
            totalCompensation=0;
            name=s;
            calcCommission();
        }
     
        public void setAnnualSales(int i){
            annualSales=i;
            calcCommission();
        }
         public void setName(String s){
            name=s;
        }
     
     
        public void calcCommission()
        {
            if(annualSales < 100000){
            totalCompensation = income;
            }
            else if(annualSales >= 100000 && annualSales <= 120000){
            commission = (float) (0.05 * annualSales);
            totalCompensation = commission+income;
            }
            else{
                commission = (float) (0.080 * annualSales);
                totalCompensation = commission+income;
            }
        }
     
        public float getTotalCompensation(){
            return totalCompensation;
        }
     
        public int getAnnualSales(){
            return annualSales;
        }
     
        public float getCommission()
        {
            return commission;
        }
        public String getName(){
            return name;
        }
        public void printTable()
        {
            float temp = annualSales;
            while(temp <= annualSales*1.5)
            {
            if(temp < 100000){
            totalCompensation = income;
            System.out.println("Total Compensation at sales "+temp+" is: "+totalCompensation);
            }
            else if(temp >= 100000 && temp <= 120000){
            commission = (float) (0.05 * annualSales);
            totalCompensation = commission+income;
            System.out.println("Total Compensation at sales "+temp+" is: "+totalCompensation);
            }
            else{
                commission = (float) (0.080 * annualSales);
                totalCompensation = commission+income;
                System.out.println("Total Compensation at sales "+temp+" is: "+totalCompensation);
            }
            temp += 5000;
            }
        }
     
        void setAttributes(int i, String t1, int j, String t2) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
     
        void compare() {
            throw new UnsupportedOperationException("Not yet implemented");
        }
     
     
    }
    Can someone help me please, I am confused.
    Last edited by helloworld922; February 5th, 2013 at 01:50 AM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sales Commission

    Exception in thread "main" java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65) this is line 65, /**
    at java.lang.Integer.parseInt(Integer.java:504) this is line 504, throw NumberFormatException.forInputString(s);
    at java.lang.Integer.parseInt(Integer.java:527) this is line 527, return parseInt(s,10);
    at sales.commission.week.pkg4.SalesCommissionWeek4.ma in(SalesCommissionWeek4.java:73)
    The String passed to the parseInt() method at line 73 did NOT contain a valid number. The code should either check that the String is not empty and/or it should catch the exception when the String is invalid.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sales Commission

    Quote Originally Posted by Norm View Post
    The String passed to the parseInt() method at line 73 did NOT contain a valid number. The code should either check that the String is not empty and/or it should catch the exception when the String is invalid.

    I am not sure what you mean is it somethong I need to add to my CommissionCalculation?

  4. #4
    Member
    Join Date
    Jan 2013
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sales Commission

    there was no variable to output or the code could not understand what to output.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Sales Commission

    somethong I need to add
    Yes, the code should test if there is input before trying to convert it.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Sales Generator
    By zbailey in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 21st, 2013, 04:00 PM
  2. Simple Commission Calculator
    By mrivera8504 in forum What's Wrong With My Code?
    Replies: 22
    Last Post: August 27th, 2012, 06:35 PM
  3. [SOLVED] Calculating Commission with a GUI???
    By jbarcus81 in forum AWT / Java Swing
    Replies: 13
    Last Post: February 25th, 2012, 07:35 AM