After evaluating the problem statement, the classes making up the proposed system and their potential objects were identified. These classes are;
This class consists of the accessor and mutator objects for an attendant. An attendant will have an attendant ID, name and availability status thus each of these attributes will have an accessor and mutator object.
This class consists of the accessor and mutator objects for a driver. A driver will be identified by their license plate number thus the driver class will have the accessor and mutator methods for its attributes. Another possible class which will inherit all the properties of the driver class is the Disabled driver class. A disabled driver will have all the properties of a driver and that is why inheritance is suitable between the two classes.
A zone is made up of spaces thus it’s an aggregate of many spaces. The zone class will have different attributes including the zone ID, the zone type, a list of vehicles the zone can accommodate and a list of spaces it’s made up of. Each of these attributes will have an accessor and mutator method which will make up the zone class.
A zone is made up of many spaces. Each space is identified by its space ID and its availability. The space class will have contain the accessor and mutator methods for each of the attribute identifying the space class.
The vehicle class will be identified by the type and the rate that the each type of vehicle is charged per hour. Each of the attributes identifying the vehicle class will have an accessor and mutator method.
This class will be used to load data into the data structures defined for the program. The class will have an object to read a text file and another object to interpret the data read from the text file and put in a list.
This class will contain the main method and will be used to instantiate different classes and methods for the program to run. All the objects will be created using this class. It will also contain a menu class which will help the user to interact with the program.
The receipt class will be used to identify a certain parking session. Thus the attributes identifying the class will include the receipt NO which will act as the token, the space the vehicle was parked, the zone that the space is in, the driver of the vehicle, the attendant who attended to the vehicle if any, the arrival time of the driver and the exit time of the driver. Each of these attributes will have an accessor and a mutator record.
After evaluating the possible functions and operations of the proposed system, the following is the use case diagram. It has two actors; a driver and an attendant. An attendant will is supposed to attend to the driver, thus he or she can perform all the actions of the driver within the system.
The following diagram shows the possible implementation of the proposed system. Each class has been represented with its objects and attributes. Some methods might be added as the system is implemented.
ID |
Requirement |
Description |
Inputs |
Expected outputs |
Pass/ Fail |
Comments |
A1.1 |
FR12 |
Find parking licensePlate of vehicle |
Enter 32-3sfd |
Screen shot SS1 is displayed |
P |
License plate number is accepted |
Enter 23-3sdf |
Screen shot SS2 is displayed |
P |
License plate number is accepted |
|||
Enter Enter 32-32assad |
Screen shot SS3 is displayed |
F |
License plate is accepted |
|||
A1.2 |
FR13 |
Selecting menu option |
Select 1 |
Screen shot SS4 is displayed |
F |
|
Select d |
Screen shot SS5 is displayed |
P |
A NumberFormatException Exception was thrown |
public class Attendant {
private int attendantID;
private String name;
private boolean availability;
public Attendant(){}
public void setAttendantID(int attID){
this.attendantID=attID;
}
public int getAttendantID(){
return this.attendantID;
}
public void setName(String attName){
this.name=attName;
}
public String getName(){
return this.name;
}
public String toString(){
return this.name+” – :”+attendantID;
}
public void setAvailability(boolean status){
this.availability=status;
}
public boolean getAvailability(){
return this.availability;
}
}
}
public class DisabledDriver extends Driver {
private boolean status;
public DisabledDriver(){}
public void setStatus(boolean status){
this.status=status;
}
public boolean getStatus(){
return this.status;
}
}
public class Loader {
public Loader(){}
private String [] readFile(String filename) throws IOException {
BufferedReader br=null;
try{
br=new BufferedReader(new FileReader(filename));
StringBuilder sb=new StringBuilder();
String line=br.readLine();
while(line!=null){
sb.append(line);
sb.append(“n”);
line=br.readLine();
}
String everything=sb.toString();
String [] blocks=everything.split(“n”);
return blocks;
}catch (Exception e){
e.printStackTrace();
return null;
}finally{
br.close();
}
}
public ArrayList populateData(String filename) throws IOException{
ArrayList data=new ArrayList<>();
String arr[]=readFile(filename);
for (int i=0;i<arr.length;i++){
String[] details=arr[i].split(“~”);
ArrayList datum=new ArrayList();
for (int j=0;j<details.length;j++){
datum.add(details[j]);
}
data.add(datum);
}
return data;
}
}
public class Receipt {
private String receiptNO;
private Space space;
private String arrivalTime;
private String exitTime;
private DisabledDriver driver;
private double amount;
private Zone zone;
private Attendant attendant;
private Vehicle userVehicle;
public Receipt(){
this.attendant=null;
this.exitTime=”000000″;
}
public void setReceiptNO(String receiptno){
this.receiptNO=receiptno;
}
public String getReceiptNO(){
return this.receiptNO;
}
public void setSpace(Space space){
this.space=space;
}
public Space getSpace(){
return this.space;
}
public void setArrivalTime(String arrivaltime){
this.arrivalTime=arrivaltime;
}
public String getArrivalTime(){
return this.arrivalTime;
}
public void seExitTime(String exittime){
this.exitTime=exittime;
}
public String getExitTime(){
return this.exitTime;
}
public void setDriver(DisabledDriver dr){
this.driver=dr;
}
public Driver getDriver(){
return this.driver;
}
public void setAttendant(Attendant att){
this.attendant=att;
}
public void setAmount(double amt){
this.amount=amt;
}
public double getAmount(){
return this.amount;
}
public void setUserVehicle(Vehicle vehicle){
this.userVehicle=vehicle;
}
public Vehicle getUserVehicle(){
return this.userVehicle;
}
public void setZone(Zone zone){
this.zone=zone;
}
public Zone getZone(){
return this.zone;
}
public void displayReceipt(){
System.out.println(“***************************Parking Receipt***********************”);
System.out.println(“Receipt NO: “+receiptNO);
System.out.println(“Vehicle License plate: “+driver.getLicensePlate());
System.out.println(“Disability : “+driver.getStatus());
System.out.println(“Arrival Time: “+getTime(arrivalTime));
System.out.println(“Exit time: “+getTime(exitTime));
System.out.println(“Amount: “+amount);
System.out.println(“**************Your allocated space is****************************”);
System.out.println(“ZoneID :”+zone.getZoneID()+” (“+zone.getType()+”)”);
System.out.println(“Space: “+space.getSpaceID());
System.out.println(“Serverd by: “+attendant.getName());
System.out.println(“Thank you for choosing MCP”);
}
public String getTime(String time){
long millis = Long.parseLong(time) % 1000;
long second = (Long.parseLong(time) / 1000) % 60;
long minute = (Long.parseLong(time) / (1000 * 60)) % 60;
long hour = (Long.parseLong(time) / (1000 * 60 * 60)) % 24;
String timeFormat = String.format(“%02d:%02d:%02d.%d”, hour, minute, second, millis);
return timeFormat;
}
}
public class Vehicle {
private int vehicleID;
private String type;
private double rate;
public Vehicle (){}
public void setVehicleID(int vID){
this.vehicleID=vID;
}
public int getVehicleID(){
return this.vehicleID;
}
public void setType(String vType){
this.type=vType;
}
public String getType(){
return this.type;
}
public void setRate(double vRate){
this.rate=vRate;
}
public double getRate(){
return this.rate;
}
}
public class Zone {
private int zoneID;
private String type;
private ArrayList vehicles;
private ArrayList spaces;
public Zone(){
vehicles=new ArrayList<>();
spaces=new ArrayList<>();
}
public void setZoneID(int zoneNO){
this.zoneID=zoneNO;
}
public int getZoneID(){
return this.zoneID;
}
public void setType(String zoneType){
this.type=zoneType;
}
public String getType(){
return this.type;
}
public void setVehicles(Vehicle vehicle){
this.vehicles.add(vehicle);
}
public ArrayList getVehicles(){
return this.vehicles;
}
public ArrayList getSpaces(){
return this.spaces;
}
public void setSpaces(Space space){
this.spaces.add(space);
}
}
public class MCP {
private ArrayList vehicleData=new ArrayList<>();
private ArrayList zoneData=new ArrayList<>();
private ArrayList attendantData=new ArrayList<>();
private ArrayList receipts=new ArrayList<>();
public MCP(){
}
public static void main(String[] args) throws IOException {
System.out.println(“Welcome to MCP parking”);
MCP mcp=new MCP();
mcp.startup();
mcp.menu();
}
public void menu(){
System.out.println(“*********************MENU*************”);
Scanner s=new Scanner(System.in);
System.out.println(“1 Find Parking”);
System.out.println(“2 Exit parking”);
try {
int option = s.nextInt();
if(option==1){
findParking();
}else if(option==2){
exitParking();
}else{
System.out.println(“Invalid option”);
menu();
}
}catch(NumberFormatException e){
System.out.println(“Use numbers only specified in the menu only”);
}
}
public void findParking(){
System.out.println(“Do you want to be assisted by an attendant? (Y=yes, N=No”);
Scanner s=new Scanner(System.in);
String option=s.next();
if(option.equalsIgnoreCase(“y”)){
Random random=new Random();
int randomNumber = random.nextInt(attendantData.size() – 1) + 1;
Attendant attendant=attendantData.get(randomNumber);
parkVehicle(attendant);
}else if(option.equalsIgnoreCase(“n”)){
//no attendant
parkVehicle();
}else{
System.out.println(“Invalid option”);
findParking();
}
}
public void parkVehicle(){
Scanner s=new Scanner(System.in);
System.out.println(“Enter the license plate of the vehicle”);
String licensePlate=s.next();
System.out.println(“Do you have any disability? (Y=Yes, N=No”);
String option=s.next();
boolean opt=false;
if(option.equalsIgnoreCase(“y”)){
opt=true;
}else if(option.equalsIgnoreCase(“n”)){
opt=false;
}else{
System.out.println(“Invalid option”);
System.out.println(“Do you have any disability? (Y=Yes, N=No”);
option=s.next();
if(option.equalsIgnoreCase(“y”)){
opt=true;
}else if(option.equalsIgnoreCase(“n”)){
opt=false;
}
}
DisabledDriver driver=new DisabledDriver();
driver.setlicensePlate(licensePlate);
driver.setStatus(opt);
System.out.println(“Select you vehicle type”);
Vehicle driverVehicle=null;
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
int selectedVehicle;
try {
selectedVehicle = s.nextInt();
if (selectedVehicle>=0 && selectedVehicle<=vehicleData.size()){
driverVehicle=vehicleData.get(selectedVehicle);
}else{
System.out.println(“Invalid option Select vehicle”);
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
selectedVehicle = s.nextInt();
if (selectedVehicle>=0 && selectedVehicle<=vehicleData.size()){
driverVehicle=vehicleData.get(selectedVehicle);
}else{
System.out.println(“Invalid option Select vehicle”);
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
}
}
}catch (NumberFormatException e){
System.out.println(“Use numbers only”);
}
showParkingLots();
//show parking lots
System.out.println(“Select parking lot option”);
Zone customerZone=null;
Space customerSpace=null;
try{
int selectedZone=s.nextInt();
if(selectedZone==0){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==1){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==2){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if (selectedZone==3){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==4){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if (selectedZone==5){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else{
System.out.println(“Invalid option, select zone using the specified zoneID”);
}
}catch(NumberFormatException e){
System.out.println(“Only numbers are allowed”);
}
Receipt receipt=new Receipt();
Random rand = new Random();
int receiptNO = rand.nextInt(500000) + 1;
receipt.setReceiptNO(String.valueOf(receiptNO));
receipt.setSpace(customerSpace);
receipt.setZone(customerZone);
receipt.setArrivalTime(String.valueOf(System.currentTimeMillis()));
receipt.setDriver(driver);
receipt.setUserVehicle(driverVehicle);
receipt.setAttendant(null);
receipts.add(receipt);
receipt.displayReceipt();
menu();
}
public void parkVehicle(Attendant attendant){
Scanner s=new Scanner(System.in);
System.out.println(“Enter the license plate of the vehicle”);
String licensePlate=s.next();
System.out.println(“Do you have any disability? (Y=Yes, N=No”);
String option=s.next();
boolean opt=false;
if(option.equalsIgnoreCase(“y”)){
opt=true;
}else if(option.equalsIgnoreCase(“n”)){
opt=false;
}else{
System.out.println(“Invalid option”);
System.out.println(“Do you have any disability? (Y=Yes, N=No”);
option=s.next();
if(option.equalsIgnoreCase(“y”)){
opt=true;
}else if(option.equalsIgnoreCase(“n”)){
opt=false;
}
}
DisabledDriver driver=new DisabledDriver();
driver.setlicensePlate(licensePlate);
driver.setStatus(opt);
System.out.println(“Select you vehicle type”);
Vehicle driverVehicle=null;
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
int selectedVehicle;
try {
selectedVehicle = s.nextInt();
if (selectedVehicle>=0 && selectedVehicle<=vehicleData.size()){
driverVehicle=vehicleData.get(selectedVehicle);
}else{
System.out.println(“Invalid option Select vehicle”);
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
selectedVehicle = s.nextInt();
if (selectedVehicle>=0 && selectedVehicle<=vehicleData.size()){
driverVehicle=vehicleData.get(selectedVehicle);
}else{
System.out.println(“Invalid option Select vehicle”);
for(int i=0;i<vehicleData.size();i++){
System.out.println(i+” “+vehicleData.get(i).getType());
}
}
}
}catch (NumberFormatException e){
System.out.println(“Use numbers only”);
}
showParkingLots();
//show parking lots
System.out.println(“Select parking lot option”);
Zone customerZone=null;
Space customerSpace=null;
try{
int selectedZone=s.nextInt();
if(selectedZone==0){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==1){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==2){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if (selectedZone==3){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if(selectedZone==4){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else if (selectedZone==5){
customerZone=zoneData.get(selectedZone);
customerSpace=findEmptyParkingSpace(customerZone);
}else{
System.out.println(“Invalid option, select zone using the specified zoneID”);
}
}catch(NumberFormatException e){
System.out.println(“Only numbers are allowed”);
}
Receipt receipt=new Receipt();
Random rand = new Random();
int receiptNO = rand.nextInt(500000) + 1;
receipt.setReceiptNO(String.valueOf(receiptNO));
receipt.setSpace(customerSpace);
receipt.setZone(customerZone);
receipt.setArrivalTime(String.valueOf(System.currentTimeMillis()));
receipt.setDriver(driver);
receipt.setUserVehicle(driverVehicle);
receipt.setAttendant(attendant);
receipts.add(receipt);
receipt.displayReceipt();
attendantData.remove(attendant);
menu();
}
public Space findEmptyParkingSpace(Zone zone){
Space value=null;
for(int i=0;i<50;i++){
Space space= (Space) zone.getSpaces().get(i);
if(space.getAvailability()==true){
value=space;
space.setAvaialability(false);
break;
}
}
zone.getSpaces().remove(value);
zone.getSpaces().add(value);
zoneData.remove(zone);
zoneData.add(zone);
return value;
}
public void showParkingLots(){
for (int i=0;i<zoneData.size();i++){
System.out.println(“Option: “+i);
System.out.println(“Zone ID: “+zoneData.get(i).getZoneID()+” “+zoneData.get(i).getType());
System.out.println(“Type of vehicles accepted: “);
for(int k=0;k<zoneData.get(i).getVehicles().size();k++){
Vehicle vehicle= (Vehicle) zoneData.get(i).getVehicles().get(k);
System.out.append(vehicle.getType()+” n”);
}
System.out.println(“Spaces (True means the space is available and false means its not)”);
for(int j=0;j<zoneData.get(i).getSpaces().size();j++){
if(j%10==0){
System.out.println();
}
System.out.print(“t “+zoneData.get(i).getSpaces().get(j).toString());
}
System.out.println(“n”);
}
}
public void exitParking(){
System.out.println(“Enter your receiptNO (Token)”);
Scanner s=new Scanner(System.in);
String token=s.next();
Receipt receipt=findReceipt(token);
if(receipt==null){
System.out.println(“invaid receipt no or token..Refer to your receipt”);
menu();
}else{
receipt.seExitTime(String.valueOf(System.currentTimeMillis()));
long timeDiff=Long.parseLong(receipt.getExitTime())-Long.parseLong(receipt.getArrivalTime());
long diffInSeconds=timeDiff/1000;
Double amount= Double.valueOf(0);
if(diffInSeconds%3600==0){
amount=(diffInSeconds/3600)*getRate(receipt.getUserVehicle());
}else{
amount=(diffInSeconds/3600)*getRate(receipt.getUserVehicle())+1*getRate(receipt.getUserVehicle());
}
receipt.setAmount(amount);
System.out.println(“Charges for your parking =”+receipt.getAmount() );
System.out.println(“Enter your payment (should be the exact as specified)”);
Double userAmount;
try {
userAmount=s.nextDouble();
if(userAmountamount){
System.out.println(“Incorrect amount”);
System.out.println(“Charges for your parking =”+receipt.getAmount() );
System.out.println(“Enter your payment (should be the exact as specified)”);
userAmount=s.nextDouble();
if(userAmountamount){
System.out.println(“Incorrect amount”);
System.out.println(“Charges for your parking =”+receipt.getAmount() );
System.out.println(“Enter your payment (should be the exact as specified)”);
userAmount=s.nextDouble();
}else{
System.out.println(“Payment made”);
}
}else{
System.out.println(“Payment made”);
}
}catch(Exception e){
System.out.println(“Use numbers only”);
}
receipt.displayReceipt();
System.out.println(“Exit parking within the next fifteen minutes”);
System.out.println(“Press 1 to raise barrier”);
String exitOption=s.next();
if(exitOption.equalsIgnoreCase(“1”)){
long currentTime=System.currentTimeMillis();
long diff=(currentTime-Long.parseLong(receipt.getExitTime()))/1000;
if(diff>15*60){
System.out.println(“You have exceeded 15 minutes from the time you paid..Seek assistance from an attendant”);
}else{
System.out.println(“Raising barrier..Bye”);
}
}
menu();
}
}
public Double getRate(Vehicle vehicle){
Double rate=0.0;
for(int i=0;i<vehicleData.size();i++){
if(vehicleData.get(i)==vehicle){
rate=vehicleData.get(i).getRate();
}
}
return rate;
}
public Receipt findReceipt(String receiptNO){
Receipt receipt=null;
for(int i=0;i<receipts.size();i++){
if(receipts.get(i).getReceiptNO().equalsIgnoreCase(receiptNO)){
receipt=receipts.get(i);
}
}
return receipt;
}
public void startup() throws IOException {
Loader loader=new Loader();
//loading the vehicle types
ArrayList vehicles=loader.populateData(“./src/vehicles.txt”);
for (int i=0;i<vehicles.size();i++){
Vehicle vehicle=new Vehicle();
vehicle.setVehicleID(Integer.parseInt(vehicles.get(i).get(0).toString()));
vehicle.setType(vehicles.get(i).get(1).toString());
vehicle.setRate(Double.parseDouble(vehicles.get(i).get(2).toString()));
vehicleData.add(vehicle);
}
//loading the zone types
ArrayList zones=loader.populateData(“./src/zones.txt”);
for (int i=0;i<zones.size();i++){
Zone zone=new Zone();
zone.setZoneID(Integer.parseInt(zones.get(i).get(0).toString()));
zone.setType(zones.get(i).get(1).toString());
String[] cars=zones.get(i).get(2).toString().split(“,”);
for (int k=0;k<cars.length;k++){
for(int l=0;l<vehicleData.size();l++){
if(Integer.toString(vehicleData.get(l).getVehicleID()).equals(cars[k])){
zone.setVehicles(vehicleData.get(l));
}
}
}
for(int l=0;l<50;l++){
Space space=new Space();
space.setSpaceID(l);
space.setAvaialability(true);
zone.setSpaces(space);
}
zoneData.add(zone);
}
//
//loading space
ArrayList attendants=loader.populateData(“./src/attendant.txt”);
for (int i=0;i<attendants.size();i++){
Attendant attendant=new Attendant();
attendant.setAttendantID(Integer.parseInt(attendants.get(i).get(0).toString()));
attendant.setName(attendants.get(i).get(1).toString());
attendant.setAvailability(true);
attendantData.add(attendant);
}
}
}
The implementation of the proposed MCP system was both very informative and came with some challenges. The stages involved in making the system from the requirements gathering stage to the implementation and testing stage all came with a lot of lessons for me. I discovered that modelling a system using Unified Modelling Language (UML) for example by use of use case diagrams to show the interaction of different users with the system and use of the class diagram to show the possible classes making up the process is the right way to follow when doing any project. This is because following these steps enabled me to get all the requirements of the proposed system before I started the actual implementation. The class diagram also helped me with the during the implementation stage because the structure of the system was already defined thus the coding part was simplified by following the structure. After the implementation was complete, the tests prepared before the implementation stage acted as checkpoints to verify and validate the system against the requirements.
Use of inheritance in my program is the most sophisticated feature in the program. Inheritance helped me to reduce code repetition. Although understanding the actual working of the classes with inheritance was a bit technical for me, I got to understand it more after a few uses. Use of classes to emulate real life objects made the end system to achieve all functionalities required in the requirements.
Essay Writing Service Features
Our Experience
No matter how complex your assignment is, we can find the right professional for your specific task. Contact Essay is an essay writing company that hires only the smartest minds to help you with your projects. Our expertise allows us to provide students with high-quality academic writing, editing & proofreading services.Free Features
Free revision policy
$10Free bibliography & reference
$8Free title page
$8Free formatting
$8How Our Essay Writing Service Works
First, you will need to complete an order form. It's not difficult but, in case there is anything you find not to be clear, you may always call us so that we can guide you through it. On the order form, you will need to include some basic information concerning your order: subject, topic, number of pages, etc. We also encourage our clients to upload any relevant information or sources that will help.
Complete the order formOnce we have all the information and instructions that we need, we select the most suitable writer for your assignment. While everything seems to be clear, the writer, who has complete knowledge of the subject, may need clarification from you. It is at that point that you would receive a call or email from us.
Writer’s assignmentAs soon as the writer has finished, it will be delivered both to the website and to your email address so that you will not miss it. If your deadline is close at hand, we will place a call to you to make sure that you receive the paper on time.
Completing the order and download