Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd a simple GIF to a class
    primarykey
    data
    text
    <p>I am in my programming 2 class and the professor wants us to make a class that will eventually develop into a game. The problem that I am having is that I dont know how to add the file to the class so that when I use the tester I get no errors. I dont have to do anything with the file, yet. I just need to make a couple of instances in the tester after my myPlayer2 but Im not sure how to go about this. I hope this and my code makes sense. Thank you.</p> <pre><code>import java.io.File; public class myPlayer { private String name; private String gender; private String role; private int health; private String state; private File sprite = new File("MarioSprite.gif"); /** * constructor for the game player * @param name-- the players name * @param gender -- the players gender * @param role -- role such as boss, healer, demon, knight * @param health -- percentage of health * @param state -- whether player is alive, dead, active, inactive, sleeping * @param sprite -- this is the sprite file for the class */ // the file name is MarioSprite.gif public myPlayer(){ name = " unknown"; gender = " unknown"; role = " not defined"; health = 0; state = " not defined"; sprite = null; } public myPlayer(String name, String gender, String role, int health, String state, File sprite){ this.name = name; this.gender = gender; this.role = role; this.health = health; this.state = state; this.sprite = sprite; } /** * @return the name */ public String getName() { return name; } /** * @param the name to set */ public void setName(String name) { this.name = name; } /** * @return the gender */ public String getGender() { return gender; } /** * @param the gender to set */ public void setGender(String gender) { this.gender = gender; } /** * @return the role */ public String getRole() { return role; } /** * @param the role to set */ public void setRole(String role) { this.role = role; } /** * @return the health */ public int getHealth() { return health; } /** * @param the health to set */ public void setHealth(int health) { this.health = health; } /** * @return the state */ public String getState() { return state; } /** * @param the state to set */ public void setState(String state) { this.state = state; } /** * @return the sprite */ public File getSprite() { return sprite; } /** * @param the sprite to set */ public void setSprite(File sprite) { this.sprite = sprite; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return "myPlayer [name=" + name + ", gender=" + gender + ", role=" + role + ", health=" + health + ", state=" + state + ", sprite=" + sprite + "]"; } } public class myPlayerTester { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub myPlayer myPlayer1, myPlayer2, myPlayer3, myPlayer4; myPlayer1 = new myPlayer(); System.out.println(myPlayer1); myPlayer2 = new myPlayer("SteveO", "Male", "demon", 99, "live", null ); System.out.println(myPlayer2); myPlayer3 = new myPlayer("Gandolf", "Female", "demon", 93, "live", null); System.out.println(myPlayer3); myPlayer4 = new myPlayer("Roger", "Female", "demon", 69, "inactive", null); System.out.println(myPlayer4); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload