Results 1 to 9 of 9
  1. #1
    fleg is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default Method not found

    Hi, i am newbie and i have one tiny problem, the task is to make a program which allocates memory for some tasks its just simulation so the point is i have 3 classes Main, Task, Memory

    in Task is
    private int requiredMemory;

    public Task(int requiredMemory) {
    this.requiredMemory = requiredMemory;
    }

    /**
    * It returns the size of memory which is required for task to be computed.
    *
    * @return Size of required memory in MB.
    */
    public int getRequiredMemory() {
    return requiredMemory;
    }

    in Memory is that problematic method... it has to be here...

    public boolean allocated(Task task){

    if (task.getRequiredMemory() > freeVolume) {
    return false;
    } else {
    return true;
    }
    }

    and in the main i create the Tasks and Memory from my Memory class and i want to use this method

    allocated(firstTask); and theres the problem cannot find a symbol - method allocated

    Thank you for your help

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default

    Hello fleg,

    Welcome to the forums.
    Can you please post the remaining code as I suspect it has more to do with your initialization and the way in which you are calling the methods as opposed to the actual method itself.

    A stab in the dark, I would guess that you are trying to call the method allocated be using the following code:

    allocated(firstTask);

    This will not work unless the method is a part of the same class. Instead you will need to do something along the lines of the following:

    Task firstTask = new Task(5);
    Memory mem = new Memory(); // Or whatever the constructor is.

    boolean b = mem.allocated(firstTask);

    Regards.

  3. #3
    fleg is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    /**
    * This class represents task which will be computed.
    *
    *
    */
    public class Task
    {

    private boolean active = false;

    private int requiredMemory;

    public Task(int requiredMemory) {
    this.requiredMemory = requiredMemory;
    }

    /**
    * It returns the size of memory which is required for task to be computed.
    *
    * @return Size of required memory in MB.
    */
    public int getRequiredMemory() {
    return requiredMemory;
    }

    /**
    * Check whether the task is active
    */
    public boolean isActive() {
    return active;
    }

    /**
    * Make the task active. If the task is already active, do nothing.
    *
    * @return TRUE if the task has been made active, otherwise FALSE.
    */
    public boolean activate() {
    if (isActive()) {
    return false;
    }
    active = true;
    return true;
    }

    /**
    * Deactivate the task. If the task is not active, do nothing
    *
    * @return TRUE if the task has been deactivated, otherwise FALSE.
    */
    public boolean deactivate() {
    if (!isActive()) {
    return false;
    }
    active = false;
    return true;
    }

    public String toString() {
    return "Task: " + requiredMemory + " MB - " + (active ? "active" : "inactive");
    }

    }

    /**
    * Write a description of class Memory here.
    *
    * @author (your name)
    * @version (a version number or a date)
    */
    public class Memory
    {
    private int capacity;
    private int volume= 200;
    private int allocatedVolume;

    public Memory(int capacity) {
    this.capacity = capacity;
    }



    public int getAllocatedVolume(){
    return allocatedVolume;
    }

    public boolean allocated(Task task){

    if (task.getRequiredMemory() > freeVolume) {
    return false;
    } else {
    return true;
    }
    }


    public String toString (){
    return "Memory: allocated" + capacity + "MB ";
    }

    public void writeInfo(){
    System.out.println (toString());
    }
    }

    public class Main
    {
    public static void main(String[] args) {

    Memory firstMemory = new Memory(1000);
    Memory secondMemory = new Memory(800);

    Task firstTask = new Task (500);
    Task secondTask = new Task (600);
    Task thirdTask = new Task (700);

    firstTask.allocated(firstTask);

    firstMemory.writeInfo();
    secondMemory.writeInfo();





    }
    }

    there it is...thanks for helping me

  4. #4
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default

    As suspected, you are attempting to access the allocated method of the Task class which does not exist.

    The line:
    firstTask.allocated(firstTask);

    should read:

    firstMemory.allocated(firstTask);

    Also, within the same, method I can't see a declaration for the variable freeVolume.

    Just one final point, the writeInfo method is also a bit redundant. Instead, just override the toString method as you have already done and then call System.out.println(firstMemory.toString()) from within the main method.

    Regards.

  5. #5
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default

    You can also use the code:

    System.out.println(firstMemory);

    This will call the toString() method by default.

    Happy coding :D.

  6. #6
    fleg is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    yes its reduntant but its school work and our teacher wants to have that method there (i am talking about toString) and its not finished yet :D i was stucked on that problem.
    thank you for your help :D... you will see me back in few days with another problem :D

  7. #7
    fleg is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default

    just one thing, our teacher said that the program has to be runned from the command line and we need to write something to the header of program or something so he can run it from command line.... if someone knows what i am talking about :D pls help me Thanks

  8. #8
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    317
    Rep Power
    4

    Default

    I presume what they want is a Jar file. Depending on your development platform then the program may create a .jar file for you. In programs such as NetBeans, this can be found within the dist folder in the project folder.

    If you are developing using such as Notepad, then you will have to create a Jar file yourself. These tutorials will provide you with all the information you need. They do look daunting but they will take you through it step by step.

    Regards.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,825
    Rep Power
    19

    Default

    I suspect he's looking for something along the lines of:
    commadline> java myProgram
    which will give some output like:
    -- Usage:
    java myProgram <some parameter> <some other paremeter>

    Now, your program does not seem to take in any parameters, but without a better description of what he asked for (not parsed through someone who didn't understand what was being asked for) it's hard to tell.

Similar Threads

  1. Method Graphics.drawString() - Symbol not found
    By km0r3 in forum AWT / Swing
    Replies: 1
    Last Post: 08-27-2010, 02:55 PM
  2. No JVM found error
    By rocky05 in forum New To Java
    Replies: 1
    Last Post: 01-27-2009, 03:41 PM
  3. no jre,jvm found error
    By rocky05 in forum Eclipse
    Replies: 2
    Last Post: 01-27-2009, 03:38 PM
  4. JButtonGroup; add() method not found?
    By Moddy in forum AWT / Swing
    Replies: 3
    Last Post: 10-15-2008, 11:08 PM
  5. 404 Not Found
    By mary in forum Java Servlet
    Replies: 5
    Last Post: 11-07-2007, 10:15 AM

Posting Permissions

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