getRemainingPeriod()

MohamedBenSalha

Neues Mitglied
Hi, guys,
i program in java
I actually wanted a program for a library system where you can borrow media and so on. 3 types of people can borrow media: students, staff and externals, who can borrow media for 90 days, unlimited and 30 days
I did not get along with the operation getRemainigLoanPeriod(). I did not know how to implement it. I made it abstract first, because it depends on the type of people.
I did not know exactly how to calculate the time. I mean, for example, if I ask for the remaining loan period tomorrow, it had to be less by 1 than today.
do either of you have a solution or something?
Thanks in advance
 

mihe7

Top Contributor
You'll have to remember the end of loan date. Then, you can calculate the number of days between today and the end of loan date, easily. For example:
Java:
Period period = Period.between(LocalDate.now(), getEndOfLoan());
return period.getDays();
 

Dompteur

Top Contributor
Defining getRemainigLoanPeriod() is a good first step.

As you are dealing with "unlimited", what is the type of the result value of "getRemainigLoanPeriod()" ?
If it's int and you should use some magic number for unlimited (like 999), than for staff getRemainigLoanPeriod() can return this number.

For students and externals, the calculation of the result value of getRemainigLoanPeriod is also quite easy :
* Calculate the current duration of the borrowing (today minus date of borrow)
* Subtract it from 90 / 30
 

Neue Themen


Oben