Results 1 to 6 of 6
  1. #1
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Question Cannot understand error concerning class call

    Hi all,
    I am trying to complete a project where I take user input, and use it to calculate annual payrates for employees based on a scaling commission determined by their actual sales amounts.... I need to use three separate files containing various classes to accomplish this task, but I have hit a serious snag, and cannot understand why.
    Anyway here is the code from my three class files:
    Java Code:
    package Annual;
    import annual.EvalNum;
    import java.util.*;
    public class Pay {
        private class Number{
            EvalNum[] E = new EvalNum[8];         
        }
        public static void main(String[] args)           
        {                 
            double T = 50000; //set value for base salary                
            double Amt; //declare variable for final pay
            int x = 1;        
         do{
          try{ //validate user input
            Scanner percent = new Scanner(System.in);
            System.out.println("Please enter annual sales:");//request user input
            System.out.println("Please enter valid dollar value:");
            double yearly = percent.nextDouble(); //store user input
               if (yearly >= 0 && yearly <= 500000){ //if over $500,000.00 in sales
               if (yearly >80000){ //if 80% sales goal was not reached
            double YrPrcnt = yearly * .05; //value used for compensation set next
            Amt = T + YrPrcnt * 1.25; //set Amt to pay plus commissions
            System.out.print("The Annual Payrate for employee is: $");
            System.out.println(Amt);}
               else {
                 System.out.print("The Annual Payrate for employee is: $"); 
                 System.out.println(T);
                 System.out.println();}}
                  else {
               System.err.print("Sales too high, ");
               System.err.println("please see Human Resources.");}
               x++; break;}
            catch(Exception e){ //if user input throws exception
                System.out.println("Try again please");}}while(x==1);
         CompensationChart C = new CompensationChart();
              C.ListIt();}}
    which is supposed to call this class:
    Java Code:
    package annual;
    import java.util.*;
    public class EvalNum
    {  public void howMany(String args[]){
    int Evals;        
    Scanner EmpNum = new Scanner(System.in);
    System.out .println("How many employees to be evaluated?");
    Evals = EmpNum.nextInt();
    System.out.println(Evals);}}
    to determine how many employees will be evaluated, and then after completing this part, call this class:
    Java Code:
    package Annual;
    public class CompensationChart {
        
    public void ListIt(){
           System.out.println ("Salesperson regular wages = $50,000");
                 // 80% of sales computed / Target = 100000 * 80%.              
           System.out.println("Sales Target is:");
           System.out.println ("$100,000 * 80% = $80,000");
           // 5% commission / commission = 5% * $100,000;
           System.out.println ("100,000 * 5% = $5000");
           // Commission with acceleration factor / Commission = 5% + 1.25
           System.out.println ("5% + 1.25 = 6.25%");
            // Return possible amount....
            // Sales with increment and 1.25 acceleration
            // factor until 50% of annaul sales / Sales = 50% + 6.25%;
            System.out.println ("50% + 6.25% = 56.25% ");        
            // Potential compensation = 100,000 / 56.25%;
            System.out.println ("$100,000 / 56.25% = $56,250");
            // Possible compensation by sales;
            // Return possible payrates including commissions;
            System.out.println("Potential compensations based on sales:");
            System.out.println("-------------------------------------");
            System.out.println ("$100,000 * 5% = $5,000");
            System.out.println ("$100,000 + $5,000 = Total Sales $105,000");
            System.out.println ("$105,000 / 56.25% = $56,562.50");
            System.out.println ("$110,000 / 56.25% = $61,875");
            System.out.println ("$115,000 / 56.25% = $64,687.50");
            System.out.println ("$120,000 / 56.25% = $67,500");
            System.out.println ("$125,000 / 56.25% = $70,312.50");
            System.out.println ("$130,000 / 56.25% = $73,125");
            System.out.println ("$135,000 / 56.25% = $75,937.50");
            System.out.println ("$140,000 / 56.25% = $78,750");
            System.out.println ("$145,000 / 56.25% = $81,562.50");
            System.out.println ("$150,000 / 56.25% = $84,375");}
       }
    //end program....}}
    to return a chart of potential compensation rates within a specified range of the employee's salary and commission rate.
    At least, that is the plan, but for some unexplained reason, the Pay class, main class, will not accept my call to the EvalNum class, and keeps saying object variable that I set to call EvalNum is not declared?? Cannot understand error concerning class call-wtf.jpg Which makes no sense to me, because I know the code is right, as using the exact same method works farther down in the class Pay here, Cannot understand error concerning class call-worksfinehere.jpg
    Well, for whatever reason, it won't accept the same call near the beginning of the program as shown:
    Java Code:
    package Annual;
    import annual.EvalNum;
    import java.util.*;
    public class Pay {
        private class Number{
            EvalNum[] E = new EvalNum[8];   
            E.howMany();                                 //THIS IS CORRECT.... WHAT?? 
        }
        public static void main(String[] args)           
        {   
                  
            double T = 50000; //set value for base salary                
            double Amt; //declare variable for final pay
            int x = 1;        
         do{
          try{ //validate user input
            Scanner percent = new Scanner(System.in);
            System.out.println("Please enter annual sales:");//request user input
            System.out.println("Please enter valid dollar value:");
            double yearly = percent.nextDouble(); //store user input
               if (yearly >= 0 && yearly <= 500000){ //if over $500,000.00 in sales
               if (yearly >80000){ //if 80% sales goal was not reached
            double YrPrcnt = yearly * .05; //value used for compensation set next
            Amt = T + YrPrcnt * 1.25; //set Amt to pay plus commissions
            System.out.print("The Annual Payrate for employee is: $");
            System.out.println(Amt);}
               else {
                 System.out.print("The Annual Payrate for employee is: $"); 
                 System.out.println(T);
                 System.out.println();}}
                  else {
               System.err.print("Sales too high, ");
               System.err.println("please see Human Resources.");}
               x++; break;}
            catch(Exception e){ //if user input throws exception
                System.out.println("Try again please");}}while(x==1);
         CompensationChart C = new CompensationChart();
              C.ListIt();}}                     //SEE, IT WORKS FINE HERE!!
    This is really starting to make me sick here. If anyone can tell me why this program refuses to properly call my external class, despite that fact that the code should all be right, I will be eternally in your debt!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot understand error concerning class call

    Again, you're calling a method inside of a class, Number, but not inside of any method or constructor. This is the same problem that I pointed out previously. As an aside, that method again should return the int that the user enters, as discussed previously, again that method should not take parameters be they String array or anything.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot understand error concerning class call

    Please post your exact instructions, because I wonder whether you should scrap this and start over.

  4. #4
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Cool Re: Cannot understand error concerning class call

    Quote Originally Posted by Fubarable View Post
    Again, you're calling a method inside of a class, Number, but not inside of any method or constructor. This is the same problem that I pointed out previously. As an aside, that method again should return the int that the user enters, as discussed previously, again that method should not take parameters be they String array or anything.
    Thank you again....

    I will see about adding a method to call the other method and check back if it gives me too much grief, but again, thanks for taking the time here!!

  5. #5
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Posts
    57
    Rep Power
    0

    Thumbs up Re: Cannot understand error concerning class call

    Quote Originally Posted by Fubarable View Post
    Please post your exact instructions, because I wonder whether you should scrap this and start over.
    What I need to do is create a payroll program, using three separate files that call on each other. This program should acquire user input in the form of a number of employees to be evaluated (EvalNum.java), the names of the employee(s) - Pay.java, the amount of yearly sales for the employee(s) - Pay.java. Upon receiving this information from the user, the program must then calculate the individual annual pay for each employee evaluated, return this to the user, and after providing the individual salary for each employee evaluated, return a chart of potential commission based salary ranges(CompensationChart).

    This could all be done in one file, I know, but that is not the task which has been placed on me here, so I have to figure out a way to split up what should be a very simple program into three separate files, hence my confusions here.
    Anyway, I do appreciate the time you have taken here, and apologize if you had to answer the same questions repeatedly....

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Cannot understand error concerning class call

    So based on the instructions it appears to me that your program structure should be:

    EvalNum.java: this class has one and only one static method that takes no parameters and returns an int that represents the number of employees to be evaluated.

    Pay.java: this class will perhaps have 2 static methods, one static method that takes an int parameter so that it knows how many employees there are, and that returns an array of String representing the employee names, and the other static method that again takes a single int parameter for the same reason and returns an array of int or double which represents the employees' yearly sakes

    CompensationChart.java: this class has the main method and calls the methods from the other two classes. In addition, it has static methods to calculate pay and to create and display a compensation chart.

Similar Threads

  1. I don't understand this error....
    By Lund01 in forum XML
    Replies: 13
    Last Post: 07-10-2011, 12:40 AM
  2. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  3. Can you help me understand how to use this class.
    By AcousticBruce in forum New To Java
    Replies: 4
    Last Post: 12-30-2010, 03:57 AM
  4. I don't understand the error ... (help!)
    By XmisterIS in forum New To Java
    Replies: 3
    Last Post: 09-02-2010, 09:33 AM
  5. i don understand this error
    By Deon in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 10:03 AM

Tags for this Thread

Posting Permissions

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