Question

Susceptible.java

interface Susceptible

{

public boolean infect(Disease disease);

public void forceInfection(Disease disease);

public Disease getCurrentDisease();

public void setImmune();

public boolean isImmune();

public Point getPosition();

}

Movable.java

interface Movable

{

public void move(int step);

}

Now we are ready to implement any entity that we want to simulate; we will create Humans. Person Disease - currentDisease: Di


public class Point {
private int xCoordinate;
private int yCoordinate;


/**
* Creates a point at the origin (0,0) and colour set to black
*/
public Point(){
xCoordinate = 0;
yCoordinate = 0;
}

/**
* Creates a new point at a given coordinate and colour
* @param xCoordinate the X coordinate [-999,999]
* @param yCoordinate the Y coordinate [-999,999]
*/
public Point(int xCoordinate, int yCoordinate){
this.xCoordinate = xCoordinate;
this.yCoordinate = yCoordinate;
}


public int getxCoordinate() {
return xCoordinate;
}

public int getyCoordinate() {
return yCoordinate;
}

public void setxCoordinate(int xCoordinate) {
this.xCoordinate = xCoordinate;
}

public void setyCoordinate(int yCoordinate) {
this.yCoordinate = yCoordinate;
}

/**
* Translates a point in 2D space given an X and Y delta
* @param xChange the amount to translate in the X direction
* @param yChange the amount to translate in the Y direction
*/
public void translate(int xChange, int yChange){
xCoordinate += xChange;
yCoordinate += yChange;
}

/**
* Calculates the distance between two points in space
* @param p the other point
* @return the distance. Please note that are Point is unit-less
*/
public double distance(Point p){
double result = Math.sqrt(Math.pow(p.xCoordinate - xCoordinate,2) +
Math.pow(p.yCoordinate - yCoordinate,2));

return result;
}

@Override
public String toString(){
//X: x, Y: y, Colour: colour
String result = "X: " + xCoordinate + " Y: " + yCoordinate;
return result;
}

@Override
public boolean equals(Object obj) {
//if both objects are in the same memory address, they ARE the same
if(this == obj){
return true;
}

//if obj is not a Point they cannot be equal
if(!(obj instanceof Point)){
return false;
}

Point other = (Point)obj;
if(xCoordinate == other.xCoordinate &&
yCoordinate == other.yCoordinate ){
return true;
}

return false;
}

public Point copy(){
return new Point(xCoordinate,yCoordinate);

}
}
java code please

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

Hi,

please find the below code according to UML diagram.

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

Person.java

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

import java.util.List;

interface Susceptible

{

   public boolean infect(Disease disease);

   public void forceInfection(Disease disease);

   public Disease getCurrentDisease();

   public void setImmune();

   public boolean isImmune();

   public Point getPosition();

}

interface Movable

{

   public void move(int step);

}

public class Person implements Susceptible, Movable {

   private Disease currentDisease;
   private String name;
   private Point point;
   private List<Susceptible> othersInfected;
   private boolean isImmune;

   /**
   * @param name
   * @param point
   */
   public Person(String name, Point point) {
       this.name = name;
       this.point = point;
   }

   public void addToTracing(Susceptible susceptible) {
       othersInfected.add(susceptible);
   }

   public List<Susceptible> getOthersInfected() {
       return this.othersInfected;
   }

   @Override
   public void move(int step) {

   }

   @Override
   public boolean infect(Disease disease) {
       if (disease.tryInfect())
           return true;
       if (isImmune || infect(disease))
           return false;
       return false;
   }

   @Override
   public void forceInfection(Disease disease) {
       infect(disease);
   }

   @Override
   public Disease getCurrentDisease() {
       return currentDisease;
   }

   @Override
   public void setImmune() {
       this.isImmune = true;
   }

   @Override
   public boolean isImmune() {
       return isImmune;
   }

   @Override
   public Point getPosition() {
       return point;
   }

   @Override
   public String toString() {
       return "Person [name=" + name + "]";
   }

}
=====================================================

Disease.java

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

package person.disease;

public class Disease {

   private String name;
   private double infectionProbability;
   private int infectionRadius;
   private static double randomInfectionProbability;

   /**
   * @param name
   * @param infectionProbability
   * @param infectionRadius
   */
   public Disease(String name, double infectionProbability, int infectionRadius) {
       this.name = name;
       this.infectionProbability = infectionProbability;
       this.infectionRadius = infectionRadius;
       randomInfectionProbability = Math.random();
   }

   /**
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * @return the infectionProbability
   */
   public double getInfectionProbability() {
       return infectionProbability;
   }

   /**
   * @return the infectionRadius
   */
   public int getInfectionRadius() {
       return infectionRadius;
   }

   public boolean tryInfect() {
       if (randomInfectionProbability < getInfectionProbability())
           return true;
       return false;
   }

}

As point class is already given in the class, not providing again.

I hope this helps you!!

Thanks.

Add a comment
Know the answer?
Add Answer to:
Susceptible.java interface Susceptible { public boolean infect(Disease disease); public void forceInfection(Disease disease); public Disease getCurrentDisease(); public...
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 Pl you will create an interface, Drawable, and an abstract class Polygon. The Point class...

    In Pl you will create an interface, Drawable, and an abstract class Polygon. The Point class is provided. Briefly go over the JavaDocs comments to see what is available to you. «interface Drawable +printToConsole(): void Polygon - points : List<Point> - colour : String Point + Polygon(String colour) + getPoints(): List<Point> + addPoint(Point p): void + equals(Object other): boolean +getArea(): double • The Polygon constructor initializes the List to a List collection of your choosing • add Point: Adds a...

  • Declare an interface Filter as follows: public interface Filter {boolean accept (Object x); } Modify the...

    Declare an interface Filter as follows: public interface Filter {boolean accept (Object x); } Modify the implementation of the DataSet class in Section 10.4 to use both a Measurer and a Filter object. Only objects that the filter accepts should be processed. Demonstrate your modification by processing a collection of bank accounts, filtering out all accounts with balances less than $1,000. Please use the code provided and fill in what is needed. BankAccount.java /**    A bank account has a...

  • In java please: TotalCostForTicket interface Create interface that includes one variable taxRate which is .09. It...

    In java please: TotalCostForTicket interface Create interface that includes one variable taxRate which is .09. It also includes an abstract method calculateTotalPrice which has no parameters and returns a value of type double. public abstract class Ticket { //There is a public static instance variable of type double for the basePrice. public static double basePrice; // private int theaterNumber; private int seatNumber; private boolean isTicketSold; private boolean isTicketReserved; public Ticket(int theaterNumber, int seatNumber) { this.theaterNumber = theaterNumber; this.seatNumber = seatNumber;...

  • Suppose we have the following Java Interface: public interface Measurable {    double getMeasure(); // An...

    Suppose we have the following Java Interface: public interface Measurable {    double getMeasure(); // An abstract method    static double average(Measurable[] objects) { // A static method    double sum = 0;    for (Measurable obj : objects) {    sum = sum + obj.getMeasure();    }    if (objects.length > 0) { return sum / objects.length; }    else { return 0; }    } } Write a class, called Person, that has two instance variables, name (as...

  • //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee {...

    //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId; } public Employee() { name = generatedNames[lastGeneratedId]; id = lastGeneratedId++; } public String getName() { return name; } public int getId() { return id; } //returns true if work was successful. otherwise returns false (crisis) public abstract boolean work(); public String toString() { return...

  • public class Person{ private Disease currentDisease; private String name; private Point position; private List<Susceptible> othersInfected; public...

    public class Person{ private Disease currentDisease; private String name; private Point position; private List<Susceptible> othersInfected; public Person(Point position,String name){ this.position =position; this.name = name; List<Susceptible> othersInfected = new ArrayList<>(); } public void addToTracing(Susceptible person){ othersInfected.add(person); } public List<Susceptible> getOthersInfected(){ return this.othersInfected; } } I got nullpointerException error when using addToTracing method, how do I fix it 9 List<Susceptible> folks = new ArrayList<>(); 10 11 folks.add(new Person (new Point(0,0), "Ann")); 12 folks.add(new Person (new Point(4,23), "Mike")); 13 folks.add(new Person (new Point(0,43),...

  • JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public...

    JAVA - Circular Doubly Linked List Does anybody could help me with this method below(previous)? public E previous() { // Returns the previous Element return null; } Explanation: We have this class with these two implemented inferfaces: The interfaces are: package edu.ics211.h04; /** * Interface for a List211. * * @author Cam Moore * @param the generic type of the Lists. */ public interface IList211 { /** * Gets the item at the given index. * @param index the index....

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • I Have a problem with my JAVA class "Directivo". In the " public double sueldo() "...

    I Have a problem with my JAVA class "Directivo". In the " public double sueldo() " method, the instruction say "Calculate the salary of a Directivo the following way: Invoke method salary of the father and add him the extra bonus" My question is : How can I do this ? how can i implement that instruction in the public double sueldo() method public class Directivo extends Planta implements Administrativo{    private double bonoExtra;    public Directivo( String nom, String...

  • Must be in Java. Show proper reasoning with step by step process. Comment on the code...

    Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...

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
ADVERTISEMENT