File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Need help with how to involving calculations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need help with how to involving calculations" Watch "Need help with how to involving calculations" New topic

Need help with how to involving calculations

Connie Kamrowski

Joined: Aug 15, 2004
Posts: 23
Ok here goes.

I have a database which stores details of resources and their availability for projects.

In the main table it stores a staff id and an availability percentage which is the default time each resource has available for allocation (ie 85%)

In a second table it stores entries for start and end dates of allocations and the percentages of each allocation ie 01/01/2005 03/03/2005 35%, 10/02/2005 15/02/2005 15%)

I need to create a manager which will take a start and end date and then check to see which resources are not fully allocated in these dates and return an array of available resources. I also need to warn the user if they are allocating more than 100% for a resource.

So I basically need to get all the resources intop an array, test to see if they are available between the dates (their records do not total 100%) and then throw the available ones into a second array to populate the list, when the user chooses one of these and adds it I have to check that the entires now do not total over 1oo% and warn if they do.

I am at a loss as to how to work this, all suggestions appreciated.


**How much deeper would the ocean be if Sponges didn't grow in it?**
marc weber

Joined: Aug 31, 2004
Posts: 11343

My approach would be to consider defining your "resources" as objects. For example, you might define a class called StaffResource with methods like...

String getID() returns staff ID.

int[] dedicated(Date startDate, Date endDate) returns an array of ints, where each element represents a date within the indicated range, and the value represents the resource's allocated time for that date. For example, if you entered a range of 4 days, you might get back { 85, 85, 100, 60, } indicating how busy that person is on each of those 4 days. (Or instead of simple ints, you might return a Map with Date/Allocation pairs.)

Map[] projectBreakdown(Date d) returns a Map of project/allocation pairs for the indicated date. For example, for a specific date, the Map might be (ProjectA, 10), (ProjectF, 25), (ProjectQ, 50). You might use this for a "close up" look at a particular date.

boolean validateAllocation(Date validationDate) returns a boolean indicating whether the resource's allocations on an indicated date surpass 100. Probably called internally by set methods.


Then you could define another class that manages a List of StaffResource objects, with something like...

Map[] resourcesFor(Date d) returns a Map of StaffResource/Availability pairs for the indicated date. For example, (ID99999, 10), (ID99998, 25), ... indicating that staff member 99999 has 10% of their time free on the given date, and staff member 99998 has 25% of their time free.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Connie Kamrowski

Joined: Aug 15, 2004
Posts: 23

That actually helps a lot.

Sometimes the hardest part is getting started.
I agree. Here's the link:
subject: Need help with how to involving calculations
It's not a secret anymore!