100% found this document useful (1 vote)
948 views

Parking Example - JAVA

The document describes a parking management system that uses classes like Vehicle, Car, Truck, and ShowRoomManagement to simulate parking cars and trucks in a showroom. The ShowRoomManagement class contains methods like park(), parkOut(), and showMotors() to respectively park vehicles, remove parked vehicles, and view the current vehicles parked. It uses arrays and objects of Car and Truck classes to track space usage and type of vehicles parked in the 20 space showroom. The main method calls the menu() method which provides an interactive text-based interface to call the different parking lot management methods.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
948 views

Parking Example - JAVA

The document describes a parking management system that uses classes like Vehicle, Car, Truck, and ShowRoomManagement to simulate parking cars and trucks in a showroom. The ShowRoomManagement class contains methods like park(), parkOut(), and showMotors() to respectively park vehicles, remove parked vehicles, and view the current vehicles parked. It uses arrays and objects of Car and Truck classes to track space usage and type of vehicles parked in the 20 space showroom. The main method calls the menu() method which provides an interactive text-based interface to call the different parking lot management methods.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Parking

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

import java.util.*;

interface Vehicle{
public int getSize();
}

class Car implements Vehicle{

public int getSize(){


return carSize;
}
private int carSize=5;
}

class Truck implements Vehicle{

public int getSize(){


return truckSize;
}
private int truckSize=10;
}

class ShowRoomManagement{

int used=0;
public void park(){

int count=0;
int count1=0;
int count2=0;
int a=0;
int b=0;

Random rn = new Random();

while(count<100){

int r=rn.nextInt(2);

if(r==0){
showRoom[used]=c1;
System.out.println("Car is Parked
Sucessfully!!");
count1++;
}

else{

if(count<=90){
showRoom[used]=t1;
System.out.println("Truck is Parked
Sucessfully!!");
count2++;
}
}

a=count1*c1.getSize();
b=count2*t1.getSize();
count=a+b;
System.out.println("Space: "+count);
used++;
}
System.out.println("\nParking is Full!!\n");
}

public void parkOut(){

System.out.println("You want to Park Out Car or Truck");


System.out.println("1-Car");
System.out.println("2-Truck");
System.out.println("3-Menu");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
int z=0;
if(s==1){
for(int i=0;i<used;i++)
if(showRoom[i]==c1)
for(int k=i;k<used;k++)
showRoom[k-1]=showRoom[k];

used--;
}
if(s==2){
for(int j=0;j<used;j++)
if(showRoom[j]==t1)
for(int a=j;a<used;a++)
showRoom[a-1]=showRoom[a];

used--;
}
if(s==3)
menu();
System.out.println("\nShow All Motors that are
Parked\n");
for(int p=0;p<used;p++){
if(showRoom[p]==c1)
System.out.println("Car");
else
System.out.println("Truck");
}
System.out.println("\n");
}

public void showMotors(){


System.out.println("\nShow All Motors that are
Parked\n");
for(int i=0;i<used;i++){
if(showRoom[i]==c1)
System.out.println("Car");
else
System.out.println("Truck");
}
System.out.println("\n");
}

public void menu(){


for(;;){
System.out.println("1-Park");
System.out.println("2-Park Out");
System.out.println("3-Show Motors");
System.out.println("4-Quit");
System.out.println("Enter ur choice: ");
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();

if(s==1)
park();
if(s==2)
parkOut();
if(s==3)
showMotors();
if(s==4)
System.exit(0);
}
}

private Vehicle showRoom[]=new Vehicle[20];


private Car c1=new Car();
private Truck t1=new Truck();
}

class Parking{
public static void main(String args[])throws
ArrayIndexOutOfBoundsException{
ShowRoomManagement srm=new
ShowRoomManagement();
srm.menu();
}
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006

You might also like