- package com;
- public class ParkingDemo {
- public static void main(String[] args){
- Parking p[]= new Parking[5];
- p[0]=new Parking("p1",25,"AP1","Two Wheeler");
- p[1]=new Parking("p2",25,"AP2","Four Wheeler");
- p[2]=new Parking("p3",25,"AP3","Four Wheeler");
- p[3]=new Parking("p4",25,"AP4","Two Wheeler");
- p[4]=new Parking("p5",25,"AP5","Four Wheeler");
- String[] allotment=vehicleAllotment(p,90);
- for(String p2:allotment)
- {
- System.out.println(p2);
- }
- String[] allotment1=vehicleAllotment(p,150);
- for(String p3:allotment1)
- {
- System.out.println(p3);
- }
- String[] allotment2=vehicleAllotment(p,110);
- for(String p4:allotment2)
- {
- System.out.println(p4);
- }
- System.out.println(numberOfPillarsforParticularVehicleType(p,"Two Wheeler"));
- }
- public static int numberOfPillarsforParticularVehicleType(Parking[] p,String value)
- {
- int count=0;
- for(int i=0;i<p.length;i++)
- {
- if(p[i].getVehicleType().equalsIgnoreCase(value))
- {
- count++;
- }
- }
- return count;
- }
- public static String[] vehicleAllotment(Parking[] p,int c)
- {
- String[] result=new String[p.length];
- for(int i=0;i<p.length;i++)
- {
- if(c>0)
- {
- if(c>=p[i].getCapacity())
- {
- result[i]=p[i].getAllotmentNo()+"-"+Integer.toString(p[i].getCapacity());
- }
- else if(c<p[i].getCapacity() && c!=0)
- {
- result[i]=p[i].getAllotmentNo()+"-"+Integer.toString(c);
- }
- else if(c==0)
- {
- result[i]=p[i].getAllotmentNo()+"-"+Integer.toString(0);
- }
- }
- else
- {
- result[i]=p[i].getAllotmentNo()+"-"+Integer.toString(0);
- }
- c=c-p[i].getCapacity();
- }
- if(c>0)
- {
- System.out.println("Remaining vehicle for allotment "+c);
- }
- return result;
- }
- }
- package com;
- public class Parking {
- private String pillarNo;
- private int capacity;
- private String allotmentNo;
- private String vehicleType;
- public Parking(String pillarNo, int capacity, String allotmentNo, String vehicleType) {
- //super();
- this.pillarNo = pillarNo;
- this.capacity = capacity;
- this.allotmentNo = allotmentNo;
- this.vehicleType = vehicleType;
- }
- public String getPillarNo() {
- return pillarNo;
- }
- public void setPillarNo(String pillarNo) {
- this.pillarNo = pillarNo;
- }
- public int getCapacity() {
- return capacity;
- }
- public void setCapacity(int capacity) {
- this.capacity = capacity;
- }
- public String getAllotmentNo() {
- return allotmentNo;
- }
- public void setAllotmentNo(String allotmentNo) {
- this.allotmentNo = allotmentNo;
- }
- public String getVehicleType() {
- return vehicleType;
- }
- public void setVehicleType(String vehicleType) {
- this.vehicleType = vehicleType;
- }
- }
[text] jpark
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: