0% found this document useful (0 votes)
11 views12 pages

En 17409056

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

En 17409056

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Continuous Assessment Cover Sheet

Faculty of Engineering

Module Details
Module Code EC2492 Module Title Object Oriented Programming
Program: B.Sc. Engineering (Hons) UGC Name: Jayasinghe H. B. C.
Stream: (Electrical & Electronics)

Assessment details
Title Group assignment No
Final Assignment If yes, Group No.
Lecturer/ Instructor Mr. Nishan de Silva Date of Performance 15/05/2020
Due date 15/05/2020 Date submitted 15/05/2020

Student statement and signature


By this declaration, I/we confirm my/our understanding and acceptance that the work reported in this report
is my/our own work. I/we also understand the consequences of engaging in plagiarism or copying others
work without proper citation. Any material used in this work (whether from published sources, the internet
or elsewhere) have been fully acknowledged and referenced and are without fabrication or falsification of
data.
[Copying or plagiarism will result in a “0” mark for the continuous assessment and “F” for the module after
an investigation on academic misconduct;
All academic misconduct is considered seriously and defined as dishonest and in direct opposition to the
values of a learning community.
Misconduct may result in penalties from failure to exclusion from the campus.
Further help and guidance on how to avoid academic misconduct can be obtained from your academic
advisor/tutor]

By this declaration, I confirm my understanding and acceptance that-


• I have adhered to relevant ethical guidelines and procedures in the completion
of the assignment.
• I have not allowed another student to have access to or copy from this work.
This work has not been submitted previously.
[The Institute may request an electronic copy of this work for submission to the Plagiarism detection facility
(TURNITIN). You must make sure that an electronic copy of your work is available in these circumstances]
Group Number: Signature
Student EN17409056 Full Jayasinghe H. B. C.
ID Name
Student Full
ID Name

Specific comments about the work (including overall comments and guidelines for improvement)

Tutor: Signature: Date:

1
Task 01: Class diagram

<<interface>>
DateTime
CarParkManager
- Date: String
+ totalVehicleSlots: int = 20
- entryTime: LocalDateTime
+ vehicleEntered(): boolean - exitTime: LocalDateTime
+ vehicleLeft(): int + setEntryTime (): LocalDateTime
+ getNumEmptySlots(): int + getExitTime (): LocalDateTime
+ getNumOccupiedSlots(): int

SLIITCarParkManager
- plateID: String
+ carCount : int = 0
+ vanCount : int = 0
+ carCount : int = 0
+ threewheelCount : int = 0
+ slotCount : int : static
+ type : String : static
+ parkingSlot (list ArrayList): void
+ ParkVehicle (type String, list ArrayList): ArrayList
+ SearchByNumberPlate (plateID String, list ArrayList): void
+ DeleteVehicle (plateID String, list ArrayList): void
+VehiclesInPark (list ArrayList): void
+ Menu (list ArrayList): void

<<abstract>>
Vehicle
- VehicleNumber: String
- Brand: String
+ getVehicleNumber (): String
+ setVehicleNumber (vehicleNumber String): void
+ getBand (): String
+ setBand (Band String): void
+ Add (s String, sc Scanner): String

Car
- noDoors: int ThreeWheeler
- color: String - engineCap: String
+ Add (s String, sc Scanner): String + Add (s String, sc Scanner): String

Van
- cargoVolume: double
+ Add (s String, sc Scanner): String

2
Task 02: Code

CarParkManager Interface

package en17409056;

interface CarParkManager {//interface variables should be "final" as below


final int totalVehicleSlots = 20;//final means can give a value only one time (thus, interface variables must
//be constant)

boolean vehicleEntered();

int vehicleLeft();

int getNumEmptySlots();

int getNumOccupiedSlots();

DateTime Class

package en17409056;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Scanner;

public class DateTime {


private String date;//instant variable
private LocalDateTime entryTime;
private LocalDateTime exitTime;

public String getDate() {//getter of Date


return date;
}

public void setDate(String date) {//Setter of Date


this.date = date;//this.date use to refer to the instance variable
}//date use to refer to the method's argument

public LocalDateTime setEntryTime() {//Setter of EntryTime


this.entryTime = java.time.LocalDateTime.now();//entryTime instant variable use laptop's time by
//importing
return entryTime;
}

public LocalDateTime getExitTime() {//getter of ExitTime


this.exitTime = java.time.LocalDateTime.now();//exitTime instant variable use laptop's time by
//importing
return exitTime ;
}

3
}

SLIITCarParkManager Class

package en17409056;

import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
import java.time.LocalDateTime;
//use extends as DateTime is a parent & super class & use implements as CarParkManager is an interface for
//this class
public class SLIITCarParkManager extends DateTime implements CarParkManager {
Scanner sc = new Scanner(System.in);
private String plateID;//private Instant variable
//private String Date;
static int carCount =0;//this variable has a starting value & it can use without an object as static
static int vanCount =0;
static int threewheelCount =0;
static int slotCount;//this variable can use without an object as static
static String type;

public void parkingSlot(ArrayList list){//parkingSlot method


System.out.println("Vehicle Category (car / van / threewheel )");
String Choice = sc.nextLine();//obtain the vehicle type

if
(Choice.equalsIgnoreCase("car")||Choice.equalsIgnoreCase("threewheel")||Choice.equalsIgnoreCase("van"))
{
slotCount++;//fill one empty parking slot
type="car";
}

else {//if another type(except car or van or threewheel) of vehicle come


System.out.println("Your Vehicle Category Is Not Allowed to Park Here");
return;
}

if (slotCount > 20) {//to inform if there are no empty parking slots are available in the particular time
if (type.equalsIgnoreCase("car")) {
slotCount--;
}
System.out.println("Currently No Parking Space for Your " + Choice);
}

else
ParkVehicle(Choice,list);//update an empty parking slot if empty parking slots are available
}

public ArrayList ParkVehicle (String type , ArrayList list) {


int slotCount ;
LocalDateTime entrytime = super.setEntryTime();//set arrival time of a vehicle in the DateTime
//super/parent class

4
String str = null ;

switch (type){
case "car"://if the arrival vehicle is a car
Car car = new Car();
str = car.Add(type,sc);
break;

case "van"://if the arrival vehicle is a van


Van van = new Van();
str= van.Add(type,sc);
break;

case "threewheel"://if the arrival vehicle is a threewheel


ThreeWheel threewheel = new ThreeWheel();
str= threewheel.Add(type,sc);
break;
}

str = str+"/"+entrytime+" - "+type;//add arrival time to the code


list.add(str);
return list;
}

public void SearchByNumberPlate(String plateID,ArrayList list) {


boolean bool = false;

for (Object d : list) {


String str = d.toString();
String Word = str.substring(0, str.indexOf("/"));

if (Word.equalsIgnoreCase(plateID)) {//if entered plateID is match to a parked vehicle


System.out.println(d);
}
else{//if entered plateID is wrong
System.out.println("No Vehicle Found for the Entered Plate ID in the Car Park");
}
}
}

/*public void SearchByDate(String EntryTime, ArrayList list) {//future development of my code


boolean bool = false;

for (Object d : list) {


String str = d.toString();
String Word = str.substring(0, str.indexOf("/"));

if (Word.equalsIgnoreCase(EntryTime)) {
System.out.println(d);
}
}
}*/

public void DeleteVehicle(String plateID,ArrayList list){

5
boolean bool = false;
LocalDateTime exittime = super.getExitTime();//Obtain departure time of a vehicle
//from DateTime(is a parent & super class for this class) class

for(Object d: list) {
String str =d.toString();
String Word= str.substring(0, str.indexOf("/"));

if (Word.equalsIgnoreCase(plateID)) {//if Entered Plate ID was Found in the Car Park


System.out.println(str);//display the Entered details of the matched vehicle
System.out.println("Vehicle Exit Time :"+exittime);
System.out.println("Press 1 to Confirm Delete");//to Confirm the departure of the displaying vehicle
System.out.println("Press Any Key For Main Menu");//to Reject the departure of the displaying
//vehicle

String choice =sc.next();//save Confirmation or Rejection

if(choice.equalsIgnoreCase("1"))//if the departure was Confirmed


list.remove(str);//then only remove details of the displaying vehicle
slotCount--;//reduce the number of filled slots in the car park by one
break;
}
else{//if Entered Plate ID was not Found in the Car Park
System.out.println("No Vehicle Found for the Entered Plate ID in the Car Park");
}
}
}

public void VehiclesInPark(ArrayList list){


for(Object d: list) {//display details on all the vehicles currently in the Car Park
System.out.println(d);
}
}

public void Menu (ArrayList list){


System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
System.out.println("||||||||||||||||||||| SLIIT Car Park Manager |||||||||||||||||||||||||");
System.out.println("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");

System.out.println("\n Park Vehicle (ADD) (Press 1)");


System.out.println("\n Delete Vehicle (Delete) (Press 2)");
System.out.println("\n Search Vehicle (By Plate ID) (Press 3)");
//System.out.println("\n Search Vehicle (By Date) (Press 4)");//future development of my code
System.out.println("\n View All Vehicles in the Car Park (Press 5)");

String type = sc.nextLine();


SLIITCarParkManager park = new SLIITCarParkManager();

switch (type){
case "1"://if a driver agree to park his vehicle
park.parkingSlot(list);//calling parkingSlot method
break;

case "2"://if a driver Delete(leave) his Vehicle from the park

6
System.out.println("Enter Plate ID of the Vehicle (Plate Number)");
String plateNumber2 = sc.nextLine();
park.DeleteVehicle(plateNumber2 ,list);//let the driver to leave his Vehicle from the park
break;

case "3"://to search a vehicle(which is aleady in the park) by using Plate ID


System.out.println("Enter Plate ID of the Vehicle (Plate Number)");
String plateNumber3 = sc.nextLine();
park.SearchByNumberPlate(plateNumber3 ,list);//calling SearchByNumberPlate method
break;

/*case "4"://future development of my code


System.out.println("Enter Entry Date of the Vehicle (Date)");
String date4 = sc.nextLine();
park.SearchByEntryTime(date4 ,list);
break;*/

case "5"://to show all the vehicles currently in the Car Park
park.VehiclesInPark(list);//calling VehiclesInPark method
break;
}
}

public static void main(String[] args) {//main method with an argument


ArrayList<String> arrlist = new ArrayList<>();
SLIITCarParkManager park = new SLIITCarParkManager();

Scanner sc = new Scanner(System.in);

while(true){
park.Menu(arrlist);//calling Menu method
}
}

@Override
public boolean vehicleEntered() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int vehicleLeft() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int getNumEmptySlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

7
@Override
public int getNumOccupiedSlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

Vehicle Class

package en17409056;

import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
//use implements as CarParkManager is an interface for this class
public abstract class Vehicle implements CarParkManager {//common variables for all vehicles (in below)
private String VehicleNumber;//Instant variable
private String Brand;
private Date EntryDate;
private Time EntryTime;

public String getVehicleNumber() {//public method for retrieving the Plate ID of a Vehicle
return VehicleNumber;
}

public void setVehicleNumber(String vehicleNumber) {//Setter of VehicleNumber to set the Vehicle


//Number
VehicleNumber = vehicleNumber;
}

public String getBrand() {//getter of Brand to get the Brand


return Brand;
}

public void setBrand(String brand) {//Setter of Brand to set the Brand


Brand = brand;
}

public Date getEntryDate() {//getter of EntryDate


return EntryDate;
}

public void setEntryDate(Date entryDate) {//Setter of EntryDate


EntryDate = entryDate;
}

public Time getEntryTime() {//getter of EntryTime


return EntryTime;

8
}

public void setEntryTime(Time entryTime) {//Setter of EntryTime


EntryTime = entryTime;
}

abstract String Add (String s , Scanner sc);//abstract method to store the details of vehicles

Car Class

package en17409056;

import java.util.ArrayList;
import java.util.Scanner;
//use extends as Vehicle is a parent & super class for this class
public class Car extends Vehicle {
//private Instant variables belongs only to this class
private int noDoors;
private String color;

@Override
String Add(String s, Scanner sc) {//obtain details if a car arrives
System.out.println("Enter Plate ID of the Car");
super.setVehicleNumber(sc.nextLine());//set VehicleNumber setter of Vehicle super class
System.out.println("Enter Brand of the Car");
super.setBrand(sc.nextLine());//set Brand setter of Vehicle super class
System.out.println("Enter Number of Doors of the Car");
this.noDoors = sc.nextInt();//obtain Number of Doors for this class
System.out.println("Enter Color of the Car");
this.color=sc.next();//obtain Color of the Car for this class

String Vnum = super.getVehicleNumber();//call getter of VehicleNumber of Vehicle super class


String VBrand = super.getBrand();//call getter of Brand of Vehicle super class

String block = Vnum+"/"+VBrand+"/"+noDoors+"/"+color;//save obtained details in


//obtaining order
return block;
}

@Override
public boolean vehicleEntered() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int vehicleLeft() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

9
@Override
public int getNumEmptySlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int getNumOccupiedSlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

Van Class

package en17409056;

import java.util.ArrayList;
import java.util.Scanner;

public class Van extends Vehicle {


private double cargoVolume ;//private Instant variable belongs only to this class

@Override
String Add(String s, Scanner sc) {
System.out.println("Enter Plate ID of the Van");
super.setVehicleNumber(sc.nextLine());//set VehicleNumber setter of Vehicle super class
System.out.println("Enter Brand of the Van");
super.setBrand(sc.nextLine());//set Brand setter of Vehicle super class
System.out.println("Enter Number of Seats of the Van");
this.cargoVolume = sc.nextInt();//obtain Number of Seats of the Van for this class

String Vnum = super.getVehicleNumber();//call getter of VehicleNumber of Vehicle super class


String VBrand = super.getBrand();//call getter of Brand of Vehicle super class

String block = Vnum+"/"+VBrand+"/"+cargoVolume;//save obtained details in obtaining order


return block;
}

@Override
public boolean vehicleEntered() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int vehicleLeft() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override

10
public int getNumEmptySlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

@Override
public int getNumOccupiedSlots() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated
methods, choose Tools | Templates.
}

ThreeWheel Class

package en17409056;

import java.util.ArrayList;

import java.util.Scanner;

public class ThreeWheel extends Vehicle {

private String engineCap;//private Instant variable belongs only to this class

@Override

String Add (String s , Scanner sc){

System.out.println("Enter Plate ID of the ThreeWheel");

super.setVehicleNumber(sc.nextLine());//set VehicleNumber setter of Vehicle super class

System.out.println("Enter Brand of the ThreeWheel");

super.setBrand(sc.nextLine());//set Brand setter of Vehicle super class

System.out.println("Enter If it is a Taxi or Not for Hire");

this.engineCap = sc.next();//obtain if it is for Hire or not for Hire (for this class)

String Vnum = super.getVehicleNumber();//call getter of VehicleNumber of Vehicle super class

11
String VBrand = super.getBrand();//call getter of Brand of Vehicle super class

String block = Vnum+"/"+VBrand+"/"+engineCap;//save obtained details in obtaining order

return block;

@Override

public boolean vehicleEntered() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated


methods, choose Tools | Templates.

@Override

public int vehicleLeft() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated


methods, choose Tools | Templates.

@Override

public int getNumEmptySlots() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated


methods, choose Tools | Templates.

@Override

public int getNumOccupiedSlots() {

throw new UnsupportedOperationException("Not supported yet."); //To change body of generated


methods, choose Tools | Templates.

}
12

You might also like