Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Intro to JAVA 1) Implement a Weapon class It should contain the following PRIVATE data: String name (default: empty String) int damage (default: 0) It

Intro to JAVA

1) Implement a Weapon class It should contain the following PRIVATE data: String name (default: empty String) int damage (default: 0) It should have the following PUBLIC methods: Constructor that takes name and damage (in that order) Getter method: String getName() Getter method: int getDamage() Page 1 of 5 Setter method: void setName(String) Setter method: void setDamage(int) STATIC method: static void printWeapon(Weapon) that prints the name of the Weapon passed in (if null, print No weapon)

2) Implement a Player class It should contain the following PRIVATE data: Position in X and Y (use an int array of size 2 and allocate space for it) int Health (default: 100) Weapon currentWeapon (default: null) It should have the following PUBLIC methods: Constructor that takes position coordinates as two ints (x and y) Getter method: int getX() Getter method: int getY() Getter method: int getHealth() Getter method: Weapon getCurrentWeapon() Setter method: void setX(int) Setter method: void setY(int) Setter method: void setHealth(int) Setter method: void setCurrentWeapon(Weapon)

3) Implement a class Assign04 to test the Weapon and Player classes. For the main() method of Assign04: Create a Weapon instance, sword, with name Common Sword and damage 50. Create a Weapon instance, coolSword, with name Glamdring, the Foe-Hammer and damage 1500. Create a Player instance, player, with position (100,100). Print the current weapon of the player using printWeapon(). (Should output No weapon) Set the player Weapon to be sword. Print the current weapon of the player using printWeapon(). (Should output Common Sword) Set the player Weapon to be coolSword. Print the current weapon of the player using printWeapon(). (Should output Glamdring, the Foe-Hammer)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

If a fraudulent imposter can perform the job, whats the harm?

Answered: 1 week ago