Question

USING Java, create a program with the following: (I would like a different answer than the...

USING Java, create a program with the following: (I would like a different answer than the answer on a similar question asked from someone else)

1-The first class is an abstract class called Weapon:

a-Weapon has two different abstract methods:

i-The first abstract method is void and is called attackType

ii-The second abstract method is void and is called range

b-Weapon has a constructor that accepts the weaponName

c-Weapon also has a regular method that calculatesDamange and takes in attackType (string) and range (int) as parameters.

i-The AttackType can be a rangedAttack or a MeleeAttack

ii-If it is a Melee Attack the range is zero and the damage is 10.

iii-If it is a rangedAttack the higher the range the less the damage (just have a few if or switch statements and make up the numbers.

2- The second class is also an abstract class called MeleeWeapon which implements ICanHolster (an interface) and extends the Weapon class.

a-MeleeWeapon has one abstract method called strike.

b-For now ICanholster is empty but once we fill it with method signatures MeleeWeapon will throw and error so be sure to override each method in ICanholster within MeleeWeapon.

c-remember all the abstract methods within the Weapon class also need to be Overridden within MeleeWeapon.

3- The third class is a regular class called RayGun, which will extend Weapon.

a-RayGun will have a method called fire which will accept the range (hint: range needs to be a field).

b-Please note that you will need to use a super keyword to inherit the constructor that sets the name of the weapon.

c-Remember to implement all the methods that are abstract within Weapon and pass values where it makes sense.

d-we need to output the calculated damage of this weapon

4-The fourth class is a regular class called Sword, which will extend MeleeWeapon

a-A sword has several characteristics such as blade length, you can include this as fields.

b- Any field you include needs a constructor and a getter.

c-Swords can be holstered unlike RayGuns (this is just an example don’t focus on the logic).

d-We need to output the calculated damage

5-The fifth class is Main, which will contain your main method (where your output comes from). In this class you will instantiate a Sword, and instantiate a Ray Gun, then output the calcualtedDamange for each, as well as the range. For the sword you will also need to output the fact that a sword can be holstered.

6-Lastly, we have an interface called ICanHolster. a-This interface is simple it simply needs a method called canHolster, much like the example given in class (and uploaded onto blackboard)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here are the 5 classes, i ran out of time so couldn't write main class, but hereon it should be pretty straight forward

==================================================================

public interface ICanHolster {

    //b-For now ICanholster is empty but once we fill it with method signatures

}

==================================================================

public abstract class Weapon {

    protected String weaponName;

    public abstract void attackType();

    public abstract void weaponName(String name);

    public Weapon(String weaponName) {
        this.weaponName = weaponName;
    }

    public int calculatesDamage(String attackType, int range) {
        if (attackType.equals("MeleeAttack")) {
            return 10;
        } else if (attackType.equals("rangedAttack ")) {
            if (range > 10) {
                return 2;
            } else if (range > 5) {
                return 5;
            } else if (range > 3) {
                return 8;
            } else {
                return 10;
            }
        } else {
            return 0;
        }
    }

}

==================================================================

public abstract class MeleeWeapon extends Weapon implements ICanHolster {

    protected String attackType;

    public MeleeWeapon(String weaponName) {
        super(weaponName);
        attackType = "MeleeAttack";
    }

    //a-MeleeWeapon has one abstract method called strike.
    public abstract void strike();

    public void attackType() {
        attackType = "MeleeAttack";
    }

    public int calculatesDamage(String attackType, int range) {
        return 10;
    }

    public void weaponName(String name) {
        this.weaponName = name;
    }
}

==================================================================

public class RayGun extends Weapon {

    private int range;

    public RayGun(String weaponName, int range) {
        super(weaponName);
        this.range = range;
    }

    @Override
    public void attackType() {

    }

    @Override
    public void weaponName(String name) {

    }

    public void fire(int range) {
        this.range = range;
    }

    public int calculatesDamage(String attackType, int range) {
        this.range = range;
        if (range > 10) {
            return 2;
        } else if (range > 5) {
            return 5;
        } else if (range > 3) {
            return 8;
        } else {
            return 10;
        }
    }
}

==================================================================

public class Sword extends MeleeWeapon {


    public Sword(String weaponName) {
        super(weaponName);
    }

    @Override
    public void strike() {

    }

}

==================================================================

Add a comment
Know the answer?
Add Answer to:
USING Java, create a program with the following: (I would like a different answer than the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Create an interface called Amount that includes a method called setPrice (). Create an a...

    In Java Create an interface called Amount that includes a method called setPrice (). Create an abstract class named Book that inherits from the interface Amount. Include a String field for the book’s title and a double field for the book’s Price . Within the class, include a constructor that requires the book title and add two getter methods — one that returns the title and one that returns the price. Include an abstract method named setPrice (). Create a...

  • Write ONE application program by using the following requirements: Using JAVA File input and outp...

    Write ONE application program by using the following requirements: Using JAVA File input and output Exception handling Inheritance At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods At least one interface: this interface needs to have at least two abstract methods At least one method overloading At least one method overriding At least...

  • In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a...

    In this lab you will work with abstract classes/interfaces. (Java Program) You will be implementing a basic employee schema within a company. The Employee class will be an abstract class that will contain methods applicable to all employees. You will then create 2 classes called SoftwareEngineer and ProductManager. Both are different employee types based on occupation. You will create an interface called Developer which will consist of specific methods that apply to only Developers (e.g. SoftwareEngineer class will implement this,...

  • Can someone please help with this in JAVA? Write one application program by using the following...

    Can someone please help with this in JAVA? Write one application program by using the following requirements: 1) Exception handling 2) Inheritance a) At least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods b) At least one subclass: this class also needs to have data members, accessor, mutator, and toString methods c) At least one interface: this interface needs to have at least two abstract methods d) At least one method...

  • -please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract...

    -please use java 3. Interface: Implement a program that creates an Interfacecalled Vehiclewith the following abstract methods(getters): getMake(), getModel(), getYear(), and creates a Classcalled Carthatimplements the Vehicleinterface. The Carclass also contains instance data that represents the make, model, and year of the carand the constructor to initialize these values.Create a driver class called CarTest, whose main method instantiates a Carobject with the following information: Chevrolet, Impala, 2019, and test the getter methods you implement. 4. Abstract Class: Implement the above...

  • Java Questions A class must implement at least one interface. Question 1 options: True False Question...

    Java Questions A class must implement at least one interface. Question 1 options: True False Question 2 (1 point) Abstract methods can be called. Question 2 options: True False Question 3 (1 point) Constructors Question 3 options: Are inherited but cannot be accessed Are inherited and can be accessed Are accessible but are not inherited Are not inherited and cannot be accessed Question 4 (1 point) We can instantiate an object from an abstract class. Question 4 options: True False...

  • Can some please help me to answer these two questions. Write a program in Java create...

    Can some please help me to answer these two questions. Write a program in Java create a class diagram fragment with two classes: User and Patient. Patient is a sub-class of User. User has a method getName(), which is both over-loaded and over-ridden in the subclass In Java write an abstract class called User. User has one abstract method called authenticate, which takes two string parameters. Write a concrete sub-class of User called Administrator with an implementation of the authenticate...

  • Adv. Java program - create a math quiz

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • A Java Program Purpose:         Work with Abstract classes. Purpose:         Abstract classes are import because they ensure...

    A Java Program Purpose:         Work with Abstract classes. Purpose:         Abstract classes are import because they ensure than any children which inherit from it must implement certain methods. This is done to enforce consistency across many different classes. Problem:        Implement a class called Student. This class needs to be abstract and should contain a String for the name, and a String for the major (and they should be private). The class must have a constructor to set the name and major....

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT