I want to make a booking system in java, and I cannot check the dates given between another dates

344
March 04, 2017, at 1:29 PM

I want to make a booking system for rooms. The user will insert a date from startDate to endDate. Alright, after thats lets say that another user will want to book the same room in between the same dates as the user.So, if the first user booked the room from 2017-1-1(yyyy-MM-dd) to 2017-1-8, the next user cannot book the same room in exactly these dates or from 2017-1-3 to 2017-1-10.the user will be informed that he/she can book only before 1/1 or after 1/8.

Here is my code:

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
    public static void main(String[] args) {

        String startDateFirst = "2016-1-1";
        String endDateFirst = "2016-1-4";
        Date convertedStartDateFirst = convertDate(startDateFirst);
        Date convertedEndDateFirst = convertDate(endDateFirst);
        List<Date> myList = new ArrayList<Date>(getDaysBetweenDates(convertedStartDateFirst,convertedEndDateFirst));

        String startDate2 = "2016-1-1";
        String endDate2 = "2016-1-3";
        Date convDateStr2 = convertDate(startDate2);
        Date convDateEnd2 = convertDate(endDate2);
        List<Date> myListSecond = new ArrayList<Date>(getDaysBetweenDates(convDateStr2,convDateEnd2));
        System.out.println("FIRST BOOKING: " + getDaysBetweenDates(convertedStartDateFirst,convertedEndDateFirst));
        System.out.println("SECOND BOOKING: " + getDaysBetweenDates(convDateStr2,convDateEnd2));

       for (int i=0; i<=myListSecond.size(); i++)
        {
                if ((myList.get(i).getTime() >= myListSecond.get(i).getTime() && myList.get(i).getTime() <= myListSecond.get(i).getTime())) {
                    System.out.println(myListSecond.get(i) + " is taken");
                } else if (myList.get(i).equals(myListSecond.get(i))) {
                    System.out.println(myListSecond.get(i) + " equal");
                } else {
                    System.out.println(myListSecond.get(i) + "is not");
                }

        }

    }
    public static Date convertDate(String strDate)
    {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        try{
            Date date = format.parse(strDate);
            //String finalDate = format.format(date);
            return date;
        }catch (ParseException e)
        {
        }
        return null;
    }
    public static List<Date> getDaysBetweenDates(Date startdate, Date enddate)
    {
        List<Date> dates = new ArrayList<Date>();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(startdate);
        while (calendar.getTime().before(enddate))`enter code here`
        {
            Date result = calendar.getTime();
            dates.add(result);
            calendar.add(Calendar.DATE,1);
        }
        return dates;
    }
}

Although, in getDaysBetweenDates I get the date but with -1 date, why? and how do I return the exactly dates.

Rent Charter Buses Company
READ ALSO
NetBeans and Inno Setup don&#39;t produce a proper Native .exe

NetBeans and Inno Setup don't produce a proper Native .exe

I've created a JavaSE app in Netbeans and am using Inno Setup 5 to generate what I thought was a complete Windows installation, including JREAs instructed, I have checked the NetBeans property boxbox for Native, and have Inno Setup 5 in the Path

445
removing object from arraylist leaves null

removing object from arraylist leaves null

I have a function called resolveClash, which I send an array (in this case - combinsFinal) with 2 or more objects in it of type ModuleLecturerStudentCombination (this is my own class)Essentially what the resolveClash function does is it puts the array into an arraylist,...

454
sql query order by current date

sql query order by current date

SELECT *, DATEDIFF(COLUMN_DATE, CURDATE()) AS diff FROM TABLE_GAMES ORDER BY CASE WHEN diff < 0 THEN 1 ELSE 0 END, diff

631
Java: characters

Java: characters

The assignment:

547