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);
}

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
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.
Susceptible.java interface Susceptible { public boolean infect(Disease disease); public void forceInfection(Disease disease); public Disease getCurrentDisease(); public...
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 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...
Follow program instructions carefully. spacing is important. I think It needs a static void main too. Need to run it! You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data: that hold the x-value and the y-value. They should be ints and must be private. Constructors: A default constructor that will set the values to (2,-7) A parameterized...
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 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 {
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 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),...
Which of the following is true about interfaces: An interface can have only non abstract methods. All methods in an interface must be abstract. A class can only implement one interface. None of the items listed. Can not contain constants but can have variables. What is the rule for a super reference in a constructor? It must be in the parent class' constructor. You cannot use super in a constructor. It must be the last line of the constructor in...
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...
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....