• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

need help with assignment urgently

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79701
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    Ranch Hand
    Posts: 488
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ...[Edited by MG]
     
    Bartender
    Posts: 11497
    19
    Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Brian Legg
    Ranch Hand
    Posts: 488
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sorry Maneesh.... the other post didn't have an "answer" either, just thought it may help his thought process.
     
    F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic