Part II: The elevators in our building have an 1100 lb. load limit. Determine which people in the list above get on the elevator. Print their names, weights, total weight, and how many got on.

Part III: Rearrange these people in ascending sequence by weight and print the two arrays. Determine again how many may ride the elevator, printing out their names, weights, total weight and the number of how many people got on.

Part IV: Rearrange these people in ascending sequence by name (USE A DIFFERENT SORT ALGORITHM THAN THE ONE YOU USED IN PART II) and print the two arrays. Determine again how many may ride the elevator, printing out their names, weights, total weight and the number of how many people got on.

Part V: Have the program determine which method allowed the most people to get on the elevator.

I have made multiple classes, but I am completely lost of what to do next.
public class Person
{
private String name;
private int weight;

I like your thinking, but the assignment says "two arrays" and not one array of Person objects. I'd probably still do it your way, if you think you can get away with it.

"elev" is a bad name for your array variable in your People class. Just call it "people" or "persons". There is no reason for the People class to know anything about elevators. The class name itself is not great -- class names should generally be singular nouns. "Group" might be better.

You need to write your sort methods (probably in your People class) and then you need a Person[] fillElevator(Person[] potentialRiders, int weightLimit) method in your Elevator class. Create your Person[] result array, then iterate through potentialRiders, adding each Person to result until you reach weightLimit. You also need a listRiders() method.

That should get you going. Show us what you come up with, and remember to use CODE tags.

fillElevator() goes in your Elevator class, not your Group class. Group knows about a collection of Persons, but doesn't (shouldn't) know anything about elevators. Also, weightLimit is going to be passed into the method, not assigned within it (unless it's an instance variable, which it probably should be -- an Elevator should know its weightLimit). You have one Person[] passed in to the method (potentialRiders) and you need to create another Person[] that you will return (result). And since we're using raw arrays, you'll probably need two passes -- one to get the count, and another to actually load the array. (It's clumsy, and that's why developers tend to prefer ArrayList.)

sortWeight() needs a return type (maybe void?). I would probably call it sortByWeight(), make it void, and have it just sort the internal persons array in place. Actually, it seems that's what you're doing, but you've passed in two parameters that you never use.

This is not going to work:

Java Code:

if (persons[j] < persons[weightIndex])

because Person is not Comparable (maybe you want getWeight() here?) Also,

Part V: Have the program determine which method allowed the most people to get on the elevator.

I especially like this part of the assignment so I dusted off an old knapsack class of mine; a knapsack has a capacity (your elevator can lift 1100lbs), a person takes up capacity (their weight) and have a value (all equal for each person). How to fill up the knapsack given the capacity constraint so that the sum of the values is maximized (read: as many peoply can be stuffed in that elevator).

A person is either stuffed in that elevator or not. When s/he is, the problem is reduced to a lesser capacity and a set of persons minus this current person. When a person doesn't fit in the elevator obviously we don't even try to stuff him in. That's how my program works. It reads the following data file:

Yeah, JosAH's method does give the absolute solution to the problem at hand, but I think what your teacher had in mind was to just fill the persons into the elevator sequentially from your array, first unsorted, then sorted by weight, then sorted by name. Then you compare the results to see which array sequence gives the best (most persons) result. If you decide to use Jos' solution, be sure to study it and understand it, in case your teacher gets suspicious, since it's a bit more advanced than what the assignment was about (that is, if I understood the instructions correctly).
Oh, and to Jos, really cool solution by recursion. I'm currently attending a class that focuses on recursion at my uni, this will come in pretty handy!

It is one program consisting of multiple classes in multiple source code files. This is not at all unusual for Java.

-Gary-

EDIT: To be clearer, I was talking about LostInJavaLand's code. JosAH's is one program consisting of multiple classes in one source code file. This is legal because only one of the classes in the file is public and has a main() method.

Well, let's start with his Person class. It's public, has a public constructor, and several public methods. That means that any other code can create Person objects and call their methods, in very much the same way that your code can create ArrayList or JTextField or Random objects. His People class takes advantage of that and creates an array of Person objects. And his Elevator class in turn creates and uses a People object.

You do have to make sure that all the necessary .class files are in directories that are on your CLASSPATH, but other than that and the access restrictions (public, private, protected, etc.) there's not much to it.

Oh, and to Jos, really cool solution by recursion. I'm currently attending a class that focuses on recursion at my uni, this will come in pretty handy!

Thanks; the core of the algorithm is really simple: assume all those people are standing in line; the range of people [0, allowed] can potentially be put in the elevator. For every person the algorithm either tries to put that person in the elevator (if it can still fit the person in) or it doesn't. Note that first the 'don't take' option is executed all the way down to where no more persons are left to chose; only then a new solution is created and people are stuffed in when the algorithm (recursively) reaches the 'take' option. Basically all combinations are checked and the best solution is kept. At the end some statistics are printed: the higher the 'cut' number (depending on the order of the people) the better the algorithm performed. Try different orders for those people and see for yourself.

It's cute isn't it? And the bounding condition is just trivial: if a person is too heavy to fit in the elevator (given a certain filling already) there's no need to explore all combinations with that person on board because they're all infeasible. Even for this small problem (12 persons) it had to travers 4096 possibilities but by applying 342 cuts it only had to investigate 3526 possibilities). Cutting on branches always pays back. Personally I'm too stupid to come up with a more 'intelligent' cut strategy.

r035198x(<----choking from all the dust from Jos' sack.

There are a whole lot more tricks in there so you'd better watch out! ;-)