Workshop 2 - Part 1 PDF

Title Workshop 2 - Part 1
Course Object Oriented Design
Institution University of Wolverhampton
Pages 2
File Size 136 KB
File Type PDF
Total Downloads 25
Total Views 150

Summary

Part one of the second week workshop ...


Description

Object Oriented Design and Programming For this workshop, and others, use Eclipse as your Development IDE. Eclipse is available in Apps Anywhere. Steps: Create a workspace (a folder) in your network drive. Call the workspace 5CS019. In it create a Java Project using Eclipse. Call the project Week1. A src package is created automatically by Eclipse. In src, create your own package, and call it week1src. Create a Car.java class inside week1src and copy the code listing shown below. It should compile fine. Now create a package that will contain your test case file. Call the package week1Testsrc. To create the test case class for your Car.java, do the following: a)select week1Testsrc, left click this package, select New—>JUnit Test Case. Give your test class the name CarTest. b) On Class Under test - select browse - then type Car and select the Car class you created in the week1src package Now you are ready to test your methods. This weeks lecture will be helpful if you need to consult it again. The task brief

Consider the following implementation of a Car class. Perform unit tests of the above program. Test the following: 1) Setters 2) constructor The text file Car.java /** * @author John Kanyaru */ public class Car { //instance variables private String model; private int tankSize; private double manfMPG; //constructor public Car(String model, int tank, double mpg) { this.model = model; tankSize = tank; manfMPG = mpg; } //set value of model public void setModel(String model) { this.model = model; } //Return model public String getModel() { return model; } //set value of model

Object Oriented Design and Programming public void setTankSize(int tank) { tankSize = tank; } //Return tankSize public int getTankSize() { return tankSize; }

//estimate distance car can travel public double estimateDistance() { //there are 0.22 gallons per litre return tankSize * manfMPG * 0.22; } } }...


Similar Free PDFs