SE200:March 18

From Marks Wiki
Jump to navigation Jump to search

Some Information

Hello

This is to announce the second shadow class for this year, hosted by SESA. Based on feedback from our various spies in your classes , we will be running through a brief overview of the basic concepts people still seem to struggle with, followed by the topics of constructors, inheritance etc.

What: 2nd Shadow Class on JAVA When: Tuesday, 18th of March, 1pm to 2pm Where: Engineering Lab 1.312, Level 3 - where the engineering cafe is. Cost: FREE (members allowed only!)

Don't worry if you haven't signed up already! Come along to the class and sign up there and collect your membership card. Its $5 to sign up for the whole year.

Cheers, SESA Exec Team

Code from the Vehicle project

Main.java

package vehicles; 

public class Main { // This class does not need to be called "Main", it is just convenient.

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
 		Vehicle glensBike = new Vehicle(2, "Glen");
		System.out.println("Glen's bike has a " + glensBike.engineBrand +
				" engine!");
		glensBike.go(200);
		System.out.println("Glen's bike has a mileage of " + glensBike.getMileage());
		System.out.println("Glen's bike has a mileage of "
				+ glensBike.getMileage());
		//Add Glen as a passenger
		glensBike.passengers.add("Glen");

	}

} 

Vehicle.java

package vehicles;

import java.util.Vector; //Required to use the Vector class

/**
 * This class represents a vehicle.
 * It is sweet.
 * @author grob083
 *
 */
public class Vehicle { 
	
	int noOfWheels; //Represents number of wheels.
	String engineBrand;
	private int mileage;
 	Vector<String> passengers; //Set to null by default.
	
	/**
	 * Constructor for a Vehicle. =O
	 */
	public Vehicle(int wheels, String engineBrand) {
		this.noOfWheels = wheels;
		this.engineBrand = engineBrand;
		this.mileage = 0;
		this.passengers = new Vector<String>(); //Not null anymore, we can
		//use it safely now.
	}
	
	public void go(int distance) {
		// We use this to make our vehicle go!
		//Commenting ftw!
		this.mileage += Math.abs(distance);
		//Math.abs() is built into Java and available automatically
 	}
	
	public int getMileage() {
		//returns our mileage.
		return this.mileage;
	}

}

TestVehicle.java

//Junit Test Class
//Conventionally named TestXXX where XXX is the class it tests.

//To get this working you will need to click on the lightbulb beside
//the error message and click "Add Junit to the build path" and
// import "TestCase".
package vehicles;

public class TestVehicle extends TestCase {
	Vehicle gBike = null; //This is the bike we will be testing. 
	
	public void setUp() {
		gBike = new Vehicle(2, "Glen");
	}
	
	public void tearDown() {}
	
	public void testGlen() {
		assertEquals(gBike.noOfWheels, 2);
		assertTrue(true);
		assertFalse(false);
	}
	
	public void testAnotherTest(){
		assertEquals(gBike.engineBrand, "Yamaha"); //expect to fail
		
	}
 
}

Also Note

We will provide time for you to ask about any problems you have been having so be sure to think of some specific questions you want to ask us.

--Glen