Results 1 to 9 of 9
Thread: need help figuring out algorithm
- 12-14-2011, 11:55 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
need help figuring out algorithm
For my comp sci class I'm making a program that a library would use.
Part of it has to be able to calculate the late fee for a book.
I've figured how to get the current day/month and all that stuff, but
for the life of me I can figure out an equation to calculate how late the book is.
To simplify everything I'm just assuming that all months have 31 days.
Any help you could provide would be much appreciated.
- 12-15-2011, 12:02 AM #2
Member
- Join Date
- Nov 2011
- Posts
- 65
- Rep Power
- 0
Re: need help figuring out algorithm
Well I'm assuming you need to have the date it was rented kept track of then subtract that from the current date?
I'm not actually sure if java supports that or has a days360 feature like excel perhaps someone know more try googling it a bit
one option would be to store the month and date seperatly or to read them seperatly and multiply the month *30 + the days?
- 12-15-2011, 12:18 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Re: need help figuring out algorithm
i have the day the book was taken out and the month stored in seperate text files and am able to read from the
text files no problem.
Oh and i forgot to mention that no late fee is owed until 30 days after the book is taken out.
I have a function for if the book was rented on the same month as it was returned, that works fine.
My problem is, for example if the book was taken out on october 12 and returned on december 14,
i cant make an equation to figure out how many days the book is late byLast edited by mnorman; 12-15-2011 at 12:21 AM.
- 12-15-2011, 12:21 AM #4
Member
- Join Date
- Nov 2011
- Posts
- 65
- Rep Power
- 0
Re: need help figuring out algorithm
excellent well id sugget getting the text into a String or array by using by using a reader and a loop for each value
then I would use a if command if days>30
days/30*2
else {"0"}Last edited by kevinn205; 12-15-2011 at 12:40 AM.
- 12-15-2011, 12:36 AM #5
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Re: need help figuring out algorithm
is the $ sign nessary or is that a typo, and if it is what does it do?
also the way i have it set up days is never greater than 30
im using
Calendar calendar = new GregorianCalendar();
int newMonth = calendar.get(Calendar.MONTH);
int newDay = calendar.get(Calendar.DAY_OF_MONTH);
to get the date if thats any help
- 12-15-2011, 12:43 AM #6
Member
- Join Date
- Nov 2011
- Posts
- 65
- Rep Power
- 0
Re: need help figuring out algorithm
Wouldnt compile with the $ sign it was just to label so you understood what i meant, the if statement also isnt formatted correctly it was just saying you should use one :D
int Both = newMonth*30 + newDay;
system.out.println(Both);
- 12-15-2011, 12:47 AM #7
Member
- Join Date
- Dec 2011
- Posts
- 15
- Rep Power
- 0
Re: need help figuring out algorithm
oh haha ok thanks :p
and thanks that helped alot, it works now :D
- 12-15-2011, 12:49 AM #8
Member
- Join Date
- Nov 2011
- Posts
- 65
- Rep Power
- 0
Re: need help figuring out algorithm
Np, best of luck with the project!
- 12-15-2011, 01:41 AM #9
Similar Threads
-
Help figuring out a regular expression!
By srs in forum New To JavaReplies: 1Last Post: 12-10-2011, 02:51 AM -
Figuring out for????
By seanfmglobal in forum New To JavaReplies: 4Last Post: 07-21-2011, 09:47 PM -
Help with figuring out the output
By Yakg in forum New To JavaReplies: 3Last Post: 12-13-2010, 09:32 AM -
problem figuring out how to carry over and drop values in currency.
By Turismo in forum New To JavaReplies: 3Last Post: 06-10-2010, 03:42 PM -
figuring out the current colour of my appelet
By vortexprogramming in forum New To JavaReplies: 2Last Post: 07-15-2008, 04:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks