Public void movePlayer

I cant figure out what to write for my switch statement on this assignment,
(25 spaced board game with 2 players, each taking turns rolling a die untill someone reaches 25)
my method parameters for the movePlayer method are sapposed to be which player, (player1 or player2), moves as well as how many spaces out of 6 (rolled on the die). i am also sapposed to check if a winner can be identified in case 1 and case 2.
i thought i was getting the hang of this but on this i'm at a total loss for ideas of how to do it,
anyone have suggestions?
public class GameBoard
        public static final int BOARD_LENGTH = 25;
     private int player1;
     private int player2;
     private int winner;
public GameBoard(int player1State, int player2State)
          player1 = 0;
          player2 = 0;
          winner = 0;
          player1 = player1State;
          player2 = player2State;
int player1State;
int player2State;
public int getBoardLength()
          return BOARD_LENGTH;
public int getPlayer1State()
          return player1State;
public int getPlayer2State()
          return player2State;
int getWinner()
          return winner;
public void resetBoard(int player1State, int player2State, int winner)
          player1State = 0;
          player2State = 0;
          winner = 0;
         // This method moves the specified player along
     // the game board a specified number of spaces.
     public void movePlayer( int spacesMoved, int playerMoved)
             int spacesMoved;
             int playerMoved;
          switch( playerMoved )
               case 1:
                    // Your code goes here.
               case 2:
                    // Your code goes here.
               default:
                    System.out.println("Warning: Player " +  //Fill this in//
                                        + " does not exist!");
}

public class GameBoard
        public static final int BOARD_LENGTH = 25;
     private int player1;
     private int player2;
     private int winner;
public GameBoard(int player1State, int player2State)
          player1 = 0;  // pointless! you reset its value 3 lines below
          player2 = 0;  // ditto
          winner = 0;
          player1 = player1State;
          player2 = player2State;
int player1State;  // why do  you need a player1 variable as well as this one?
int player2State;  // ditto
public int getBoardLength()
          return BOARD_LENGTH;
public int getPlayer1State()
          return player1State;
public int getPlayer2State()
          return player2State;
int getWinner()
          return winner;
public void resetBoard(int player1State, int player2State, int winner)
          player1State = 0;
          player2State = 0;
          winner = 0;
         // This method moves the specified player along
     // the game board a specified number of spaces.
     public void movePlayer( int spacesMoved, int playerMoved)
             int spacesMoved;  // pointless! You have a parameter with same name
             int playerMoved;  // ditto
          switch( playerMoved )
               case 1:
                    // Your code goes here.
                               // presumably it is player1's turn so increase the player1 variable by number of spaces
               case 2:
                    // Your code goes here.
                                // ditto but for player2
               default:
                    System.out.println("Warning: Player " +  //Fill this in//
                                        + " does not exist!");
}See comments.

Similar Messages

  • Difference between public void, private void and public string

    Hi everyone,
    My 1st question is how do you know when to use public void, private void and public string? I am mightily cofuse with this.
    2ndly, Can anybody explain to me on following code snippet:
    Traceback B0;//the starting point  of Traceback
    // Traceback objects
    abstract class Traceback {
      int i, j;                     // absolute coordinates
    // Traceback2 objects for simple gap costs
    class Traceback2 extends Traceback {
      public Traceback2(int i, int j)
      { this.i = i; this.j = j; }
    }And using the code above is the following allowed:
    B[0] = new Traceback2(i-1, 0);
    Any replies much appreciated. Thank you.

    1)
    public and private are access modifiers,
    void and String return type declarations.
    2)
    It's called "inheritance", and "bad design" as well.
    You should read the tutorials, you know?

  • Difference between Public Void and Public Int

    I was wondering what the difference was between 'public void' and 'public int'?

    Yeah,
    Given package forumTest;
    public class ReturnVoid
         public int returnInt()
         public void returnVoid()
    }compiling using the 1.4.2 reference compiler produces the following result:
    $ javac -d classes/ src/forumTest/ReturnVoid.java
    src/forumTest/ReturnVoid.java:6: missing return statement
            ^
    1 error

  • Public void actionPerformed(ActionEvent e)

    public void actionPerformed(ActionEvent e)
            if(e.equals("north"))
                e.getSource().getClass(CLI);
        } hi i have a class called CLI which handles all the methods. i am reating a gui. i have created the buttons and layout and added actionlisteners to them. i am having trouble assigning the method north() whic is of type static void to the button.
    bassically when the button "north" is pressed i want to call the method North. i have been recommened to use the getSource() method from
    import java.util.EventObject;
    any ideas on where im going wrong?

    Forget getSource, assign a separate anonymous ActionListener to each button, that way when actionPerformed is called you already know which button was pressed.
    All you need to do (if you've put a handler method private void north() into your main class) is:
    northButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e)  {
             north();
      });(And, obviously, similarly for other buttons).
    This creates an instance of an anonymous inner class and connects the button to it so that the actionPerformed method is called when the button is pressed. That, in turn, calls north(); Because it's an inner class it can use the methods of the class it's contained in.

  • I want to know when the method "public void setName" is invoked?

    The jsp file contain the one which list below:
    <mt:hello name="foo"/>
    package com.acme.tag;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class HelloTag extends TagSupport
    private String name="";
    public HelloTag()
    super();
    � public void setName(String name) �
    � {                                                                    �
    � this.name=name; �
    � } �
    �_____________________________________________�
    public int doEndTag() throws javax.servlet.jsp.JspTagException
    try
    pageContext.getOut().write("Hello "+name+"!");
    catch(java.io.IOException e)
    throw new JspTagException("IO Error: " + e.getMessage());
    return EVAL_PAGE;
    }

    does the other method like :
    <b>public void setPageContext(PageContext PageContext)</b>
    and
    <b>public javax.servlet.jsp.tagext.Tag getParent()</b>
    is invoked like setName list above.
    Thanks!

  • How can i call the public void paint(Graphics g) method on click of button?

    Hello,
    I have done this before i know its got to do something with the repaint() method but can someone show me with and example and call the paint method using AWT in a frame not in an applet....
    Thank you very much.

    Thank You very Much.... You have cleared all my doubts.
    But my main objective is to display an image in an AWT Frame !!
    here is the code that i have been trying..
    import java.awt.*;
    import java.awt.event.*;
    public class check6 extends Panel
         Frame f;
         Image i;
         public check6()
              f = new Frame("Heading");
              f.addWindowListener(new WindowAdapter(){
                   public void windowClosing(WindowEvent e){
                        System.exit(0);
              final Button b1 = new Button("Submit");
              b1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e){
                        repaint();
              i = getImage(getCodeBase(), "titanic.jpg");
              add(b1);
              setLayout(new FlowLayout(FlowLayout.LEFT));
              f.add(this);
              f.setSize(500,500);
              f.setVisible(true);
         public void paint(Graphics g)
              g.drawImage(i,10,10,this);
         public static void main(String args[])
              new check6();
    }

  • Question about public void characters(char []ch, int start, int length) thr

    Can anyone tell me how you would keep all the characters from within one pair of tags together each time characters() is called?
    the character() method doesn't read all the character data at once, and i would like to create a buffer of what it has read.
    thank you.

    I recommend using getNodeName and/or/combination
    with
    getNodeValue to get the strings.i have tried using a buffer, and i have got that to work!
    At long last I am seeing the string I would like to see as it is in the xml file!
    thank you for your help
    here is an example of my code:
    private boolean isDescription = false;
    StringBuffer sb = new StringBuffer();
    public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
         if(localName.equals("description")) {
              sb = new StringBuffer();
              isDescription = true;
    public void characters(char []ch, int start, int length) throws SAXException {
         if(isDescription == true) {
              String desc = new String(ch, start, length);
              sb.append(desc);
    public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
         if(localName.equals("description")) {
              isDescription == false;
              System.out.println(sb.toString());
    }

  • JTree DnD Problem - public void drop(DropTargetDropEvent e)

    This method won't executed, can someone give me some ideas what the problem could be.
    After the following (simplified) method is called nothing happens.
    public void dragOver(DropTargetDragEvent e)
    e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE );
    How usually the void drop(DropTargetDropEvent e) method gets executetd ?
    thanks for answers...

    Ensure that you have initialised a DropTarget
    and implemented the DropTargetListener

  • RMI: swing: class ot interface expeted : public void

    PLease take look at the program and the error, i have underlined the area where error has occured...
    Thnk you
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.rmi.*;
    import java.net.*;
         public class appRMIcc extends Frame implements ActionListener{
               JLabel l;
               JTextField tf1,tf2;
               JButton b;
                    public appRMIcc(){
                         setLayout(new FlowLayout());
                         l = new JLabel("Enter the Credit Card number");
                         tf1 = new JTextField(30);
                         tf2 = new JTextField(30);
                         b = new JButton("Check the Card Number");
                         add(l);add(tf1);add(b);
                         add(tf2);
                         b.addActionListener(this);
                         public void actionPerformed(ActionEvent e){                          String cc = tf1.getText();
                              try{
                                   RMIccinterface robj;
                                   robj = (RMIccinterface) Naming.lookup("rmi://127.0.0.1/visagold");
                                   if(robj.isValid(cc)) tf2.setText(String.valueOf("Credit Card valid"));
                                   else
                                   tf2.setText(String.valueOf("Invalid Credit Card Number"));
                                   catch(Exception ex){
                                        System.out.println(ex);
               public static void main(String v[]){
                    appRMIcc dd = new appRMIcc();
                    dd.setSize(400,400);
                    dd.show();
    i got the following error, i ra the above program in the command line, it worked fine but applet is not working..
    --------------------Configuration: <Default>--------------------
    C:\j2sdk\bin\appRMIcc.java:28: 'class' or 'interface' expected
                                    public void actionPerformed(ActionEvent e){
                                           ^
    1 error
    Process completed.
         

    public appRMIcc(){
      setLayout(new FlowLayout());
      l = new JLabel("Enter the Credit Card number");
      tf1 = new JTextField(30);
      tf2 = new JTextField(30);
      b = new JButton("Check the Card Number");
      add(l);add(tf1);add(b);
      add(tf2);
      b.addActionListener(this);
    }If you say so...

  • Public void drop(DropTargetDropEvent e)

    This method won't executed, can someone give me some ideas what the problem could be or when normaly this method gets called ?
    After the following (simplified) method is called nothing happens.
    public void dragOver(DropTargetDragEvent e)
    e.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE );
    How usually the void drop(DropTargetDropEvent e) method gets executetd ?
    thanks for answers...

    Ensure that you have initialised a DropTarget
    and implemented the DropTargetListener

  • Public void init() {

    public void init() {
    imgMap = getImage(getCodeBase(), ("cardiff3.jpg"));
    }//init
    when i load this image in an applet over the net the downloaded parts of the image only become visible when i click the mouse(mouseClicked() happens to call repaint().
    how can i get the image to load without having to click the mouse all the time. is there an automatic way of calling repaint() repeatedly?

    just a thought...
    public void init() {
    imgMap = getImage(getCodeBase(), ("cardiff3.jpg"));
    if (imgMap != null){
    repaint();
    }//init

  • Public void getConfiguredList() { ....} //is the name correct

    hi,
    i have used the name in my project where i'm getting a list. actually the method will not return anything, but by that call i can get the list from some other notifier. here, is the method name getConfiguredList() with void return type correct?
    help!
    -karups

    yeah, that's correct.but, i might have implemented the method to directly return the value, but it takes longer time as the data is coming from server to the client. hence i used the notification mechanism, once the data is received, my calss will be informed with the data. here in my case after calling the method i'm doing nothing but waiting for the data to come.this way i release the thread lock,so the user won't get the feel of delay in response, coz he'll do any other operation in that time span. so, i guess, it,naming like this, makes sense in this particular situtation. pl. opine.

  • Code too large  for public void _jspService

    the file size is 820Kb.it was not getting compiled with a jasper compiler so i used a plain javac to try and compile and even that failed.Previously i had done the same for a 640k file and javac had worked fine but now it doesnt.Does even javac has a limit please feel free to suggest solutions which would help me to compile these files.Maybe memory settings please its urgent.

    There is no limit on the size of the source file.
    For auto-generated code you sometimes hit the size limitation on a method (64k bytes of bytecode).
    It is possible javac is running out of memory, tryjavac -J-Xmx128m

  • How to call java with public static void main(String[] args) throws by jsp?

    how do i call this from jsp? <%spServicelnd temp = new spServicelnd();%> does not work because the program has a main. can i make another 2nd.java to call this spServiceInd.java then call 2nd.java by jsp? if yes, how??? The code is found below...
    import java.net.MalformedURLException;
    import java.io.IOException;
    import com.openwave.wappush.*;
    public class spServiceInd
         private final static String ppgAddress = "http://devgate2.openwave.com:9002/pap";
         private final static String[] clientAddress = {"1089478279-49372_devgate2.openwave.com/[email protected]"};
    //     private final static String[] clientAddress = {"+639209063665/[email protected]"};
         private final static String SvcIndURI = "http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
         private static void printResults(PushResponse pushResponse) throws WapPushException, MalformedURLException, IOException
              System.out.println("hello cze, I'm inside printResult");
              //Read the response to find out if the Push Submission succeded.
              //1001 = "Accepted for processing"
              if (pushResponse.getResultCode() == 1001)
                   try
                        String pushID = pushResponse.getPushID();
                        SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                        StatusQueryResponse queryResponse = sp.queryStatus(pushID, null);
                        StatusQueryResult queryResult = queryResponse.getResult(0);
                        System.out.println("Message status: " + queryResult.getMessageState());
                   catch (WapPushException exception)
                        System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
                   catch (MalformedURLException exception)
                        System.out.println("*** ERROR - MalformedURLException (" + exception.getMessage() + ")");
                   catch (IOException exception)
                        System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
              else
                   System.out.println("Message failed");
                   System.out.println(pushResponse.getResultCode());
         }//printResults
         public void SubmitMsg() throws WapPushException, IOException
              System.out.println("hello cze, I'm inside SubmitMsg");          
              try
                   System.out.println("hello cze, I'm inside SubmitMsg (inside Try)");                         
                   //Instantiate a SimplePush object passing in the PPG URL,
                   //product name, and PushID suffix, which ensures that the
                   //PushID is unique.
                   SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                   //Send the Service Indication.
                   PushResponse response = sp.pushServiceIndication(clientAddress, "You have a pending Report/Request. Please logIn to IRMS", SvcIndURI, ServiceIndicationAction.signalHigh);
                   //Print the response from the PPG.
                   printResults(response);
              }//try
              catch (WapPushException exception)
                   System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
              catch (IOException exception)
                   System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
         }//SubmitMsg()
         public static void main(String[] args) throws WapPushException, IOException
              System.out.println("hello cze, I'm inside main");
              spServiceInd spsi = new spServiceInd();
              spsi.SubmitMsg();
         }//main
    }//class spServiceInd

    In general, classes with main method should be called from command prompt (that's the reason for main method). Remove the main method, put the class in a package and import the apckage in your jsp (java classes should not be in the location as jsps).
    When you import the package in jsp, then you can instantiate the class and use any of it's methods or call the statis methods directly:
    <%
    spServiceInd spsi = new spServiceInd();
    spsi.SubmitMsg();
    %>

  • Difference between void and null?

    wht is da difference between void and null w.r.t java?

    corlettk wrote:
    Why do you care, unless you're implementing a java compiler or JVM?Wow, you sure do suck at helping out in a forum. Why even make this post? You're not helping the OP any, and you made yourself look like a tool.
    To the op:
    Null is java's version of a null value. Java's version is more strict then many other languages, and will not work in a boolean expression or anywhere code expects a real and not null value. It's simply null.
    Void is java's way of declaring no return type on a method. Methods that are void take no 'return' statement and if one is provided will cause a fatal error. The exception to this is using 'return' without a value, which returns control to the caller of the method.
    Observe:
    //this method returns an int
    public int return_int(){
        int value = 5;
        return value;
    //this method does not return an int
    public void return_nothing(){
        int another_value = 123;
        System.out.println("Here's the value: " + return_int());
    //this method does not return anything
    public void nothing_returned(){
        return_nothing();
        return;
        System.out.println("This line never gets printed; the method returned control already!");
    }

Maybe you are looking for

  • VPN 3000 problem

    I have 2 CVPN 3000 at my institution. They have both software version 4.7.2.L-k9. Thay also have WebVPN running. Lately something strange has been happening. One VPN loses connection (ping keepalives stop working) and no one can connect. When this ha

  • HP Laserjet 1018, Word 2007 on Windows XP - Duplex printing alignment

    HP Laserjet 1018, Word 2007 on Windows XP Want to Print a book on both sides of A4 paper. I am printing one page per page (not the book mode). If I print single sided, the top of the page (e.g. header text) on odd and even pages are aligned. When I p

  • Attempting to activate WatchABC, get error code 400-1.

    I've successfully (according to Charter) activated my AppleTV device but receive error code 400-1 (not authorized).  How do I correct this?

  • Script Updater to change username and password

    Can the script updater change the username and password for a bunch of test? I tried using the Global search and replace but it was not able to find the string. Please help?

  • Result recording status

    Hi , I have a senario like as In purchasing we do the MIGO upto 5 PO of same material , when we do for sixth PO it doesn't allow me to do and inform that first complete RR and UD the previous PO's for that i tried in QINF status "Status profile   QM_