Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
3.4 kB
2
Indexable
Never
import java.time.LocalDate;

public class MyDate {
    private int day;
    private int month;
    private int year;
    private LocalDate borrowDate;

    public MyDate(int day, int month, int year) {
        this.day = day;
        this.month = month;
        this.year = year;
    }

    public MyDate() {

    }

    public void setYear(int year) {
        this.year = year;
    }

    public LocalDate returnDate(int borrowerID, int resourceID) {
        borrowDate = LocalDate.now();
        switch (borrowerID) {
            case 1: // student
                switch (resourceID) {
                    case 1:{
                        LocalDate returnDateStudents = borrowDate.plusDays(30); //book
                        return returnDateStudents;}
                    case 2:{
                        LocalDate returnDateStudents = borrowDate.plusDays(60); //ebook
                        return returnDateStudents;}
                    case 3:{
                        LocalDate returnDateStudents = borrowDate.plusDays(14); //journal
                        return returnDateStudents;}
                    case 4:
                        LocalDate returnDateStudents = borrowDate.plusDays(10); //dissertation
                        return returnDateStudents;
                    default:
                        break;
                }

            case 2:{ // staff
                LocalDate returnDateStaffAndFaculty = borrowDate.plusDays(60);
                return returnDateStaffAndFaculty;}

            case 3: // faculty
                LocalDate returnDateStaffAndFaculty = borrowDate.plusDays(60);
                return returnDateStaffAndFaculty;
            default:
                break;
        }
        return borrowDate;
    }

    public LocalDate extendReturnDate(int borrowerID, int resourceID) {
        LocalDate currentDate = LocalDate.now();
        switch (borrowerID) {
            case 1:
                switch (resourceID) {
                    case 1: {
                        currentDate = currentDate.plusDays(30); // book
                        return currentDate;
                    }
                    case 2: {
                        currentDate = currentDate.plusDays(60); // ebook
                        return currentDate;
                    }
                    case 3: {
                        currentDate = currentDate.plusDays(14); // journal
                        return currentDate;
                    }
                    case 4:
                        currentDate = currentDate.plusDays(10); // dissertation
                        return currentDate;
                    default:
                        return currentDate;
                }

            case 2: {
                currentDate = currentDate.plusDays(60);
                return currentDate;
            }

            case 3:
                currentDate = currentDate.plusDays(60);
                return currentDate;
            default:
                break;
        }
        return currentDate;
    }

    public String toString() {
        return String.format("%d/%d/%d", day, month, year);
    }

    // public static void main(String[] args) {
    //     MyDate date = new MyDate();
    //     System.out.println(date.returnDate(1, 1)); // 18
    //     System.out.println(date.extendReturnDate(1, 1)); // 30
    // }

}