Home-->Resources-->Layout
 

Layout

Shown below is a sample of code with full commenting. Do not worry too much about the code itself but observe the style of commenting and the use of whitespace. Code that you write in class and especially code that you submit will be expected to be laid out in a similar style.

public class Car {
  
  
  
    /**
     * The color of the car
     *
     */
    private String color;
  
    
    
    /**
     * The size of the engine (in litres)
     *
     */
    private float engineSize;
    
    
  
    /**
     * The number of people that can fit in the car
     *
     */
    private int numPeople;



    /**
     * Indicates whether or not the engine is currently running or
     * not.
     *
     */
    private boolean running;



    /**
     * Create a new instance with the specified color, engine size and 
     * capacity.
     *
     * @param color the color of the car
     * @param engineSize the size of car's engine
     * @param numPeople the capacity of the car
     *
     */
    public Car(String color, float engineSize, int numPeople) {
        this.color = color;
	this.engineSize = engineSize;
	this.numPeople = numPeople;
	this.running = false;
    }


    
    /**
     * Return the color of the cor
     *
     * @return the color of the car
     *
     */    
    public String getColor() {
	return color;
    }



    /**
     * Return the engine size of the car.
     *
     * @return the engine size
     *
     */
    public float getEngineSize() {
	return engineSize;
    }
    
    
    
    /**
     * Return the number of people that can fit in the car.
     *
     * @return the capacity of the car
     *
     */
    public int getNumPeople() {
	return numPeople;
    }



    /**
     * Return whether or not the engine is currently running.
     *
     * @return true if the engine is running;
     * false otherwise
     *
     */
    public boolean getRunning() {
	return running;
    }



    /**
     * Switch the engine on.
     *
     **/
    public void turnOn() {
	running = true;
    }


    
    /**
     * Switch the engine off.
     *
     **/
    public void turnOff() {
	running = false;
    }


    
}

Notice the following:


Last updated at 8:48pm, Thursday September 22nd 2011
Dr Natalia Beloff (N.Beloff@sussex.ac.uk)