class look for nouns in the process
methods: verbs
each method is the responsibility of a single class
private int numberOfPassengers; public void addPassenger(int n) { if (numberOfPassengers + 1 < numberOfSeats) { numberOfPassengers++; } } public int getPassengerCount() { return numberOfPassengers; }
import java.util.ArrayList; public class Car { private int numberOfSeats; private ArrayListpassengers; private int numberOfPassengers; public Car(int numberOfSeats) { this.numberOfSeats = numberOfSeats; passengers = new ArrayList (); } /** * Adds a passenger to this car, provided that there is space. * @param name the name of the passenger */ public void addPassenger(String name) { if(getPassengerCount() + 1 < numberOfSeats) { passengers.add(name); } } public int getPassengerCount() { return passengers.size(); } public String getPassengerList() { return passengers.toString(); } }