hi there guys
im currently doing an assessment and have found this non static error which im stuck at here is my code for the class i know its ugly lol but the teacher started us off lol
public class Player
{
private String name;
private World world;
private int unplacedArmies;
private int placedArmies;
private int turn;
public Player(String name, World world)
{
placedArmies();
unplacedArmies();
startTurn();
name();
}
/**
* Return the number of territories that this player owns.
*/
(ignore this bit ) public int territoryCount()
{
// You should not modify this method.
//
// Note: This code is very ugly because we haven't learnt about
// arrays and loops yet.
//
// You should NEVER write code like this! ;-)
//
int count = 0;
if (world.africa().territory1().owner() == this) count++;
if (world.africa().territory2().owner() == this) count++;
if (world.africa().territory3().owner() == this) count++;
if (world.africa().territory4().owner() == this) count++;
if (world.euroAsia().territory1().owner() == this) count++;
if (world.euroAsia().territory2().owner() == this) count++;
if (world.euroAsia().territory3().owner() == this) count++;
if (world.euroAsia().territory4().owner() == this) count++;
if (world.australia().territory1().owner() == this) count++;
if (world.australia().territory2().owner() == this) count++;
if (world.australia().territory3().owner() == this) count++;
if (world.australia().territory4().owner() == this) count++;
if (world.northAmerica().territory1().owner() == this) count++;
if (world.northAmerica().territory2().owner() == this) count++;
if (world.northAmerica().territory3().owner() == this) count++;
if (world.northAmerica().territory4().owner() == this) count++;
if (world.southAmerica().territory1().owner() == this) count++;
if (world.southAmerica().territory2().owner() == this) count++;
if (world.southAmerica().territory3().owner() == this) count++;
if (world.southAmerica().territory4().owner() == this) count++;
return count;
}
public void startTurn()
{
turn++;
unplacedArmies = (territoryCount() /3);
System.out.println(name + "'s turn #" + turn++);
System.out.println("you have" + placedArmies + "armies placed.");
System.out.println("you have" + unplacedArmies + "armies to be placed.");
}
(this is where the error is)
public void placeArmy(Territory territory)
{
placedArmies = placedArmies + 1;
unplacedArmies = unplacedArmies - 1;
Territory.armies() = Territory.armies() + 1; }
the last line is where i get the message saying "non static error armies() cannot be referenced from a static context
public void attack(Territory myTerritory, Territory enemyTerritory)
{
}
public String name()
{
return name;
}
public int placedArmies()
{
return placedArmies = 0;
}
public int unplacedArmies()
{
return unplacedArmies = 6;
}
}