Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lester Zamboni, your micro-managing supervisor, was so impressed by your work la

ID: 3883758 • Letter: L

Question

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 weapon’s 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 <wName> that should be capable of <total damage> 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.

Weapon Type

damage

fork

2

knife

4

stick

1

Explanation / Answer

//Please see the java code below:

import java.util.*;
import java.util.Scanner;

public class Weapon {

   //the name of the weapon
    String wName;
    // basic damage capabilities of the weapon
    int wDamage;
    //How good the weapon is
    double wQuality;
    //Weapon Type
    private final static int fork=2;
    private final static int knife=4;
    private final static int stick=1;

     // WeaponQuality
   private final static double poor=0.5;
   private final static double average=1.0;
   private final static double good=1.5;


  
    Weapon(String wName,int wDamage,double wQuality)
    {
       this.wName=wName;
       this.wDamage=wDamage;
       this.wQuality=wQuality;
    }

  
    Weapon(String wName,int wDamage)
    {
       this.wName=wName;
       this.wDamage=wDamage;
       this.wQuality=average;
    }

    Weapon(double wQuality)
    {
       this.wName="stick";
       this.wDamage=1;
       this.wQuality=wQuality;
    }
  
    public double weaponActualDamage()
    {
       return (this.wDamage *this.wQuality);
    }
  
    public void showWeapon()
    {
       System.out.println("The name of the weapon is "+this.wName);
       System.out.println("Basic damage capabilities of the weapon "+this.wDamage);
       System.out.println("Quality of the weapon is "+this.wQuality);
       System.out.println();
    }
  
public static void main(String[] args) {
      
  
    // System.out.println("The Expression 1/2 +1/6 reduce to string "+numerator3+"/"+ denominator3);
  
  
    //Create a fork weapon object of good quality
      Weapon W1=new Weapon("fork",fork,good);
      W1.showWeapon();
   // Create a knife weapon object, passing only two parameters (wName and wDamage).
      Weapon W2=new Weapon("Knife",knife);
      W2.showWeapon();
      //Create a weapon object that passes a quality of good. (pass 1 parameter)
      Weapon W3=new Weapon(good);
      W3.showWeapon();
}

      
}

OUTPUT:

The name of the weapon is fork
Basic damage capabilities of the weapon 2
Quality of the weapon is 1.5

The name of the weapon is Knife
Basic damage capabilities of the weapon 4
Quality of the weapon is 1.0

The name of the weapon is stick
Basic damage capabilities of the weapon 1
Quality of the weapon is 1.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote