File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes need help with assignment urgently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help with assignment urgently" Watch "need help with assignment urgently" New topic
Author

need help with assignment urgently

ruth duru
Greenhorn

Joined: Apr 19, 2009
Posts: 1
Hi, im doing an assignment for uni and im currently stuck on my eat() method. The assignment is to program a pacman style game.
The specific step im stuck on is:

**•The eat() method takes an item and makes it disappear. This method also adds an amount N to the player's points, where N = 1000 - distanceTravelled, and N must be no smaller than 100. After eating, this method should print out the message "yum".**

This is my coding so far:

/**
* Write a description of class Player here.
*
* @Author: Ruth Duruchukwu
* @version 1.0
*/
public class Player
{
// instance variables
private World world;
private Body body;
private String name;
private int points, distanceTravelled;
private boolean alive;
public static final int RADIUS = 20;


/**
* Constructor for objects of class Player
*/
public Player()
{
body = new Body();
alive = true;
}

//Setter
public void setWorld(World newWorld)
{
world = newWorld;
}

//Getter
public World getWorld()
{
return world;
}

//Setter
public void setBody(Body newBody)
{
body = newBody;
}

//Getter
public Body getBody()
{
return body;
}

//Accessor
public Player (String newName)
{
name = newName;
}

//Setter
public void
setName(String newName)
{
name = newName;
}

//Getter
public String getName()
{
return name;
}

//Setter
public void setPoints(int newPoints)
{
points = newPoints;
}

//Getter
public int getPoints()
{
return points;
}

//Setter
public void setDistanceTravelled(int newDistanceTravelled)
{
distanceTravelled = newDistanceTravelled;

}

//Getter
public int getDistanceTravelled()
{
return distanceTravelled;
}

//Getter
public boolean isAlive()
{
return alive;
}

//Setter
public void setAlive(boolean newAlive)
{
alive = newAlive;
}

//Methods

public void setInitialState(int x, int y, int radius)
{
body.setX(x);
body.setY(y);
body.setRadius(radius);
}

public void moveHorizontal(int distance)
{
body.move(distance,0);
distanceTravelled += Math.abs(distance);
System.out.println("wagga");
}

public void moveVertical(int distance)
{
body.move(0,distance);
distanceTravelled += Math.abs(distance);
System.out.println("wagga");
}



//system

}

}

im also using Bluej as my software, if that helps
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Welcome to JavaRanch

We have a policy that you must create your own solution; if we gave you an answer it wouldn't help you; in fact it might lose you marks in your assignment.
Please explain what you think the method should do. Something like this
  • Open shed door
  • Get lawnmower out
  • Turn lawnmower on
  • start repetition
  • Walk up lawn
  • Walk back
  • End repetition when you reach end of lawn
  • And that will supply your eat() method . . . Oh, no, it's the mowLawn(Lawn l, Mower m) method.
    That is called pseudo-code, which you ought to have been taught about. Now write out the pseudo-code for your eat() method, and think exactly what that does. And read carefully how you are supposed to work out N. And what your setPoints method does. And when.

    Now work out why you are getting the compiler error.

    Now write out an eat() method. Is it supposed to be eat() or eat(Item)?

    And please use the code button for all your code, and never say "urgent" on this website.

    I don't think it makes much difference to us whether you use BlueJ, but I don't like BlueJ and personally think it actually gets in the way of learning.
    Brian Legg
    Ranch Hand

    Joined: Nov 07, 2008
    Posts: 488
    ...[Edited by MG]


    SCJA
    ~Currently preparing for SCJP6
    Maneesh Godbole
    Saloon Keeper

    Joined: Jul 26, 2007
    Posts: 10491
        
        9

    Brian,

    I am sure you meant well, but I think you seem to have missed the point.
    Providing, or helping anyone find ready made solutions is not going to help that person learn.


    [How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
    Brian Legg
    Ranch Hand

    Joined: Nov 07, 2008
    Posts: 488
    Sorry Maneesh.... the other post didn't have an "answer" either, just thought it may help his thought process.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: need help with assignment urgently