Project 4 Introduction - the SeaPort Project series For this set of projects for
ID: 3722765 • Letter: P
Question
Project 4
Introduction - the SeaPort Project series
For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports.
Here are the classes and their instance variables we wish to define:
SeaPortProgram extends JFrame
o variables used by the GUI interface
o world: World
Thing implement Comparable <Thing>
o index: int
o name: String
o parent: int
World extends Thing
o ports: ArrayList <SeaPort>
o time: PortTime
SeaPort extends Thing
o docks: ArrayList <Dock>
o que: ArrayList <Ship> // the list of ships waiting to dock
o ships: ArrayList <Ship> // a list of all the ships at this port
o persons: ArrayList <Person> // people with skills at this port
Dock extends Thing
o ship: Ship
Ship extends Thing
o arrivalTime, dockTime: PortTime
o draft, length, weight, width: double
o jobs: ArrayList <Job>
PassengerShip extends Ship
o numberOfOccupiedRooms: int
o numberOfPassengers: int
o numberOfRooms: int
CargoShip extends Ship
o cargoValue: double
o cargoVolume: double
o cargoWeight: double
Person extends Thing
o skill: String
Job extends Thing - optional till Projects 3 and 4
o duration: double
o requirements: ArrayList <String>
// should be some of the skills of the persons
PortTime
o time: int
Eventually, in Projects 3 and 4, you will be asked to show the progress of the jobs using JProgressBar's.
2
Here's a very quick overview of all projects:
1. Read a data file, create the internal data structure, create a GUI to display the structure, and let
the user search the structure.
2. Sort the structure, use hash maps to create the structure more efficiently.
3. Create a thread for each job, cannot run until a ship has a dock, create a GUI to show the
progress of each job.
4. Simulate competing for resources (persons with particular skills) for each job.
Project 4 General Objectives
Project 4 - Concurrency
Resource pools
o Threads competing for multiple resources
Blocking threads
Extending the GUI interface to visualize the resource pools and progress of the various threads.
Explanation / Answer
package net.contargo.iris.seaport;
import net.contargo.iris.GeoLocation;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.validator.constraints.NotEmpty;
import java.math.BigInteger;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.Size;
@Entity(name = "Seaport")
public class Seaport extends GeoLocation {
private static final int MAX_NAME_SIZE = 254;
@Id
@GeneratedValue
private Long id;
@NotEmpty
@Size(max = MAX_NAME_SIZE)
private String name;
private boolean enabled = false;
private BigInteger uniqueId;
public Seaport() {
// JPA entity classes must have a no-arg constructor
}
public Seaport(GeoLocation geoLocation) {
this.setLatitude(geoLocation.getLatitude());
this.setLongitude(geoLocation.getLongitude());
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isEnabled() {
return enabled;
}
public BigInteger getUniqueId() {
return uniqueId;
}
public void setUniqueId(BigInteger uniqueId) {
this.uniqueId = uniqueId;
}
@Override
public String getNiceName() {
return getName();
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@Override
public boolean equals(Object o) {
return new EqualsBuilder().appendSuper(super.equals(o)).isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder().appendSuper(super.hashCode()).toHashCode();
}
@Override
public String toString() {
return new ToStringBuilder(this).append("id", id).append("name", name).append("enabled", enabled).toString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.