Hey here is the task.

1. Design a class, called People, that includes a person’s name and a weight with a constructor, 2 getter methods, and a toString() method.
2. Design a second class, called PeopleList (like the IntegerList lab or CDCollection class) that has an array of People, and methods to construct a list of a given size, add to a list, print a list (toString() method).
3. Add a class Driver to manage the PeopleList calling each method to add a item, print the array, sort the PeopleList (two different methods), howMayGotOnArray, etc.


the People class and the PeopleList are compiling. I can add people to the list and stuff its kind of the last bit where I have to find out how many can get on and such.

here is my code for all three files

people file

import java.text.NumberFormat;
public class People
{
	private String name;

	private int weight;

    public People(String Personname, int Personweight)
    {
    	name = Personname;
    	weight = Personweight;


    }

    public String getName()
    {
    	return name;
    }
    public int getWeight()
    {
    	return weight;
    }

    public String toString()
    {
      	String description;

    	description = name +"\t"+ weight;

    	return description;
    }



}

peopleList file

public class PeopleList
{


	private People[] peopleList;
	private int weights;
	private String names;
    private int count;

    public PeopleList()
    {
    	peopleList = new People[100];

    	names = "no one";
    	weights = 0;
    	count = 0;
    }
    public void addPeople(String name, int weight)
    {

    	peopleList[count] = new People(name, weight);
    	count++;
    }
    public String toString()
    {
    	String listing;

    	listing ="--------------------------------------";
    	listing +="\nThe number of people = " +count;
    	listing += "\n\nPeople List: \n\n";

    	for(int gopeople = 0; gopeople < count; gopeople++)
    	{
    		listing += peopleList[gopeople] +"\n";
    	}

    	return listing;
    }


}

and my Driver File

public class Driver
{


    public static void main(String[] args)
    {
       PeopleList elevator = new PeopleList();

       elevator.addPeople("Ann", 30);
       elevator.addPeople("Bob", 150);
       elevator.addPeople("Ralph", 305);


       System.out.println(elevator);

       elevator.addPeople("Tim", 225);
       elevator.addPeople("Barbra", 135);

       System.out.println(elevator);
    }
}

any help is fully appreciated

add the weight of each person to weights, and verify if the capacity of the elevator can take the extra weight before going over it's maximum.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.