Insects 10 marks Create two classes Hosquito and Tack Each o

:Insects [10 marks Create two classes: Hosquito and Tack. Each of these classes will extend the Inaect class. Each class must have the following methoda/coastructons defined Mosqaito clase A moequito\'s health is an integer between 0 (dead) and 100 (very active) public Noaquito (Sering nane) II create a sosquito with so disease and health 100 public Hosquito(String nase, iat bealth, Diaeaee) // create a moaquito that has the given health and disease // (disease sight be null: Beaning no diaeaae) pablic void bite(Person p) // Pre and postconditions: none II Side Effecta (1) The person\'s bealth will be decreased by 1 (2) The soaquito\'s health vill be decreased by 1 // (3) It the Boaquito\'s health (betere bing reduced by 1) 1 greater thaa 50 and it has a diaease, it transaits the disease to the person (if the person doean\'t already have this disease) If the soaquito\'a health ia leas than or equal to 50 and haa a disease, it givea the disease to the person if the person doesn\'t already have t). but the disease it gives has 1/2 the severity of the disease the soaquito haa Tick clas A tick\'s health is an integer betwee (dead) and 100 (very active) pablic Tick(String sane) // create a tick with no disease and health 100 public Tick (String name, int health, Disease disease) I/ create a tick that bas the given health and diaeaae / (disease might be nall) public void bite Peraon p) // Pre and postconditions none // Side Effecta a) The person\'s bealth will be decreased by 5 (2) The tick\'a bealth ill be decreased by 1 (3) I the Tick has a disease it givea it to the persos. If the person already has this disease, the person\'s disease abould be replaced with the sane disease having the sax severity and nax chance of trananiaaion Cof the peraon\'s existing disease and the one that the tick just gave) COMPI006/1406-Fall 2016 Due November 1 at 3:30 Erasple If a tick has the plague with severity 99 and chance of tranaaaaaan O.3, and the peraon it ibiting already haa the plague with severity 80 and chance of trananiasion of 0.8, then the person will end up with the plague with severity 99 and chance of tranaisaion 0.8

Solution

Though there is no discreption regarding Disease and person class, I have Just created them as markers to compile the code succesfully without errors.

Insect.java: as given

package lab;


// Insect class as given
public abstract class Insect {
   public final String name;
   protected int health;
   protected Disease disease;
  
   public Insect(String name)
   {
       this.name=name;
   }
  
   public abstract void bite(Person p);
  
}

Mosquito.java:

package lab;


// The mosquito class extends insect
public class Mosquito extends Insect {
   // constructor with a name
   public Mosquito(String name) {
       // constructing the parent class
       super(name);
       // setting health to 100 as given
       health=100;
       // setting disease to null
       // indicate no disease at beginning
       disease=null;
       // TODO Auto-generated constructor stub
   }
   // Constructor with health name disease as given
   public Mosquito(String name,int health,Disease disease)
   {
       // setting values and calling parent class constructor
       super(name);
       super.health=health;
       super.disease=disease;
      
   }
   // Overriding the bite method from the Insect class
   public void bite(Person p)
   {
       // if mosquito health is less than 5o and has disease
       if(super.health>50 && super.disease!=null)
       {
           // checking person has disease or not
           if(p.disease==null)
           {
               // injecting disease to the person
               p.disease=super.disease;
               // reducing health ny 1
               p.health--;
               health--;
              
           }
           else // else just reducing the health
           {
               p.health--;
               health--;
           }
       }
       // else >=50 checking disease presents
       else if(super.disease!=null)
       {
           // injecting disease and reducing health
           p.disease=disease;
           p.health--;
           health--;
       }
       // else just reducing the health
       else
       {
           p.health--;
           health--;
       }
  
   }
  
}

Tick.java:

package lab;

// Tick class extending the Insect class
public class Tick extends Insect {

   // Constructor setting the name
   public Tick(String name)
   {
       // Parent class constructor
       // setting default values
       super(name);
       disease=null;
       health=100;
   }
   // Constructor with the name health and disease
   public Tick(String name,int health,Disease disease)
   {
       // setting values
       super(name);
       super.health=health;
       super.disease=disease;
   }
   // Overriding the bite method From the parent class
   public void bite(Person p)
   {
       // If the disease is not null
       if(super.disease!=null)
       {
           // Injecting the person that disease
           p.disease=disease;
           // reducing the health
           p.health=p.health-5;
           health--;;
       }
   }
}

Disease.java

package lab;


// The class has taken just to make sure there are no compilation errors
// while writing the program
public class Disease {

}

Person.java

package lab;
//The class has taken just to make sure there are no compilation errors
//while writing the program
public class Person {

   int health;
   Disease disease;
  
}

 :Insects [10 marks Create two classes: Hosquito and Tack. Each of these classes will extend the Inaect class. Each class must have the following methoda/coastr
 :Insects [10 marks Create two classes: Hosquito and Tack. Each of these classes will extend the Inaect class. Each class must have the following methoda/coastr
 :Insects [10 marks Create two classes: Hosquito and Tack. Each of these classes will extend the Inaect class. Each class must have the following methoda/coastr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site