0

Can anyone help me ? Our teacher gave us a task it is about "game of life", he actually gave us the methods that we can use, but i really dont know how to start ! he asked us to use 3 classes: class cellule,class ruleand class Automata(and the main of course)

package jeu_de_vie;


public class Cellule {
    private int state; // should be equal to 0 (if alive) or 1 (if dead)

    public Cellule(int state) { // constructor
        this.state = state;

    }
    public void SetEtat(int state){}

    public void Calculate_future_state(Cellule Cg, Cellule Cd,Regle R){} // to calculate the next state

    public boolean Equals (Cellule A,Cellule B){} // to verify if the cellular are equal
}
s.happy
  • 11
  • 5
  • 1
    "should be equal to 0 (if alive) or 1 (if dead)" Sounds like a boolean might be more appropriate (or an enum). – Andy Turner Feb 17 '17 at 20:09

1 Answers1

1

Looks like you have to write code for the 3 functions, this is how it should work:

SetEtat :

This function would be used to set the state of the cellule so it's simple and would work just like the constructor, take the parameter value and assign it to global variable state

public void SetEtat(int state){
    this.state = state;
}

Equals :

According to me this function should return a boolean value so return type should be boolean instead of void, because you would use this for checking and you need a return value. For this to work, state needs to be public or you would need a getter function.

public boolean Equals(Cellule A, Cellule B){
    return (A.state==B.state);
 }

The calculate future state function seems to be incomplete because there is no context of an object of type Regle.

Ayush Seth
  • 1,169
  • 10
  • 21
  • thank u Master Yushi, well Regle is an instance of another class called Regle(rule)that i have implemented and it is converting the rule that we wish use and converte it to binary – s.happy Feb 17 '17 at 20:38
  • @s.happy Can you explain what you need to do in the second function? What actually is the problem you are facing? – Ayush Seth Feb 17 '17 at 20:39
  • 1-Well, calculate_Future_state is supposed to return the future state of cellular(which means it should return int,i have to correct it) after using the rule we wish ; what i dont get is how to use Regle R to find out the next state of the cellular 2- the method setEtat should give me the next state of the cellular why does it work as a contructor – s.happy Feb 17 '17 at 20:48
  • I suppose how to use the Regle R (the rule) to work out the future state would be explained in the question/material provided by your teacher. You should have a look at that. 2) I think the method setEtat is used to set the state of the Cellule, it takes an int parameter. How is it supposed to compute the next state without any extra info? – Ayush Seth Feb 17 '17 at 20:51
  • i will reread the questions of my teacher and come back to u if i don't figure out something. Thank you again @MasterYushi – s.happy Feb 17 '17 at 21:03