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

For the following question, i have done up to number 6. however i dont know how

ID: 3677931 • Letter: F

Question

For the following question, i have done up to number 6. however i dont know how to to the 7, 8, 9.

Create a project called “Lab6”. Inside it, create a class called “Warrior” (without a main method) and a class called “Driver” that has a main method in it. Below is a description of the features of the Warrior class. As you add features to the Warrior class, put code into the main method of the Driver that tests the new Warrior features. The Warrior class should have the following features:

1. Three instance variables: • a String variable called name • an int variable called strength • an int variable called healthLevel

2. A constructor that accepts three parameters (String, int, int) and sets the instance variables to these values.

3. A constructor that accepts one parameter (String) that sets the name to the parameter, sets strength to 10, and sets healthLevel to 200.

4. An instance method called isAlive that takes no parameters and returns true if the current object has a positive healthLevel and false otherwise.

5. An instance method called smite that takes one parameter of type Warrior. The current object will “smite” the parameter, which means the parameter’s healthLevel will be decreased by the strength of the current object.

6. An equals method. In order for two Warriors to be considered equal, they must have the same name and strength. (Do not compare their healthLevels.)

7. A toString method. This should return a String in the following format: Conan the Barbarian - Strength: 24, Health: 400

8. A static method called fight. This method takes two parameters of type Warrior, and returns a Warrior. The two Warriors will take turns smiting one another until one of them is dead. (The first parameter gets to strike first!) The method will return a reference to the winner. (Note: You should never allow a Warrior who has died to still “smite” the other one!)

9. A static method called tournament. This method takes four paramters of type Warrior, and returns a Warrior. The first and second parameters will fight. Then the third and fouth parameters will fight. Finally, the winners of those two fights will fight against each other. The method returns a reference to the winner of this last fight.

//1

public class Warrior {

   public String name;

public int strength;

public int healthLevel;

//2

   Warrior(String sc, int size, int levelHealth){

       name=sc;

       strength=size;

       healthLevel=levelHealth;

  

   }

//3

   Worrior (String sc){

       name = sc;

       strength = 10;

       healthLevel= 200;

   }

//4

   public boolean inAlive(){

       if (healthLevel>0)

           return true;

       else{

           return false;

       }

   }

//5

   public void smite(Warrior w){

       w.healthLevel-=strength;

   }

//6

   public int equals (Warrior w){

       if (name.equals(w.name)&& strength==w.strength){

           return 1;

       }else{

           return 0;

       }

   }

   public String toSrtring (){

       System.out.print("Conan the Barbian - Strength:"+strength+ ",Health:"+healthLevel);

return null ;

   }

Explanation / Answer

//Three instance variables: • a String variable called name • an int variable called strength • an int variable called healthLevel.

public class Warrior

{

   public String name;

   public int strength;

   public int healthLevel;

Warrior w = new warrior();

// A constructor that accepts three parameters (String, int, int) and sets the instance variables to these values

Public Warrior(String sc, int size, int levelHealth)

{

                        name=sc;

                        strength=size;

                        healthLevel=levelHealth;

  

            }

// A constructor that accepts one parameter (String) that sets the name to the parameter, sets strength to 10, and sets healthLevel to 200.

Public   setName(String sc)

{

               name=sc;

                        size.strength = 10;

                        levelhealth.healthLevel= 200;

            }

// An instance method called isAlive that takes no parameters and returns true if the current object has a positive healthLevel and false otherwise.

            public boolean inAlive()

{

                        if (healthLevel>0)

                return true;

                        else

                 return false;

             }

//An instance method called smite that takes one parameter of type Warrior. The current object will “smite” the parameter, which means the parameter’s healthLevel will be decreased by the strength of the current object.

public void smite(Warrior w)

{

       w.healthLevel-=strength;

smite s=new smite();

   }

//An equals method. In order for two Warriors to be considered equal, they must have the same name and strength. (Do not compare their healthLevels.)

public int equals (Warrior w)

   {

       if (name==w.name&& strength==w.strength)

           return 1;

       else

           return 0;

   }

}

//A toString method. This should return a String in the following format: Conan the Barbarian - Strength: 24, Health: 400

Class driver

{

public String toString()

{

  return name+" "+strength+" "+Health;  

}  

public static void main(String args[])

      {  

   Warrior w=new warrior(“canon-the barbarian”,24,400);  

       

   System.out.println(w);//compiler writes here w.toString()  

    }  

}

//A static method called fight. This method takes two parameters of type Warrior, and returns a Warrior. The two Warriors will take turns smiting one another until one of them is dead. (The first parameter gets to strike first!) The method will return a reference to the winner. (Note: You should never allow a Warrior who has died to still “smite” the other one!)

Public static fight( int size, int levelhealth)

{

If(s.levelHealth==0)

return w.winner;

else

return 0;

}

//A static method called tournament. This method takes four paramters of type Warrior, and returns a Warrior. The first and second parameters will fight. Then the third and fouth parameters will fight. Finally, the winners of those two fights will fight against each other. The method returns a reference to the winner of this last fight.

Public static tournament(int a,int x, int y,int z)

{

      tournament t=new t();

                        if(t.a>t.x)

return A=t.a;

else

return A=t.x;

if(t.y>t.z)

return B=t.y;

else

return B=t.z;

              if(A>B)

return A;

else return B;

}

note- above code is a reference and it can be modified with respect to the lab program.

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