Results 1 to 9 of 9
Thread: Method not found
- 10-08-2010, 04:37 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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
- 10-08-2010, 05:02 PM #2
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
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.
- 10-08-2010, 05:23 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
/**
* 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
- 10-08-2010, 05:44 PM #4
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
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.
- 10-08-2010, 05:59 PM #5
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
You can also use the code:
System.out.println(firstMemory);
This will call the toString() method by default.
Happy coding :D.
- 10-08-2010, 06:33 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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
- 10-11-2010, 11:22 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 12
- Rep Power
- 0
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
- 10-12-2010, 01:12 PM #8
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
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.
- 10-12-2010, 05:02 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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
-
Method Graphics.drawString() - Symbol not found
By km0r3 in forum AWT / SwingReplies: 1Last Post: 08-27-2010, 02:55 PM -
No JVM found error
By rocky05 in forum New To JavaReplies: 1Last Post: 01-27-2009, 03:41 PM -
no jre,jvm found error
By rocky05 in forum EclipseReplies: 2Last Post: 01-27-2009, 03:38 PM -
JButtonGroup; add() method not found?
By Moddy in forum AWT / SwingReplies: 3Last Post: 10-15-2008, 11:08 PM -
404 Not Found
By mary in forum Java ServletReplies: 5Last Post: 11-07-2007, 10:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks