|  | 
|  | 1 | +package ClassAndObjects; | 
|  | 2 | + | 
|  | 3 | + | 
|  | 4 | +class MonsterWorks { | 
|  | 5 | + | 
|  | 6 | +	public final String TOMBSTONE = "Here Lies a Dead monster"; | 
|  | 7 | +	private int health = 500; | 
|  | 8 | +	private int attack = 20; | 
|  | 9 | +	private int movement = 2; | 
|  | 10 | +	private boolean alive = true; | 
|  | 11 | +	public String name = "Big Monster"; | 
|  | 12 | + | 
|  | 13 | +	public int getAttack() { | 
|  | 14 | +		return attack; | 
|  | 15 | +	} | 
|  | 16 | + | 
|  | 17 | +	public int getMovement() { | 
|  | 18 | +		return movement; | 
|  | 19 | +	} | 
|  | 20 | + | 
|  | 21 | +	public int getHealth() { | 
|  | 22 | +		return health; | 
|  | 23 | +	} | 
|  | 24 | + | 
|  | 25 | +	public void setHealth(int decreaseHealth) { | 
|  | 26 | +		health = health - decreaseHealth; | 
|  | 27 | +		if (health < 0 && alive == true) { | 
|  | 28 | +			alive = false; | 
|  | 29 | +		} | 
|  | 30 | +	} | 
|  | 31 | + | 
|  | 32 | +	public void setHealth(double decreaseHealth) { | 
|  | 33 | +		int intDecreaseHealth = (int) decreaseHealth; | 
|  | 34 | +		health = health - intDecreaseHealth; | 
|  | 35 | +		if (health < 0) { | 
|  | 36 | +			alive = false; | 
|  | 37 | +		} | 
|  | 38 | +	} | 
|  | 39 | +} | 
|  | 40 | +//Moster Class | 
|  | 41 | +public class Monster{ | 
|  | 42 | + | 
|  | 43 | +	public static void main(String[] args){ | 
|  | 44 | +		MonsterWorks gorilla = new MonsterWorks(); | 
|  | 45 | +		gorilla.name = "Jumbo"; | 
|  | 46 | +		System.out.println(gorilla.name+" got health power: "+gorilla.getHealth()); | 
|  | 47 | +		System.out.println(gorilla.name + " has an attack value of " + gorilla.getAttack()); | 
|  | 48 | +		gorilla.setHealth(30); | 
|  | 49 | +		System.out.println(gorilla.name+" got attacked, Now Health "+gorilla.getHealth()); | 
|  | 50 | +	} | 
|  | 51 | +} | 
0 commit comments