Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment 07 - Monsters You must work in alone on this assignment. Do not use any Java language features we have not cover so far

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Assignment 07 - Monsters You must work in alone on this assignment. Do not use any Java language features we have not cover so far in this course. Assignment Objectives After completing this assignment the student should be able to: Implement a class according to given specifications Implement private instance variables Implement constructor methods Implement getter and setter methods Assignment Requirements For this assignment you are given the following files: Assignment07.java (make no changes to this file) Monster.java (you must complete this file) Weapon.java (you must complete this file) Problem Description and Given Info You are going to complete a little program that simulates a battle between two Monsters. Each Monster will have a name and a healthScore. Each Monster will have a specific Weapon that they use to attack the other Monster. Each weapon will have a name. Each Weapon will have a maxDamage that it can do. Each Monster will also be able to attack another Monster. You will write a pair of classes. One to define our Monster objects, and the other to define our Weapon objects. Remember that a class is like a blueprint that we can then use to instantiate objects of that type. So, once we have defined the Monster and Weapon classes, we will be able to instantiate (create) Monster and Weapon objects. Part 1 - Implement the Weapon Class In a file named Weapon.java, implement the class described below. The Weapon class must have the following private instance variables: a variable named name that will store a String a variable named maxDamage that will store an int The Weapon class must have the following public constructor methods: a default constructor an overloaded constructor that takes two arguments. This first argument will be a String. The second argument will be an int. The Weapon class must have the following public methods: a method named getName. This method will take no arguments. This method will return a String. a method named setName. This method will take one String argument. This method will not return anything. a method named getMaxDamage. This method will take no arguments. This method will return a int. The Weapon class must have the following public methods: a method named getName. This method will take no arguments. This method will return a String. a method named setName. This method will take one String argument. This method will not return anything. a method named getMaxDamage. This method will take no arguments. This method will return a int. a method named setMaxDamage. This method will take one int argument. This method will not return anything. Other Details The default constructor should initialize the Weapon object with the name "Pointy Stick", and a maxDamage of 1. P.Miller CSE110 Principles of Programming Assignment 07::100 pts The overloaded constructor should initialize the object's name and maxDamage with the values passed in to the parameter variables. The getName method should simply return the value stored in the object's name variable. The setName method should assign the value passed in as an argument, to the object's name variable. The getMaxDamage method should simply return the value currently stored in the object's maxDamage variable. The setMaxDamage method should store the value passed in as an argument in the object's maxDamage variable. Part 2 - Implement the Monster Class In a file named Monster.java, implement the class described below. The Monster class must have the following private instance variables: a variable named name that will store a String a variable named healthScore that will store a int a variable named weapon that will store a Weapon The Monster class must have the following public constructor methods: an overloaded constructor that takes three arguments. This first argument will be a String. The second argument will be an int. The third argument will be a Weapon. The Monster class must have the following public methods: a method named getName. This method will take no arguments. This method will return a String. a method named getHealthScore. This method will take no arguments. This method will return an int. a method named getWeaponName. This method will take no arguments. This method will return a String. a method named attack. This method will take one argument. The argument should be a Monster. This method will return an int. Other Details The constructor should initialize the object's name, healthScore, and weapon variables with the values passed in as arguments to this constructor. The getName method should just return a copy of the value currently stored in the object's name variable. The getHealthScore method should just return a copy of the value currently stored in the object's healthScore variable. The getWeapon Name method should just return this monster's weapon's name. The attack method should: 1. Pick a random int between 0 and this Monster's Weapon's maxDamage 2. Subtract this amount from the argument Monster's healthScore 3. Return the number of points of damage that this attack inflicted Hints The easiest way to generate random numbers in Java is to call the Math.random method. This method will return a random double between 0.0 and 1.0. You can think of this value as a percentage (with 0.0 being 0.0% and 1.0 being 100%). We can use this random percentage to pick a random number in an arbitrary range. For example, to pick a random number between 0.0 and 10.0, we can evaluate the expression Math.random() * 10.0. To pick a random number between 30.0 and 50.0, we can evaluate the expression Math.random() * 20.0 + 30.0. P.Miller Assignment 07::100 pts CSE110 Principles of Programming What to turn in For this assignment you must upload the following files by the due date. Monster.java Weapon.java // !!! MAKE NO CHANGES TO THIS FILE !!! import java.util.Scanner; public class Assignment07 { private static Scanner scnr = new Scanner(System.in); public static void main(String[] args) { // instantiate 2 Weapon objects Weapon weapon1 = new Weapon ("Atomic Fire Breath", 100); Weapon weapon2 = new Weapon ("Thunderbolt", 50); // instantiate 2 Monster objects Monster monster1 = new Monster ("Godzilla", 100, weapon1); Monster monster2 = new Monster ("Pikachu", 200, weapon2); // we start with round 1 of the fight int round = 1; // battle continues in rounds until one (or both ) monster have a health the is && monster2.getHealthScore() > 0) { int damage1 = monster1.attack(monster2); // first monster attacks second monster int damage2 = monster2.attack(monster1); // second monster attacks first monster // report the results for this round System.out.println("========================= System.out.println("Round #" + round); System.out.println("--- --."); System.out.println(monster1.getName() + " attacks " + monster2.getName() + " with " + monster1.getWeaponName() + ", doing " + damage1 + " points of damage."); System.out.println(monster2.getName() + " attacks " + monster1.getName() + " with " + monster2.getWeaponName() + ", doing " + damage2 + " points of damage."); System.out.println("... System.out.println(monster1.getName() + " Health = " + monster1.getHealthScore(); System.out.println(monster2.getName() + " Health = " + monster2.getHealthScore(); // pause before advancing to the next round System.out.print(" Press ENTER to continue..."); scnr.nextLine(); // advance to the next round round += 1; 1/ we made it out of the loop because one (or both ) monster have a health the is 0) { winner = monster1.getName(); if (monster2.getHealthScore() > 0) { winner = monster? get Name : if (monster2.getHealthScore() > 0) { winner = monster2.getName(); // report the winner System.out.println("The winner is " + winner + "!")

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

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Under the FLSA, minors under 1 6 years of age

Answered: 1 week ago

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago