├── .gitignore ├── README.md ├── out └── production │ └── Parking_Lot │ ├── .gitignore │ ├── README.md │ └── Parking_Lot.iml ├── ScanTicket.java ├── Parking_Lot.iml ├── Car.java ├── Payment.java ├── ParkingSpot.java ├── LICENSE ├── ParkingTicket.java ├── RandomInfo.java ├── ParkingLot.java └── TotalTime.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .idea 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Parking Lot System 2 | -------------------------------------------------------------------------------- /out/production/Parking_Lot/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | .idea 3 | -------------------------------------------------------------------------------- /out/production/Parking_Lot/README.md: -------------------------------------------------------------------------------- 1 | Parking Lot System 2 | -------------------------------------------------------------------------------- /ScanTicket.java: -------------------------------------------------------------------------------- 1 | public class ScanTicket{ 2 | 3 | public int cheaknumber(String inputnumber, String storenumber){ 4 | 5 | int size1 = inputnumber.length(); 6 | int size2 = storenumber.length(); 7 | if (size1 != size2){ 8 | return 0; 9 | } 10 | else if(inputnumber.equals(storenumber)){ 11 | return 1; 12 | } 13 | return 0; 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Parking_Lot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /out/production/Parking_Lot/Parking_Lot.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Car.java: -------------------------------------------------------------------------------- 1 | public class Car{ 2 | public String NumberPlate; 3 | public String CarColor; //red, yellow, green, etc.. 4 | public String CarType; 5 | 6 | public String getNumberPlate(){ 7 | return NumberPlate; 8 | } 9 | 10 | public void setNumberPlate(String NumberPlate){ 11 | this.NumberPlate = NumberPlate; 12 | } 13 | 14 | public String getCarColor(){ 15 | return CarColor; 16 | } 17 | 18 | public void setCarColor(String CarColor){ 19 | this.CarColor = CarColor; 20 | } 21 | 22 | public String getCarType(){ 23 | return CarType; 24 | } 25 | 26 | public void setCarType(String CarType){ 27 | this.CarType = CarType; 28 | } 29 | } -------------------------------------------------------------------------------- /Payment.java: -------------------------------------------------------------------------------- 1 | public class Payment{ 2 | 3 | float HourAmount = 30; 4 | float TotalAmountForHour = 0; 5 | float TotalAmountForMinute = 0; 6 | 7 | public float TotalAmount(int Hour, int Minute){ 8 | TotalAmountForHour = Hour * HourAmount; 9 | if (Minute < 60 && Minute >= 30) { 10 | TotalAmountForMinute = 20; 11 | } 12 | else if(Minute < 30 && Minute >= 15){ 13 | TotalAmountForMinute = 15; 14 | } 15 | else if(Minute < 15 && Minute >= 1){ 16 | TotalAmountForMinute = 10; 17 | } 18 | 19 | return (TotalAmountForHour+TotalAmountForMinute); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /ParkingSpot.java: -------------------------------------------------------------------------------- 1 | public class ParkingSpot{ 2 | 3 | int[] arr = new int[10]; 4 | 5 | 6 | public int SpotNum(){ 7 | int spot = 0; 8 | for (int i = 0; i < 10; i++){ 9 | if(arr[i] == 0) { 10 | spot = i + 1; 11 | arr[i] = i + 1; 12 | break; 13 | } 14 | } 15 | return spot; 16 | } 17 | 18 | public int si(){ 19 | int cheakspot = 0; 20 | for(int i = 0; i < 10; i++){ 21 | if(arr[i] != 0){ 22 | return 1; 23 | } 24 | else if(arr[i] == 0){ 25 | cheakspot++; 26 | } 27 | } 28 | return cheakspot; 29 | } 30 | 31 | public void sipe(){ 32 | System.out.print("\nSpot status : "); 33 | for(int i = 0; i < 10; i++){ 34 | System.out.print(arr[i]+" "); 35 | } 36 | System.out.println(); 37 | } 38 | 39 | public void FreeSpot (int num){ 40 | arr[num - 1] = 0; 41 | } 42 | 43 | 44 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Kiran Upase 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ParkingTicket.java: -------------------------------------------------------------------------------- 1 | import java.time.format.DateTimeFormatter; 2 | 3 | public class ParkingTicket{ 4 | 5 | //public String ParkingTime; 6 | public String enterDate; 7 | public String enterTime; 8 | private long CardNumber ; 9 | public String CardType; 10 | public int SpotNumber; 11 | 12 | public Car car; 13 | 14 | public Car getAssignedCar(){ 15 | return car; 16 | } 17 | 18 | public void setAssignedCar(Car car){ 19 | this.car = car; 20 | } 21 | 22 | public String getDate(){ 23 | return enterDate; 24 | } 25 | 26 | public void setDate(String enterDate){ 27 | this.enterDate = enterDate; 28 | } 29 | 30 | public String getTime(){ 31 | return enterTime; 32 | } 33 | 34 | public void setTime(String enterTime){ 35 | this.enterTime = enterTime; 36 | } 37 | 38 | private long getCardNumber(){ 39 | return CardNumber; 40 | } 41 | 42 | public void setCardNumber(long CardNumber){ 43 | this.CardNumber = CardNumber; 44 | } 45 | 46 | private String getCardType(){ 47 | return CardType; 48 | } 49 | 50 | public void setCardType(String CardType){ 51 | this.CardType = CardType; 52 | } 53 | 54 | 55 | public int getSpotNumber(){ 56 | return SpotNumber; 57 | } 58 | 59 | public void setSpotNumber(int SpotNumber){ 60 | this.SpotNumber = SpotNumber; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /RandomInfo.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.time.LocalDate; 3 | import java.time.LocalTime; 4 | import java.time.format.DateTimeFormatter; 5 | 6 | public class RandomInfo{ 7 | Random rand = new Random(); 8 | 9 | String[] states = {"MH", "GJ", "RJ", "DL", "MP", "UP", "KA", "JK", "LA"}; 10 | String[] dist = {"02", "27", "12", "19", "22", "08", "05", "26", "30"}; 11 | String[] alpha = {"AB", "CV", "RT", "ZX", "WE", "JK", "RL", "AQ", "PO", "DH"}; 12 | String[] color = {"Red", "Yellow", "Green", "white", "Brown", "Violet", "Pink"}; 13 | String[] type = {"Sedan", "van", "Minivan", "Bus", "Pickup-truck", "Hatchback"}; 14 | 15 | public String Numberplate(){ 16 | int st = rand.nextInt(states.length); 17 | int di = rand.nextInt(dist.length); 18 | int al = rand.nextInt(alpha.length); 19 | 20 | return states[st]+"-"+dist[di]+" "+alpha[al]+" "+rand.nextInt((99 - 10)+ 1) + 10; 21 | } 22 | 23 | public String CarColor(){ 24 | int res = rand.nextInt(color.length); 25 | return color[res]; 26 | } 27 | 28 | public String CarType() { 29 | int typ = rand.nextInt(type.length); 30 | return type[typ]; 31 | } 32 | 33 | 34 | // information for parkingaticket 35 | public String Time(){ 36 | LocalTime localTime = LocalTime.now(); 37 | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm a"); 38 | String enterTime = localTime.format(dateTimeFormatter); 39 | return enterTime; 40 | } 41 | 42 | public String ExitTime(){ 43 | LocalTime localTime = LocalTime.now(); 44 | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm a"); 45 | String exitTime = localTime.format(dateTimeFormatter); 46 | return exitTime; 47 | } 48 | 49 | public String Date(){ 50 | LocalDate mydate = LocalDate.now(); 51 | return mydate.toString(); 52 | } 53 | public String ExitDate(){ 54 | LocalDate date = LocalDate.now(); 55 | return date.toString(); 56 | } 57 | 58 | String[] cardtype = {"Debit", "Credit"}; 59 | public String CardType(){ 60 | int caty = rand.nextInt(cardtype.length); 61 | return cardtype[caty]; 62 | } 63 | 64 | public long CardNumber(){ 65 | return ((rand.nextLong() % 100000000000000L) + 5200000000000000L); 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /ParkingLot.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.*; 3 | 4 | 5 | public class ParkingLot{ 6 | 7 | public static void main(String[] args){ 8 | 9 | ArrayList assignedspotlist = new ArrayList<>(); 10 | 11 | 12 | ParkingSpot parkingspot = new ParkingSpot(); 13 | RandomInfo randominfo = new RandomInfo(); 14 | Scanner scan = new Scanner(System.in); 15 | 16 | while( true ) { 17 | 18 | System.out.print("You want to parked your vehicle : "); 19 | String userinput = scan.nextLine(); 20 | int size = userinput.length(); 21 | 22 | ParkingTicket parkingticket = new ParkingTicket(); 23 | Car car = new Car(); 24 | 25 | if (size == 5) { 26 | System.out.print("\033\143"); 27 | // get car information from car class 28 | String carcolor = randominfo.CarColor(); 29 | String numberplate = randominfo.Numberplate(); 30 | String cartype = randominfo.CarType(); 31 | 32 | parkingticket.setAssignedCar(car); 33 | parkingticket.getAssignedCar().setNumberPlate(numberplate); 34 | parkingticket.getAssignedCar().setCarColor(carcolor); 35 | parkingticket.getAssignedCar().setCarType(cartype); 36 | 37 | // get spot from parkingSpot class 38 | int spotnum = parkingspot.SpotNum(); 39 | if(spotnum == 0){ 40 | System.out.println("Sorry, spot is not available."); 41 | continue; 42 | } 43 | parkingticket.setSpotNumber(spotnum); 44 | 45 | 46 | // get parking ticket from parkingticket class 47 | String cardtype = randominfo.CardType(); 48 | String time = randominfo.Time(); 49 | String date = randominfo.Date(); 50 | long cardnumber = randominfo.CardNumber(); 51 | 52 | parkingticket.setCardType(cardtype); 53 | parkingticket.setTime(time); 54 | parkingticket.setDate(date); 55 | parkingticket.setCardNumber(cardnumber); 56 | 57 | 58 | 59 | System.out.println("\t\t== Parking Ticket ==\n" + 60 | "Car Number : " + numberplate + " Car Color : " + carcolor + " Car Type : " + cartype + 61 | "\nParking Time : " + time + " Date : " + date + 62 | "\nSpot Number : " + spotnum + "\n" 63 | ); 64 | 65 | 66 | assignedspotlist.add(parkingticket); 67 | System.out.println(assignedspotlist.size()); 68 | 69 | } 70 | else if(size == 4){ 71 | //System.out.print("\033\143"); 72 | int cheakspot = parkingspot.si(); 73 | if (cheakspot == 10 ){ 74 | System.out.println("There is no car ."); 75 | continue; 76 | } 77 | else { 78 | System.out.print("Enter your car number : "); 79 | String number = scan.nextLine(); 80 | ScanTicket scanticket = new ScanTicket(); 81 | TotalTime totaltime = new TotalTime(); 82 | Payment payment = new Payment(); 83 | 84 | for(ParkingTicket cp : assignedspotlist){ 85 | String carnumber = cp.getAssignedCar().getNumberPlate(); 86 | int item = scanticket.cheaknumber(number, carnumber); 87 | if( item == 0 ){ 88 | continue; 89 | } 90 | else if(item == 1){ 91 | int spot = assignedspotlist.indexOf(cp); 92 | //System.out.println("\n"+spot+"\n"); 93 | 94 | String exitdate = randominfo.ExitDate(); 95 | 96 | String exittime = randominfo.ExitTime(); 97 | 98 | String enterdate = assignedspotlist.get(spot).getDate(); 99 | String entertime = assignedspotlist.get(spot).getTime(); 100 | 101 | 102 | int time[] = totaltime.CalculateTime(enterdate, exitdate, entertime, exittime); 103 | float amount = payment.TotalAmount(time[0], time[1]); 104 | 105 | System.out.println("\n\t\t=== Your Parking information ===\n" + 106 | "Car Number : " + assignedspotlist.get(spot).getAssignedCar().getNumberPlate() + 107 | " Car Color : " + assignedspotlist.get(spot).getAssignedCar().getCarColor() + 108 | " Car Type : "+assignedspotlist.get(spot).getAssignedCar().getCarType()+ 109 | "\nParking Time : "+assignedspotlist.get(spot).getTime()+ 110 | " Exit Time : "+exittime+ 111 | "\nParking Date : "+assignedspotlist.get(spot).getDate()+ 112 | " Exit Date :" +exitdate+ 113 | " Spot Number : "+assignedspotlist.get(spot).getSpotNumber()+ 114 | "\nTotal Time : "+time[0]+" Hour "+time[1]+" Minute "+ 115 | "\nTotal Amount : "+amount+" rupees\n" 116 | ); 117 | 118 | parkingspot.FreeSpot(assignedspotlist.get(spot).getSpotNumber()); 119 | assignedspotlist.remove(spot); 120 | 121 | break; 122 | } 123 | 124 | } 125 | 126 | } 127 | 128 | } 129 | 130 | else if(size == 6){ 131 | 132 | System.out.println("All Car Information : \n"); 133 | for(ParkingTicket pt : assignedspotlist){ 134 | System.out.println("\n\ncar number : "+pt.getAssignedCar().getNumberPlate()+ 135 | " car color : "+pt.getAssignedCar().getCarColor()+ 136 | " car type : "+pt.getAssignedCar().getCarType()+ 137 | "\nparking time : "+pt.getTime()+" date : "+pt.getDate()+ 138 | " spot number : "+pt.getSpotNumber() 139 | 140 | ); 141 | 142 | } 143 | parkingspot.sipe(); 144 | System.out.println(); 145 | } 146 | 147 | } 148 | 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /TotalTime.java: -------------------------------------------------------------------------------- 1 | public class TotalTime{ 2 | 3 | public static int[] CalculateTime(String enterdate, String exitdate, String entertime, String exittime){ 4 | 5 | int firstDay = Integer.parseInt(enterdate.substring(8, 10)); 6 | int lastDay = Integer.parseInt(exitdate.substring(8, 10)); 7 | int firstMonth = Integer.parseInt(enterdate.substring(5,7), 10); 8 | int lastMonth = Integer.parseInt(exitdate.substring(5,7)); 9 | int firstYear = Integer.parseInt(enterdate.substring(0,4)); 10 | 11 | //time calculation for different month days 12 | if( firstMonth != lastMonth){ 13 | int daysInMonth ; 14 | if (firstMonth == 1 || firstMonth == 3 || firstMonth == 5 || firstMonth == 7 || firstMonth == 8 || firstMonth == 10 || firstMonth == 12 ) { 15 | daysInMonth = 31; 16 | } 17 | else { 18 | if (firstMonth == 2) { 19 | daysInMonth = (firstYear % 4 == 0) ? 29 : 28; 20 | } else { 21 | daysInMonth = 30; 22 | } 23 | } 24 | 25 | int Days = daysInMonth - firstDay; 26 | Days = Days + (lastDay - 1); 27 | int HourInTotalDays = Days * 24; 28 | 29 | // Total hour in 1st day 30 | int HoursInFirstDay = 0; 31 | int MinutesInFirstDay = 0; 32 | 33 | if (entertime.substring(6, 8).equals("AM")) { 34 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 35 | HoursInFirstDay = 11 + 12; 36 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 37 | } else { 38 | HoursInFirstDay = (12 - (Integer.parseInt(entertime.substring(0, 2)) + 1)) + 12; 39 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 40 | } 41 | } else if (entertime.substring(6, 8).equals("PM")) { 42 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 43 | HoursInFirstDay = 11; 44 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 45 | } else { 46 | HoursInFirstDay = 12 - (Integer.parseInt(entertime.substring(0, 2)) + 1); 47 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 48 | } 49 | } 50 | 51 | 52 | // Total hour and minute in last day 53 | int HoursInLastDay = 0; 54 | int MinutesInLastDay = 0; 55 | 56 | if (exittime.substring(6, 8).equals("AM")) { 57 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 58 | HoursInLastDay = 0; 59 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 60 | } else { 61 | HoursInLastDay = Integer.parseInt(exittime.substring(0, 2)); 62 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 63 | } 64 | } else if (exittime.substring(6, 8).equals("PM")) { 65 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 66 | HoursInLastDay = 12; 67 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 68 | } else { 69 | HoursInLastDay = 12 + Integer.parseInt(exittime.substring(0, 2)); 70 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 71 | } 72 | } 73 | 74 | // Total hours and minutes 75 | 76 | int hour = HourInTotalDays + HoursInFirstDay + HoursInLastDay; 77 | int minute = MinutesInFirstDay + MinutesInLastDay; 78 | 79 | if (minute >= 60) { 80 | minute = minute - 60; 81 | hour = hour + 1; 82 | } 83 | 84 | return new int[]{hour, minute}; 85 | 86 | } 87 | // time calculation for same month days 88 | else { 89 | if ((lastDay - firstDay) >= 2) { 90 | // Total hour in days 91 | int Days = (lastDay - (firstDay - 1)) - 2; 92 | int HourInTotalDays = Days * 24; 93 | 94 | // Total hour in 1st day 95 | int HoursInFirstDay = 0; 96 | int MinutesInFirstDay = 0; 97 | 98 | if (entertime.substring(6, 8).equals("AM")) { 99 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 100 | HoursInFirstDay = 11 + 12; 101 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 102 | } else { 103 | HoursInFirstDay = (12 - (Integer.parseInt(entertime.substring(0, 2)) + 1)) + 12; 104 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 105 | } 106 | } else if (entertime.substring(6, 8).equals("PM")) { 107 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 108 | HoursInFirstDay = 11; 109 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 110 | } else { 111 | HoursInFirstDay = 12 - (Integer.parseInt(entertime.substring(0, 2)) + 1); 112 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 113 | } 114 | } 115 | 116 | 117 | // Total hour and minute in last day 118 | int HoursInLastDay = 0; 119 | int MinutesInLastDay = 0; 120 | 121 | if (exittime.substring(6, 8).equals("AM")) { 122 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 123 | HoursInLastDay = 0; 124 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 125 | } else { 126 | HoursInLastDay = Integer.parseInt(exittime.substring(0, 2)); 127 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 128 | } 129 | } else if (exittime.substring(6, 8).equals("PM")) { 130 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 131 | HoursInLastDay = 12; 132 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 133 | } else { 134 | HoursInLastDay = 12 + Integer.parseInt(exittime.substring(0, 2)); 135 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 136 | } 137 | } 138 | 139 | // Total hours and minutes 140 | 141 | int hour = HourInTotalDays + HoursInFirstDay + HoursInLastDay; 142 | int minute = MinutesInFirstDay + MinutesInLastDay; 143 | 144 | if (minute >= 60) { 145 | minute = minute - 60; 146 | hour = hour + 1; 147 | } 148 | 149 | return new int[]{hour, minute}; 150 | } 151 | 152 | // for one day difference only 153 | 154 | else if ((lastDay - firstDay) == 1) { 155 | int HoursInFirstDay = 0; 156 | int MinutesInFirstDay = 0; 157 | 158 | if (entertime.substring(6, 8).equals("AM")) { 159 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 160 | HoursInFirstDay = 11 + 12; 161 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 162 | } else { 163 | HoursInFirstDay = (12 - (Integer.parseInt(entertime.substring(0, 2)) + 1)) + 12; 164 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 165 | } 166 | } else if (entertime.substring(6, 8).equals("PM")) { 167 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 168 | HoursInFirstDay = 11; 169 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 170 | } else { 171 | HoursInFirstDay = 12 - (Integer.parseInt(entertime.substring(0, 2)) + 1); 172 | MinutesInFirstDay = 60 - Integer.parseInt(entertime.substring(3, 5)); 173 | } 174 | 175 | } 176 | 177 | // nour and minute in first and last days 178 | int HoursInLastDay = 0; 179 | int MinutesInLastDay = 0; 180 | 181 | if (exittime.substring(6, 8).equals("AM")) { 182 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 183 | HoursInLastDay = 0; 184 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 185 | } else { 186 | HoursInLastDay = Integer.parseInt(exittime.substring(0, 2)); 187 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 188 | } 189 | 190 | } else if (exittime.substring(6, 8).equals("PM")) { 191 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 192 | HoursInLastDay = 12; 193 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 194 | } else { 195 | HoursInLastDay = 12 + Integer.parseInt(exittime.substring(0, 2)); 196 | MinutesInLastDay = Integer.parseInt(exittime.substring(3, 5)); 197 | } 198 | 199 | } 200 | int hour = HoursInFirstDay + HoursInLastDay; 201 | int minute = MinutesInFirstDay + MinutesInLastDay; 202 | if (minute >= 60) { 203 | minute = minute - 60; 204 | hour = hour + 1; 205 | } 206 | return new int[]{hour, minute}; 207 | 208 | } 209 | 210 | // for one single day 211 | 212 | else if ((lastDay - firstDay) == 0) { 213 | int ParkedHour = 0; 214 | int ParkedMinute = 0; 215 | int ExitHour = 0; 216 | int ExitMinute = 0; 217 | int hour = 0; 218 | int minute = 0; 219 | 220 | if (entertime.substring(6, 8).equals("AM") && exittime.substring(6, 8).equals("AM")) { 221 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 222 | hour = Integer.parseInt(exittime.substring(0, 2)); 223 | minute = (60 - Integer.parseInt(entertime.substring(3, 5))) + Integer.parseInt(exittime.substring(3, 5)); 224 | } else { 225 | hour = Integer.parseInt(exittime.substring(0, 2)) - (Integer.parseInt(entertime.substring(0, 2)) + 1); 226 | minute = (60 - Integer.parseInt(entertime.substring(3, 5))) + Integer.parseInt(exittime.substring(3, 5)); 227 | } 228 | } else if (entertime.substring(6, 8).equals("PM") && exittime.substring(6, 8).equals("PM")) { 229 | 230 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 231 | hour = Integer.parseInt(exittime.substring(0, 2)); 232 | minute = (60 - Integer.parseInt(entertime.substring(3, 5))) + Integer.parseInt(exittime.substring(3, 5)); 233 | } else { 234 | hour = Integer.parseInt(exittime.substring(0, 2)) - (Integer.parseInt(entertime.substring(0, 2)) + 1); 235 | minute = (60 - Integer.parseInt(entertime.substring(3, 5))) + Integer.parseInt(exittime.substring(3, 5)); 236 | } 237 | 238 | } else if (entertime.substring(6, 8).equals("AM") && exittime.substring(6, 8).equals("PM")) { 239 | 240 | if (Integer.parseInt(entertime.substring(0, 2)) == 12) { 241 | ParkedHour = 12; 242 | ParkedMinute = 60 - Integer.parseInt(entertime.substring(3, 5)); 243 | } else { 244 | ParkedHour = 12 - (Integer.parseInt(entertime.substring(0, 2)) + 1); 245 | ParkedMinute = 60 - Integer.parseInt(entertime.substring(3, 5)); 246 | } 247 | 248 | if (Integer.parseInt(exittime.substring(0, 2)) == 12) { 249 | ExitHour = 0; 250 | ExitMinute = Integer.parseInt(exittime.substring(3, 5)); 251 | } else { 252 | ExitHour = Integer.parseInt(exittime.substring(0, 2)); 253 | ExitMinute = Integer.parseInt(exittime.substring(3, 5)); 254 | } 255 | hour = ParkedHour + ExitHour; 256 | minute = ParkedMinute + ExitMinute; 257 | 258 | } 259 | 260 | if (minute >= 60) { 261 | minute = minute - 60; 262 | hour = hour + 1; 263 | } 264 | 265 | return new int[]{hour, minute}; 266 | } 267 | } 268 | return new int[] {}; 269 | } 270 | 271 | } --------------------------------------------------------------------------------