Implementing methods in a class

I have a class called Employee that uses getters and seters and methods from another project. I brought the code from the methods into the Employee class to run them in my class. It is supose to calculate an employee's monthly income plus commission and a seniority bonus based on years. When I compile the class I get errors. I was wondering if you java experts can look and see what my problem is. Here is the code and errors, thanks...
public class Employee
     private String firstName, lastName,
          address, city, state,zipCode;
     private short seniority = 0;
     private double baseSalary = 500;
     private Company company;
     //constructor
     public Employee(String fn, String ln, String a, String c, String s,
          String zc, short newSeniority, double newBs, Company newCompany){
          firstName = fn;
          lastName = ln;
          address = a;
          city = c;
          state = s;
          zipCode = zc;
          seniority = newSeniority;
          baseSalary = newBs;
          company = newCompany;
     public Employee(){
          firstName = "";
          lastName = "";
          address = "";
          city = "";
          state = "";
          zipCode = "";
     public double computeCommision(double weeklyPay) {
          double thisCommission;   
       if(weeklyPay < baseSalary)
              thisCommission = 0.00;   
       else if(weeklyPay < 1000.00)
          thisCommission = weeklyPay * .05;   
       else if(weeklyPay < 5000.00)
          thisCommission = weeklyPay * .08;   
       else if(weeklyPay >= 5000.00)
          thisCommission = weeklyPay * .10 + 400;   
       else thisCommission = 0.00;  
       return thisCommission;
     public double bonus(double weeklyPay, int yearsWorked) {
          short seniority;
        double thisCommission = computeCommission(weeklyPay);
        if (yearsWorked >= 2) // No bonus for less than two years
             seniority = (weeklyPay * yearsWorked)/100;
        return seniority;
     public double payroll() {
          double payroll = 0.0, pay, commission, bonus, years;
        System.out.println("\nPlease enter the years you have worked for this company:");
        int response = MyInput.readInt();
        for (int i = 0; i < 4; i++)
        System.out.println("\nPlease enter you salary for week "  + (i+1) + ": ");
        pay = MyInput.readDouble();
        commission =  computeCommission(pay);
        bonus = bonus((commission + pay), response);
        payroll = payroll + pay + commission + bonus;     
        return payroll;
     public String getFirstName() { return firstName; }
     public void setFirstName(String fn) { firstName = fn; }
     public String getLastName() { return lastName; }
     public void setLastName(String ln) { lastName = ln; }
     public String getAddress() { return address; }
     public void setAddress(String a) { address = a; }
     public String getCity() { return city; }
     public void setCity(String c) { city = c; }
     public String getState() { return state; }
     public void setState(String s)     { state = s; }
     public String getZipCode()     { return zipCode; }
     public void setZipCode(String zc) { zipCode = zc; }
     public short getSeniority() { return seniority; }
     public void setSeniority(short newSeniority) { seniority = newSeniority; }
     public double getBaseSalary() { return baseSalary; }
     public void setBaseSalary(double newBs) { baseSalary = newBs; }
     public Company getCompany() { return company; } //getter method for company in company class
     public void setBank(Company newCompany) { company = newCompany; }
}   and the errors are :
C:\cis163\Project5_1\src\Employee.java:59: cannot resolve symbol
symbol : method computeCommission (double)
location: class Employee
double thisCommission = computeCommission(weeklyPay);
^
C:\cis163\Project5_1\src\Employee.java:62: possible loss of precision
found : double
required: short
seniority = (weeklyPay * yearsWorked)/100;
^
C:\cis163\Project5_1\src\Employee.java:70: cannot resolve symbol
symbol : variable MyInput
location: class Employee
int response = MyInput.readInt();
^
C:\cis163\Project5_1\src\Employee.java:75: cannot resolve symbol
symbol : variable MyInput
location: class Employee
pay = MyInput.readDouble();
^
C:\cis163\Project5_1\src\Employee.java:76: cannot resolve symbol
symbol : method computeCommission (double)
location: class Employee
commission = computeCommission(pay);
^
5 errors

ok, sorry. I wasnt clear on what you were saying. MyInput.java is in the same folder when I compiled it. I changed my code around a little, changed some variables so it was easier for me to understand. I am still getting several errors after I wrote code for the Project which I called project5. Not sure where I am going wrong but I will post my classes and main to see if anyone can help me out.
//Company class
public class Company
    private String companyName;
     private String companyAddress;
     private String companyCity;
     private String companyState;
     private String companyZip ;
     //Constructor method
     public Company(String cn, String ca, String cc, String cs, String cz) {
          companyName = cn;         
          companyAddress = ca;         
          companyCity = cc;         
          companyState = cs;         
          companyZip = cz;
    public Company(){
         companyName = "";
         companyAddress = "";
         companyCity = "";
         companyState = "";
         companyZip = "";
     public String getName() { return companyName; }
    public void setName(String cn) { companyName = cn; }
     public String getAddress() { return companyAddress; }
    public void setAddress(String ca){ companyAddress = ca; }
    public String getCity() { return companyCity; }
    public void setCity(String cc) { companyCity = cc; }     
    public String getState() { return companyState; }     
    public void setState(String cs) { companyState = cs; }
    public String getZip()     { return companyZip; }     
    public void setZip(String cz) { companyZip = cz; }
//Employee class
public class Employee
     private String employeeFName, employeeLName,employeeAddress,
          employeeCity, employeeState, employeeZip;
     private short seniority = 0;
     private double baseSalary = 500;
     private Company company;
     //constructor
     public Employee(String efn, String eln, String ea, String ec, String es,
          String ez, short newSeniority, double newBs, Company newCompany){
          employeeFName = efn;
          employeeLName = eln;
          employeeAddress = ea;
          employeeCity = ec;
          employeeState = es;
          employeeZip = ez;
          seniority = newSeniority;
          baseSalary = newBs;
          company = newCompany;
     public Employee(){
          employeeFName = "";
          employeeLName = "";
          employeeAddress = "";
          employeeCity = "";
          employeeState = "";
          employeeZip = "";
     public double computeCommission(double weeklyPay) {
          double thisCommission;   
       if(weeklyPay < baseSalary)
              thisCommission = 0.00;   
       else if(weeklyPay < 1000.00)
          thisCommission = weeklyPay * .05;   
       else if(weeklyPay < 5000.00)
          thisCommission = weeklyPay * .08;   
       else if(weeklyPay >= 5000.00)
          thisCommission = weeklyPay * .10 + 400;   
       else thisCommission = 0.00;  
       return thisCommission;
     public double bonus(double weeklyPay, int yearsWorked) {
          short seniority;
        double thisCommission = computeCommission(weeklyPay);
        if (yearsWorked >= 2) // No bonus for less than two years
             seniority = (short) ((weeklyPay * yearsWorked)/100);
        return seniority;
     public double payroll() {
          double payroll = 0.0, pay, commission, bonus, years;
        System.out.println("\nPlease enter the years you have worked for this company:");
        int response = MyInput.readInt();
        for (int i = 0; i < 4; i++)
        System.out.println("\nPlease enter you salary for week "  + (i+1) + ": ");
        pay = MyInput.readDouble();
        commission =  computeCommission(pay);
        bonus = bonus((commission + pay), response);
        payroll = payroll + pay + commission + bonus;     
        return payroll;
     public String getFirstName() { return employeeFName; }
     public void setFirstName(String efn) { employeeFName = efn; }
     public String getLastName() { return employeeLName; }
     public void setLastName(String eln) { employeeLName = eln; }
     public String getAddress() { return employeeAddress; }
     public void setAddress(String ea) { employeeAddress = ea; }
     public String getCity() { return employeeCity; }
     public void setCity(String ec) { employeeCity = ec; }
     public String getState() { return employeeState; }
     public void setState(String es)     { employeeState = es; }
     public String getZipCode()     { return employeeZip; }
     public void setZipCode(String ez) { employeeZip = ez; }
     public short getSeniority() { return seniority; }
     public void setSeniority(short newSeniority) { seniority = newSeniority; }
     public double getBaseSalary() { return baseSalary; }
     public void setBaseSalary(double newBs) { baseSalary = newBs; }
     public Company getCompany() { return company; } //getter method for company in company class
     public void setBank(Company newCompany) { company = newCompany; }
public class Project5 { //Beginning of class Project5
public static void main (String args[]) { //Beginning of main
        //Company
        String companyName = "";
        String companyAddress = "";
        String companyCity = "";
        String companyState = "";
        String companyZip = "";
        // Creates a new Company object called aCompany
        Company aCompany = new Company( companyName, companyAddress,
             companyCity, companyState, companyZip );
        // Prompts user about information about company
        // and sets fields for the Company object.
        System.out.println( "***Company Information***" );
        System.out.println( "Please enter information about company:");
        System.out.println();
        System.out.print( "Company name: " );
        companyName = MyInput.readString();
        aCompany.setName( companyName );
        System.out.print( "Company address: " );
        companyAddress = MyInput.readString();
        aCompany.setAddress( companyAddress );
        System.out.print( "Company city: " );
        companyCity = MyInput.readString();
        aCompany.setCity( companyCity );
        System.out.print( "Company state: " );
        companyState = MyInput.readString();
        aCompany.setState( companyState );
        System.out.print( "Company zip: " );
        companyZip = MyInput.readString();
        aCompany.setZip( companyZip );
        System.out.println();
        // Employee
        String employeeFName = "";
        String employeeLName = "";
        short seniority = 0;
        String employeeAddress = "";
        String employeeCity = "";
        String employeeState = "";
        String employeeZip = "";
        // Creates a new Employee object called anEmployee who works for the above company.
        Employee anEmployee = new Employee( employeeFName,employeeLName, seniority,
             employeeAddress, employeeCity, employeeState, employeeZip, aCompany );
        // Prompts user about information about employee
        // and sets fields for the Employee object.
        System.out.println( "***Employee Information***" );
        System.out.println( "Please enter information about an employee:");
        System.out.println();
        System.out.print( "Employee first name: " );
        employeeFName = MyInput.readString();
        anEmployee.setFirstName( employeeFName );
        System.out.print( "Employee last name: " );
        employeeLName = MyInput.readString();
        anEmployee.setLastName( employeeLName );
        System.out.print( "Employee address: " );
        employeeAddress = MyInput.readString();
        anEmployee.setAddress( employeeAddress );
        System.out.print( "Employee city: " );
        employeeCity = MyInput.readString();
        anEmployee.setCity( employeeCity );
        System.out.print( "Employee state: " );
        employeeState = MyInput.readString();
        anEmployee.setState( employeeState );
        System.out.print( "Employee zip: " );
        employeeZip = MyInput.readString();
        anEmployee.setZip( employeeZip );
        System.out.print( "How many years the employee has been with the company? : " );
        seniority = (short)MyInput.readInt();
        anEmployee.setSeniority( seniority );
        System.out.println();
        // Displays company information
        System.out.println( "*** Company Information Summary ***" );
        System.out.println( "Company name:    " + aCompany.getName());
        System.out.println( "Company address: " + aCompany.getAddress() );
        System.out.println( "Company city:    " + aCompany.getCity() );
        System.out.println( "Company state:   " + aCompany.getState() );
        System.out.println( "Company zip:     " + aCompany.getZip() );
        System.out.println();
        // Displays employee information
        System.out.println( "*** Employee Information Summary ***");
        System.out.println( "Employee firstName:  " + anEmployee.getFirstName() );
        System.out.println( "Employee lastName:   " + anEmployee.getLastName() );
        System.out.println( "Employee seniority:  " + anEmployee.getSeniority() );
        System.out.println( "Employee baseSalary: $" + anEmployee.getBaseSalary() );
        System.out.println( "Employee address:    " + anEmployee.getAddress() );
        System.out.println( "Employee city:       " + anEmployee.getCity() );
        System.out.println( "Employee state:      " + anEmployee.getState() );
        System.out.println( "Employee zip:        " + anEmployee.getZip() );
        // We retrieve the company name from anEmployee object.
        System.out.println( "Company name the employee works for: "
             + anEmployee.getCompany().getName() );
        // Calls payroll() to calculate one month salary
        System.out.println();
        System.out.println( "*** Calculate monthly pay *** " );
        double oneMonthSalary = anEmployee.payroll(); // Calls payroll()
        DecimalFormat myDecimalFormat = new DecimalFormat( "0.00" );
// Instantiate DecimalFormat object
        // Format one month salary and display to console
        System.out.println();
        System.out.println( "One month salary is: $" + myDecimalFormat.format(oneMonthSalary) );
        System.out.println();
}sorry, its alot. I'm getting 18 errors, which are:
C:\cis163\Project5_1\src\Project5.java:24: cannot resolve symbol
symbol : variable MyInput
location: class Project5
companyName = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:28: cannot resolve symbol
symbol : variable MyInput
location: class Project5
companyAddress = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:32: cannot resolve symbol
symbol : variable MyInput
location: class Project5
companyCity = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:36: cannot resolve symbol
symbol : variable MyInput
location: class Project5
companyState = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:40: cannot resolve symbol
symbol : variable MyInput
location: class Project5
companyZip = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:56: cannot resolve symbol
symbol : constructor Employee (java.lang.String,java.lang.String,short,java.lang.String,java.lang.String,java.lang.String,java.lang.String,Company)
location: class Employee
Employee anEmployee = new Employee( employeeFName,employeeLName, seniority,
^
C:\cis163\Project5_1\src\Project5.java:66: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeFName = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:70: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeLName = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:74: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeAddress = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:78: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeCity = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:82: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeState = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:86: cannot resolve symbol
symbol : variable MyInput
location: class Project5
employeeZip = MyInput.readString();
^
C:\cis163\Project5_1\src\Project5.java:87: cannot resolve symbol
symbol : method setZip (java.lang.String)
location: class Employee
anEmployee.setZip( employeeZip );
^
C:\cis163\Project5_1\src\Project5.java:90: cannot resolve symbol
symbol : variable MyInput
location: class Project5
seniority = (short)MyInput.readInt();
^
C:\cis163\Project5_1\src\Project5.java:114: cannot resolve symbol
symbol : method getZip ()
location: class Employee
System.out.println( "Employee zip: " + anEmployee.getZip() );
^
C:\cis163\Project5_1\src\Project5.java:127: cannot resolve symbol
symbol : method payroll ()
location: class Employee
double oneMonthSalary = anEmployee.payroll(); // Calls payroll()
^
C:\cis163\Project5_1\src\Project5.java:129: cannot resolve symbol
symbol : class DecimalFormat
location: class Project5
DecimalFormat myDecimalFormat = new DecimalFormat( "0.00" );
^
C:\cis163\Project5_1\src\Project5.java:129: cannot resolve symbol
symbol : class DecimalFormat
location: class Project5
DecimalFormat myDecimalFormat = new DecimalFormat( "0.00" );
^
18 errors

Similar Messages

  • CRM 7.0 implement method from MVC class

    Hello, folks.  I will prefix my question with the fact that I am a relative dinosaur in the development arena, still focused primarily procedural coding practices.  Although this still serves me well, it also means that I know little about OO development.  I have had some training and can make use of such common tools as OO ALV.  However, I know next to nothing about MVC (model view controller) programming, WEB Dynpro for ABAP, etc.  I am currently assigned to a CRM project (I am also new to CRM) and have a particular requirement that I cannot seem to address with any sort of procedural-based solution (i.e. function module).
    My requirement is to create a "URL Attachment" to a service request in CRM.  To elaborate, I have created an inbound point-to-point interface (i.e. not PI/XI) from an external system using Web Services.  The Web Service I have created ultimately invokes a call to function CRMXIF_ORDER_SAVE via a wrapper function I developed with the same interface.  This function, however, does not support the creation of "URL Attachments", only "Attachment Links".  So, my approach then is to implement additional functionality in my wrapper function to create this URL Attachment via some other means.  If you have any questions regarding URL Attachments vs. Attachment Links, please let me know.
    I have scoured the function modules to no avail.  What I have found is that via MVC, the functionality on the CRM Web UI is associated with the following class: CL_GS_CM_ADDURL_IMPL.  A search in SE24 reveals that there are actually several related? classes:
    CL_GS_CM_ADDURL
    CL_GS_CM_ADDURL_CN02
    CL_GS_CM_ADDURL_CN03
    CL_GS_CM_ADDURL_CTXT
    CL_GS_CM_ADDURL_IMPL
    My question is whether I can somehow implement one of these classes to address my requirement.  Looking at the logic within the IP_TO_ADDURL method, I cannot figure out whether I can somehow leverage this and, if so, exactly what coding would be required in my wrapper function.  I should also point that, at least from a Web UI point of view, this is a two step process whereby you must first create the attachment and the actually save it. 
    Any and all insights are much appreciated.
    Thanks.

    Hi there,
    I am not familiar with the CRM classes you mention - but what you describe is pretty much standard functionality included in Generic Object Services. May that path will lead you home.
    Cheers
    Graham Robbo

  • Implement method inside abstract class?

    hello everyone:
    I have a question regarding implementation of method inside a abstract class. The abstract class has a static method to swamp two numbers.
    The problem ask if there is any output from the program; if no output explain why?
    This is a quiz question I took from a java class. I tried the best to recollect the code sample from my memory.
    if the code segment doesn't make sense, could you list several cases that meet the purpose of the question. I appreciate your help!
    code sample
    public abstract class SwampNumber
       int a = 4;
       int b = 2;
       System.out.println(a);
       System.out.println(b);
       swamp(a, b);
       public static void swamp(int a, int b)
         int temp = a;
             a = b;
             b = a;
         System.out.println(a);
         System.out.println(b);

    It won't compile.
    You can't instantiate an abstract class before you know anything.
    //somewhere in main
    SwampNumber myNum = new SwampNumber();
    //Syntax ErrorQuote DrClap
    This error commonly occurs when you have code that >>is not inside a method.
    The only statements that can appear outside methods >>in a Java class are >>declarations.Message was edited by:
    lethalwire

  • Problem implementing Methods in a class

    Hi,
    I am trying to change this code :
    import java.util.Scanner;
    public class Test {
    public static void main(String[]args) {
    Scanner stdin = new Scanner(System.in);
    System.out.print("Number: ");
    double n = stdin.nextDouble();
    System.out.println(n + " * " + n + " = " + n*n);
    So that instead of everytime that I get in I have to create an a new state,
    I want to create it an object that could be access for every class
    and I did this but is not running:
    import java.util.Scanner;
    public class Miguel {
    public static void main(String[]args) {
    public double calc(double n)
    Scanner stdin = new Scanner(System.in);
    System.out.print("Number: ");
    double n = stdin.nextDouble();
    System.out.println(n + " * " + n + " = " + n*n);
    return n
    System.out.println(calc());
    }

    and I did this but is not running:Not only that, it's not compiling. You can't declare methods within methods, as you have done by attempting to declare calc() inside of main().
    When you post code, please post it between [code] and [/code] tags (you can just use the "code" button on the message posting screen). It makes your code much easier to read by preserving the original spacing, adding syntax highliting, and it prevents accidental markup from array indices like [i].

  • Implementation method SEARCH_FOR_NEXT_PROCESSOR of Class PT_GEN_REQ

    Hi All,
    we are trying to implement BADI u201CFind next processoru201D  of the implementation PT_GEN_REQ and we would like to filter the next processor according to the absence/attendance type which is not one of parameters of the method SEARCH_FOR_NEXT_PROCESSOR.
    Is there a way to do so?
    Thanks in advace for your help,
    Amedeo

    Hi Harald,
    to check the user defined entries, I suggest you implement it in the START_WF method. There's a method call:
        CALL METHOD lc_step->agent_append
          EXPORTING
            agent          = l_agent
          EXCEPTIONS
            already_exists = 1
            locked         = 2
            OTHERS         = 3.
    which adds the agents to the recipient list. The validation could be put before this I think.
    Hope this helps,
    Mikko

  • Calling an implemented method from an external class.

    Hey guys...
    I'm writing a package to be put into a program I'm writing for a project (for Uni), but I also want to use the package in other programs.
    Basically, the package will return a JScrollPane that can be put into any JFrame or JPanel or whatever.
    It draws boxes on the JScrollPane in different colours and locations depending on what information is passed to it (kind of like iCal or Microsoft Outlook Calendar), and is to be used for a Resource Allocation Program that requires drag and drop of boxes for moving bookings around etc.
    http://www.pixel2.com.au/ethos/class_diagram.png
    This is a copy of the class diagram for the relevant classes. ViewFrame is the class that instantiates the JScrollPane (AllocationTable). It implements the AllocationInterface to implement methods such as moveAllocation() newAllocation() etc.
    BookingPanel is the content pane for the JScrollPane. AllocatedBox is the individual bookings, or boxes that are painted onto the BookingPanel.
    BookingPanel implements ActionListener, MouseListener and MouseMotionListener, which enables drag and drop functionality.
    What I want to do, is when mouseReleased() is called by dropping a box, call the method moveAllocation() in ViewFrame to make the changes to the database to move the booking around.
    I don't know how to access that from BookingPanel as the name of ViewFrame will change obviously for different programs.
    If you could help me out, that would be great!
    If you need anything else explained, please let me know.
    Thanks,
    Ryan.

    LeRyan wrote:
    Hey guys...
    I'm writing a package to be put into a program I'm writing for a project (for Uni), but I also want to use the package in other programs.
    Basically, the package will return a JScrollPane that can be put into any JFrame or JPanel or whatever.I think you have some terminology issues that might stand in your way of getting help or understanding the issues. A Package is a grouping of classes, so a package doesn't return anything...
    It draws boxes on the JScrollPane in different colours and locations depending on what information is passed to it (kind of like iCal or Microsoft Outlook Calendar), and is to be used for a Resource Allocation Program that requires drag and drop of boxes for moving bookings around etc.So from your description of the function of this thing, I think you mean a class - some sort of JComponent?
    >
    http://www.pixel2.com.au/ethos/class_diagram.png
    This is a copy of the class diagram for the relevant classes. ViewFrame is the class that instantiates the JScrollPane (AllocationTable). It implements the AllocationInterface to implement methods such as moveAllocation() newAllocation() etc.
    BookingPanel is the content pane for the JScrollPane. AllocatedBox is the individual bookings, or boxes that are painted onto the BookingPanel.
    BookingPanel implements ActionListener, MouseListener and MouseMotionListener, which enables drag and drop functionality.
    What I want to do, is when mouseReleased() is called by dropping a box, call the method moveAllocation() in ViewFrame to make the changes to the database to move the booking around.
    I don't know how to access that from BookingPanel as the name of ViewFrame will change obviously for different programs.
    If I follow, and I am not sure that I do - you want a reference to the ViewFrame in the BookingPanel. So either on construction of the BookingPanel via a parameter in the constructor, or as a separate step via a setter, place a reference to the ViewFrame in BookingPanel. Then when you call mouseReleased you can call moveAllocation through that reference.
    If you could help me out, that would be great!
    If you need anything else explained, please let me know.
    Thanks,
    Ryan.

  • Question about methods in a class that implements Runnable

    I have a class that contains methods that are called by other classes. I wanted it to run in its own thread (to free up the SWT GUI thread because it appeared to be blocking the GUI thread). So, I had it implement Runnable, made a run method that just waits for the thread to be stopped:
    while (StopTheThread == false)
    try
    Thread.sleep(10);
    catch (InterruptedException e)
    //System.out.println("here");
    (the thread is started in the class constructor)
    I assumed that the other methods in this class would be running in the thread and would thus not block when called, but it appears the SWT GUI thread is still blocked. Is my assumption wrong?

    powerdroid wrote:
    Oh, excellent. Thank you for this explanation. So, if the run method calls any other method in the class, those are run in the new thread, but any time a method is called from another class, it runs on the calling class' thread. Correct?Yes.
    This will work fine, in that I can have the run method do all the necessary calling of the other methods, but how can I get return values back to the original (to know the results of the process run in the new thread)?Easy: use higher-level classes than thread. Specifically those found in java.util.concurrent:
    public class MyCallable implements Callable<Foo> {
      public Foo call() {
        return SomeClass.doExpensiveCalculation();
    ExecutorService executor = Executors.newFixedThreadPool();
    Future<Foo> future = executor.submit(new MyCallable());
    // do some other stuff
    Foo result = future.get(); // get will wait until MyCallable is finished or return the value immediately when it is already done.

  • Implementing UIApplicationDelegate protocol methods in NSObject class not working.

    Hi Everyone,
    I am new bee in iphone developement. I want to implement UIApplicationDelegate protocol methods in one of my NSObject class, how can i implement that help me please.
    I have mentioned the sample code what acutal i want to impelment.
    .h file
    @interface SmaplClass : NSObject <UIApplicationDelegate>
    .m file
    - (void)applicationWillResignActive:(UIApplication *)application
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
    Want to implement the above methods is NSObject class to be implemented or used, its not working. Help me can do it.
    Please help me
    Thanks,

    I complete the above discussion with saying that it is better to implement the notification handling methods in your app delegate. If there are good reasons to not to do so, you have to implement the methods in another class, instantiate the class, and call the methods from the actual UIApplicationDelegate protocol methods in the AppDelegate object. This way you can remove the actual notification handling code from AppDelegate class.
    For example, suppose you implemented the methods in the class called Test. This is a sample code in the AppDelegate class:
    @implementation AppDelegate
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
          Test *t = [[Test alloc] init];
         [t application: application didReceiveRemoteNotification: userInfo];
    @end
    Or you can create an association relationship between the AppDelegate and Test, so you do not have to create a new Test instance in each of the remote notification handling methods:
    @interface AppDelegate {
         Test *test;
    @end
    @implementation AppDelegate
    + (id)init {
         if (self = [super init]) {
              test = [[Test alloc] init];
         return self;
    - (void)dealloc {
         [test release];
         [super dealloc];
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
         // No need to create a Test instance. You just forward the call from AppDelegate instance to test      // instance
         [test application: application didReceiveRemoteNotification: userInfo];
    @end

  • Error When Trying to POST: Method not implemented in data provider class

    Hi Experts,
    I have created an Odata Service using Netweaver Gateway Service builder. I am using Advanced Rest Client to test the service. I can successfully GET my data, but I run into issues when I try and POST new data.
    When trying to POST, I used the GET method to get the x-csrf-token, and added it to my header. I also updated the body XML with the data that I would like to POST. However, after sending the POST request, I am getting a "500 Internal Service Error" with the xml message "Method '<OdataServiceName>'_CREATE_ENTITY" not implemented in data provider class".
    Any help on this would be greatly appreciated. Thanks!

    Hi Kelly,
    Can you share screenshots of the error? Maybe something wrong with payload :can you share the same also? Did you try to debug it by putting a breakpoint in the CREATE_ENTITY method in the backend? Any luck?
    Regards,
    JK

  • How to check (programmatic) existence of a method in a class implementation

    Hi
    I need to check the existence of method in a class in a programmatic way and call it only when it is available otherwise proceed with subsequent steps in my ABAP OO Program. Is there way to do it? This is needed in a customer exit situation and each task is implemented with method and not all tasks would have methods implemented.
    Any feedback is greatly appreciated.
    Thanks

    When you try to call the method dynamically and ifthe method doesn't exist, system would complain by raising the exception cx_sy_dyn_call_illegal_method. You can Catch this exception when you call the method.
    CLASS lcl_test DEFINITION.
      PUBLIC SECTION.
        METHODS:
          check_exist.
    ENDCLASS.                    "lcl_test DEFINITION
    DATA: lo_test TYPE REF TO lcl_test.
    DATA: lv_method TYPE char30.
    lv_method = 'GET_DATA'.
    CREATE OBJECT lo_test.
    TRY.
        CALL METHOD lo_test->(lv_method).
      CATCH cx_sy_dyn_call_illegal_method.
    ENDTRY.
    CLASS lcl_test IMPLEMENTATION.
      METHOD check_exist.
      ENDMETHOD.                    "check_exist
    ENDCLASS.
    Regards,
    Naimesh Patel

  • I need  to implement clone method  in theAdvancedDataGrid class

    I need  to implement clone method  in theAdvancedDataGrid class, to copy the object in its completeness   Could anyone give me a helping hand.

    Hi Nikos,
    from youe question it's not clear what do you need to copy: data, parts of ADG (GUI) or something else?
    If it's not a GUI - only data - you can use mx.utils.ObjectUtil.copy(value:Object):Object

  • Moving a method from one class to another issues

    Hi, im new. Let me explain what i am trying to achieve. I am basically trying to move a method from one class to another in order to refactor the code. However every time i do, the program stops working and i am struggling. I have literally tried 30 times these last two days. Can some one help please? If shown once i should be ok, i pick up quickly.
    Help would seriously be appreciated.
    Class trying to move from, given that this is an extraction:
    class GACanvas extends Panel implements ActionListener, Runnable {
    private WorldMenuItems speedMenuItems, designMenuItemsPlantGrowth, designMenuItemsPlantCount;
         private WorldMenuItems designMenuItemsPlantEaten, designMenuItemsApproximatePopulation;
         private WorldMenuItems designMenuItemsEatersBorn,designMenuItemsMutationProbability;
         private WorldMenuItems designMenuItemsCrossoverProbability;
    MenuBar getMenuBar() {
              menuBar = new MenuBar();
              addControlItemsToMenuBar();
              addSpeedItemsToMenuBar();
              addWorldDesignItemsToMenuBar();
              return menuBar;
    This is the method i am trying to move (below)
    public void itemsInsideWorldDesignMenu() {
              designMenuItemsPlantGrowth = new WorldMenuItems("Plants Grow",
                        new String[] { "In Rows", "In Clumps", "At Random",
                                  "Along the Bottom", "Along the Edges" }, 1);
              designMenuItemsPlantCount = new WorldMenuItems("Number Of Plants",
                        new String[] { "50", "100", "150", "250", "500" }, 3);
              designMenuItemsPlantEaten = new WorldMenuItems("When a Plant is Eaten",
                        new String[] { "It grows back somewhere",
                                  "It grows back nearby", "It's Gone" }, 0);
              designMenuItemsApproximatePopulation = new WorldMenuItems(
                        "Approximate Population", new String[] { "10", "20", "25",
                                  "30", "40", "50", "75", "100" }, 2);
              designMenuItemsEatersBorn = new WorldMenuItems("Eaters are Born",
                        new String[] { "At the Center", "In a Corner",
                                  "At Random Location", "At Parent's Location" }, 2);
              designMenuItemsMutationProbability = new WorldMenuItems(
                        "Mutation Probability", new String[] { "Zero", "0.25%", "0.5%",
                                  "1%", "2%", "3%", "5%", "10%" }, 3);
              designMenuItemsCrossoverProbability = new WorldMenuItems(
                        "Crossover Probability", new String[] { "Zero", "10%", "25%",
                                  "50%", "75%", "100%" }, 4);
    Class Trying to move to:
    class WorldMenuItems extends Menu implements ItemListener {
       private CheckboxMenuItem[] items;
       private int selectedIndex = -1;
       WorldMenuItems(String menuName, String[] itemNames) {
          this(menuName, itemNames, -1);
       WorldMenuItems(String menuName, String[] itemNames, int selected) {
          super(menuName);
          items = new CheckboxMenuItem[itemNames.length];
          for (int i = 0; i < itemNames.length; i++) {
             items[i] = new CheckboxMenuItem(itemNames);
    add(items[i]);
    items[i].addItemListener(this);
    selectedIndex = selected;
    if (selectedIndex < 0 || selectedIndex >= items.length)
    selectedIndex = 1;
    items[selectedIndex].setState(true);
         public int getSelectedIndex() {
              return selectedIndex;
    public void itemStateChanged(ItemEvent evt) {  // This works on other systems
    CheckboxMenuItem newSelection = (CheckboxMenuItem)evt.getSource();
    for (int i = 0; i < items.length; i++) {
    if (newSelection == items[i]) {
    items[selectedIndex].setState(false);
    selectedIndex = i;
    newSelection.setState(true);
    return;

    Ok i've done this. I am getting an error on the line specified. Can someone help me out and tell me what i need to do?
    GACanvas
    //IM GETTING AN ERROR ON THIS LINE UNDER NAME, SAYING IT IS NOT VISIBLE
    WorldMenuItems worldmenuitems = new WorldMenuItems(name, null);
    public MenuBar getMenuBar() {
              menuBar = new MenuBar();
              addControlItemsToMenuBar();
              addSpeedItemsToMenuBar();
              worldmenuitems.addWorldDesignItemsToMenuBar();
              return menuBar;
    class WorldMenuItems extends Menu implements ItemListener {
         private WorldMenuItems speedMenuItems, designMenuItemsPlantGrowth, designMenuItemsPlantCount;
         private WorldMenuItems designMenuItemsPlantEaten, designMenuItemsApproximatePopulation;
         private WorldMenuItems designMenuItemsEatersBorn,designMenuItemsMutationProbability;
         private WorldMenuItems designMenuItemsCrossoverProbability;
         GACanvas gacanvas = new GACanvas(null);
       private CheckboxMenuItem[] items;
       private int selectedIndex = -1;
       WorldMenuItems(String menuName, String[] itemNames) {
          this(menuName, itemNames, -1);
       WorldMenuItems(String menuName, String[] itemNames, int selected) {
          super(menuName);
          items = new CheckboxMenuItem[itemNames.length];
          for (int i = 0; i < itemNames.length; i++) {
             items[i] = new CheckboxMenuItem(itemNames);
    add(items[i]);
    items[i].addItemListener(this);
    selectedIndex = selected;
    if (selectedIndex < 0 || selectedIndex >= items.length)
    selectedIndex = 1;
    items[selectedIndex].setState(true);
         public int getSelectedIndex() {
              return selectedIndex;
    public void itemStateChanged(ItemEvent evt) {  // This works on other systems
    CheckboxMenuItem newSelection = (CheckboxMenuItem)evt.getSource();
    for (int i = 0; i < items.length; i++) {
    if (newSelection == items[i]) {
    items[selectedIndex].setState(false);
    selectedIndex = i;
    newSelection.setState(true);
    return;
    public void itemsInsideWorldDesignMenu() {
         designMenuItemsPlantGrowth = new WorldMenuItems("Plants Grow",
                   new String[] { "In Rows", "In Clumps", "At Random",
                             "Along the Bottom", "Along the Edges" }, 1);
         designMenuItemsPlantCount = new WorldMenuItems("Number Of Plants",
                   new String[] { "50", "100", "150", "250", "500" }, 3);
         designMenuItemsPlantEaten = new WorldMenuItems("When a Plant is Eaten",
                   new String[] { "It grows back somewhere",
                             "It grows back nearby", "It's Gone" }, 0);
         designMenuItemsApproximatePopulation = new WorldMenuItems(
                   "Approximate Population", new String[] { "10", "20", "25",
                             "30", "40", "50", "75", "100" }, 2);
         designMenuItemsEatersBorn = new WorldMenuItems("Eaters are Born",
                   new String[] { "At the Center", "In a Corner",
                             "At Random Location", "At Parent's Location" }, 2);
         designMenuItemsMutationProbability = new WorldMenuItems(
                   "Mutation Probability", new String[] { "Zero", "0.25%", "0.5%",
                             "1%", "2%", "3%", "5%", "10%" }, 3);
         designMenuItemsCrossoverProbability = new WorldMenuItems(
                   "Crossover Probability", new String[] { "Zero", "10%", "25%",
                             "50%", "75%", "100%" }, 4);
    public void addWorldDesignItemsToMenuBar() {
         gacanvas = new GACanvas(null);
         itemsInsideWorldDesignMenu();
         Menu designMenuItems = new Menu("WorldDesign");
         designMenuItems.add(designMenuItemsPlantGrowth);
         designMenuItems.add(designMenuItemsPlantCount);
         designMenuItems.add(designMenuItemsPlantEaten);
         designMenuItems.add(designMenuItemsApproximatePopulation);
         designMenuItems.add(designMenuItemsEatersBorn);
         designMenuItems.add(designMenuItemsMutationProbability);
         designMenuItems.add(designMenuItemsCrossoverProbability);
         gacanvas.menuBar.add(designMenuItems);

  • Calling a method from abstarct class

    Hi Experts,
    Am working on ABAP Objects.
    I have created an Abstract class - with method m1.
    I have implemented m1.
    As we can not instantiate an abstract class, i tried to call the method m1 directly with class name.
    But it it giving error.
    Please find the code below.
    CLASS c1 DEFINITION ABSTRACT.
      PUBLIC SECTION.
        DATA: v1 TYPE i.
        METHODS: m1.
    ENDCLASS.                    "c1 DEFINITION
    CLASS c1 IMPLEMENTATION.
      METHOD m1.
        WRITE: 'You called method m1 in class c1'.
      ENDMETHOD. "m1
    ENDCLASS.                    "c1 IMPLEMENTATION
    CALL METHOD c1=>m1.
    Please tell me what is wrong and how to solve this problem.
    Thanks in Advance.

    Micky is right, abstract means not to be instantiated. It is just a "template" which you can use for all subsequent classes. I.e you have general abstract class vehicle . For all vehicles you will have the same attributes like speed , engine type ,  strearing , gears etc and methods like start , move etc.
    In all subsequent classes (which inherit from vehicle) you will have more specific attributes for each. But all of these classes have some common things (like the ones mentioned above), so they use abstract class to define these things for all of them.
    Moreover there is no sense in creating instance (real object) of class vehicle . What kind of physical object would vehicle be? there is no such object in real world, right? For this we need to be more precise, so we create classes which use this "plan" for real vehicles. So the abstract class here is only to have this common properties and behaviour defined in one place for all objects which will have these. Abstract object however cannot be created per se. You can only create objects which are lower in hierarchy (which are specific like car , ship, bike etc).
    Hope this claryfies what we need abstract classes for.
    Regards
    Marcin

  • Can't add list element when calling a method from another class

    I am trying to call a method in another class, which contains code listmodel.addElement("text"); to add an element into a list component made in that class.
    I've put in System.out.println("passed"); in the method just to make sure if the method was being called properly and it displays normally.
    I can change variables in the other class by calling the method with no problem. The only thing I can't do is get listmodel.addElement("text"); to add a new element in the list component by doing it this way.
    I've called that method within it's class and it added the element with no problem. Does Java have limitations about what kind of code it can run from other classes? And if that's the case I'd really like to know just why.

    There were no errors, just the element doesnt get added to the list by doing it this way
    class showpanel extends JPanel implements ActionListener, MouseMotionListener {
           framepanel fp = new framepanel();
           --omitted--
         public void actionPerformed(ActionEvent e){
                  if(e.getSource() == button1){
                       fp.addLayer();
    /*is in a different class file*/
    class framepanel extends JPanel implements ActionListener{
            --omitted--
         public void addLayer(){
              listmodel.addElement("Layer"+numLayer);
              numLayer++;
    }

  • Calling a non-static method from another Class

    Hello forum experts:
    Please excuse me for my poor Java vocabulary. I am a newbie and requesting for help. So please bear with me! I am listing below the program flow to enable the experts understand the problem and guide me towards a solution.
    1. ClassA instantiates ClassB to create an object instance, say ObjB1 that
        populates a JTable.
    2. User selects a row in the table and then clicks a button on the icon toolbar
        which is part of UIMenu class.
    3. This user action is to invoke a method UpdateDatabase() of object ObjB1. Now I want to call this method from UIMenu class.
    (a). I could create a new instance ObjB2 of ClassB and call UpdateDatabase(),
                                      == OR ==
    (b). I could declare UpdateDatabase() as static and call this method without
         creating a new instance of ClassB.With option (a), I will be looking at two different object instances.The UpdateDatabase() method manipulates
    object specific data.
    With option (b), if I declare the method as static, the variables used in the method would also have to be static.
    The variables, in which case, would not be object specific.
    Is there a way or technique in Java that will allow me to reference the UpdateDatabase() method of the existing
    object ObjB1 without requiring me to use static variables? In other words, call non-static methods in a static
    way?
    Any ideas or thoughts will be of tremendous help. Thanks in advance.

    Hello Forum:
    Danny_From_Tower, Encephalatic: Thank you both for your responses.
    Here is what I have done so far. I have a button called "btnAccept" created in the class MyMenu.
    and declared as public.
    public class MyMenu {
        public JButton btnAccept;
         //Constructor
         public MyMenu()     {
              btnAccept = new JButton("Accept");
    }     I instantiate an object for MyMenu class in the main application class MyApp.
    public class MyApp {
         private     MyMenu menu;
         //Constructor     
         public MyApp(){
              menu = new MyMenu();     
         public void openOrder(){
               MyGUI MyIntFrame = new MyGUI(menu.btnAccept);          
    }I pass this button all the way down to the class detail02. Now I want to set up a listener for this
    button in the class detail02. I am not able to do this.
    public class MyGUI {
         private JButton acceptButton;
         private detail02 dtl1 = new detail02(acceptButton);
         //Constructor
         public AppGUI(JButton iButton){
         acceptButton = iButton;
    public class detail02{
        private JButton acceptButton;
        //Constructor
        public detail02(JButton iButton){
          acceptButton = iButton;
          acceptButton.addActionListener(new acceptListener());               
       //method
        private void acceptListener_actionPerformed(ActionEvent e){
           System.out.println("Menu item [" + e.getActionCommand(  ) + "] was pressed.");
        class acceptListener implements ActionListener {       
            public void actionPerformed(ActionEvent e) {
                   acceptListener_actionPerformed(e);
    }  I am not able to get the button Listener to work. I get NullPointerException at this line
              acceptButton.addActionListener(new acceptListener());in the class detail02.
    Is this the right way? Or is there a better way of accomplishing my objective?
    Please help. Your inputs are precious! Thank you very much for your time!

Maybe you are looking for