COMP2396
Loading...
Searching...
No Matches
Weapon.java
Go to the documentation of this file.
1package assignment2;
2
3/**
4 * The Weapon class represents any game weapon with a name and power level.
5 * A weapon can be used to shoot and generate power for attacks.
6 */
7public class Weapon {
8 private final String weaponName;
9 private final int power;
10
11 /**
12 * Constructs a new Weapon with the specified name and power level.
13 *
14 * @param name the name of the weapon
15 * @param power the power level of the weapon
16 */
17 public Weapon(String name, int power) {
18 this.weaponName = name;
19 this.power = Math.max(0, power);
20 }
21
22 /**
23 * Returns the name of the weapon.
24 *
25 * @return the weapon's name
26 */
27 public String getName() {
28 return weaponName;
29 }
30
31 /**
32 * Simulates shooting the weapon and returns the power generated.
33 *
34 * @return the power generated by the weapon
35 */
36 public int shoot() {
37 return power;
38 }
39}
The Weapon class represents any game weapon with a name and power level.
Definition Weapon.java:7
String getName()
Returns the name of the weapon.
Definition Weapon.java:27
final String weaponName
Definition Weapon.java:8
final int power
Definition Weapon.java:9
Weapon(String name, int power)
Constructs a new Weapon with the specified name and power level.
Definition Weapon.java:17
int shoot()
Simulates shooting the weapon and returns the power generated.
Definition Weapon.java:36