This site requires JavaScript, please enable it in your browser!
Greenfoot back
ThatAsianPixel
ThatAsianPixel wrote ...

2020/3/7

I need a bit of help

ThatAsianPixel ThatAsianPixel

2020/3/7

#
I'm pretty sure this may not be a greenfoot problem, but I need some help with this problem. I think I got something wrong with the ms.getMoveset.size() but can someone double-check for me? problem:
public void Attack()
    {
        Moves m1 = new Moves("Skull Bash",130,100,"Normal","Physical");
        Moves m2 = new Moves("Hydro Pump",110,80,"Water","Special");
        Moves m3 = new Moves("Ice Beam",90,100,"Ice","Special");
        Moves m4 = new Moves("Weather Ball",50,100,"Normal","Special");
        Moveset ms = new Moveset(m1,m2,m3,m4);
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter: Fight or Run");
        if(scan.nextLine()=="Run")
        {
             System.out.println("Choose a move: ");
             for(int i = 0; i<ms.getMoveset.size();i++)
             {
             }
        }
        
    }
and here is the Moveset class:
public class Moveset 
{
    private ArrayList<Moves> moveset;
    public Moveset(Moves move1, Moves move2, Moves move3, Moves move4)
    {
        moveset.add(move1);
        moveset.add(move2);
        moveset.add(move3);
        moveset.add(move4);
    }
    
    public ArrayList<Moves> getMoveset()
    {
        return moveset;
    }
danpost danpost

2020/3/7

#
ThatAsianPixel wrote...
I think I got something wrong with the ms.getMoveset.size() << Code Omitted >>
You have yet to create an ArrayList object in your Moveset class (line 3 by default is assigned a null value).
You need to login to post a reply.