Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lester Zamboni, your micro-managing supervisor, was so impressed by your work last week that he has given you a new task in the development of

Lester Zamboni, your micro-managing supervisor, was so impressed by your work last week that he has given you a new task in the development of Legendary Epics. The starter zone of the game is in development, so your task is to develop the weapon treasure table for this zone.

Some game development background: Most combat-based games have weapon-based objects that are capable of being wielded by a character to do varying amounts of damage to an enemy. However, not all weapons are the same in capability and quality. Lester needs you to code a weapon class using Overloaded Constructors that you can create weapons dynamically, and assign them a quality value, and damage value.

Here is your task:

Create a class definition called Weapon.java. This class definition needs these THREE data fields:

A string called wName, which refers to the name of the weapon. Possible weapons are:

Weapon Type

damage

fork

2

knife

4

stick

1

An integer called wDamage, which refers to the basic damage capabilities of the weapon. Above is a damage table for three types of weapons.

A double named wQuality, which refers to how good the weapon is. Quality is a potential damage bonus or penalty. Below is a table of the three quality conditions that a weapon can have. By default, most weapons are of average quality.

Quality

Damage Multiplier

poor

0.5

average

1

good

1.5

Note: A calculation of the weapons actual damage is made by multiplying wDamage by wQuality, rounded to the nearest integer. For example, a fork of average quality does 2 damage (2*1). A knife of good quality does 6 damage (4*1.5). A stick of poor quality does .5 damage, which should always be rounded using Math.round(), so that damage is expressed as an integer.

Next, write 3 constructors:

A constructor that takes all three parameters for weapons: wName, wDamage, and wQuality, assigning values to each object field.

A constructor that takes two parameters for weapons: wName and wDamage. Assume that when no Quality is provided, a default of average (1) is assigned by the constructor.

A constructor that takes one parameter for weapons: wQuality. Assume that when no name is provided, it will be a stick, which always has a damage value of 1.

Next, write 1 display method showWeapon() that outputs the weapon information onto the console in this format:

You found a that should be capable of damage.

Save all this information in a class definition named Weapon.java.

Next, we need a class that creates 3 weapon objects and displays the damage text description into the console by passing parameters into the Weapon() constructor in your other class :

Create a fork weapon object of good quality (pass 3 parameters).

Create a knife weapon object, passing only two parameters (wName and wDamage).

Create a weapon object that passes a quality of good. (pass 1 parameter).

Save this class as CreateWeapon.java.

Sample output:

image text in transcribed

the pervious code was

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

public class Charactergen {

public static int calculateHealth(int baseHealth, int minHealthBonus, int maxHealthBonus)

{

return baseHealth + (minHealthBonus + (int)(Math.random() * maxHealthBonus));

}

public static double calculateCurrency(double baseCurrency)

{

return baseCurrency - (Math.random());

}

public static void displayOutput(String charName, int startHealth, double startCurrency)

{

DecimalFormat df = new DecimalFormat("#.##");

JOptionPane.showMessageDialog(null, "Your name is " + charName + ", your starting health is " + startHealth + " and your starting credits are " + (Double.valueOf(df.format(startCurrency))), "Your Character Stats", JOptionPane.INFORMATION_MESSAGE);

}

public static void main(String[] args) {

String charName;

int minHealthBonus = 1; //Minimun possible amount for starting health bonus

int maxHealthBonus = 5; //Maximun posible amount for starting health bonus

final int BASE_HEALTH = 50; //Initial health

final double BASE_CURRENCY = 10.55; //Character's starting currency before deduction is made

//The following creates a pop up menu prompting the user to enter a character name, the user's input is stored as a string called charName

Character human = new Character();

charName = JOptionPane.showInputDialog(null, "Enter your character's name:", "Welcome to Legendary Epics!", JOptionPane

.QUESTION_MESSAGE);

human.setCharName(charName);

human.setHealth(calculateHealth(BASE_HEALTH, minHealthBonus, maxHealthBonus));

human.setCurrency(calculateCurrency(BASE_CURRENCY));

displayOutput(human.getCharName(), human.getHealth(), human.getCurrency());

}

}

:\Users\Brian\Desktop\CIT 149\My ExamplesWeek 4Java CreateWeapon You found a fork that should be capable of 3 damage You found a knife that should be capable of 4 damage You found a stick that should be capable of 2 damage

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_2

Step: 3

blur-text-image_3

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago