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

define this class in JAVA 1. Define a class called Ninja Make instance variables

ID: 3839979 • Letter: D

Question

define this class in JAVA


1. Define a class called Ninja Make instance variables for name, dojoName, and killCount. b. create a static variable for totalKills yet". e, create a detault constructor that defaults name to "No Name d, create to No Name yet'' and killcount 0 for name and a constructor that has parameters that set the value dojo name. This wil also set kiliCount to 0. (name, doloName, kinCount Create accessor methods for all the variables and total Kills e. Create a method that increments killCount and totalKills has more kills, Create a STATIC method that compares 2 ninjas to see who This method will print out the name of the ninja with more kills and what percentage his kill number is from the total kilis,

Explanation / Answer

Ninja.java


public class Ninja {
   private String name, dojoName;
   private int killCount;
   public static int totalKills;
   public Ninja() {
       name = "No Name yet";
       dojoName = "No Name yet";
       killCount=0;
   }
   public Ninja(String name, String dojoName) {
       this.name = name;
       this.dojoName=dojoName;
       killCount=0;
      
   }
   public String getName() {
       return name;
   }
   public String getDojoName() {
       return dojoName;
   }
   public int getKillCount() {
       return killCount;
   }
   public static int getTotalKills() {
       return totalKills;
   }
   public void increaseCount(int count) {
       killCount = killCount+count;
       totalKills++;
   }
   public static void compare(Ninja n1, Ninja n2) {
       if(n1.totalKills>= n2.totalKills){
           double percentag = n1.getKillCount()/totalKills;
           System.out.println("Name: "+n1.getName()+" Kills: "+n1.getKillCount()+" Percentage: "+percentag);
       }
       else{
           double percentag = n1.getKillCount()/totalKills;
           System.out.println("Name: "+n2.getName()+" Kills: "+n2.getKillCount()+" Percentage: "+percentag);
       }
   }
}