Week 2 How To Design and Implement A Class

Week 2 How To Design and Implement A Class - 1 Designing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Designing and Implementing a Class: An Example Design a car class that has the following properties and methods:: TankSize Property: This holds the number of gallons of gas the car’s tank can hold MilesTraveled: The property holds the number of miles the car traveled on a tank of case Model Property: This property stores the model of the car CalcGasMileage Method: This method divides the MilesTravelled Property by the TankSize Property and returns the answer to the module that called it. To model this class, you should create a class diagram that looks like this: Car +Numeric TankSize +Numeric MilesTraveled +String Model +Numeric CalcGasMileage( ) Notice how the name of the class is in the top row of the class diagram. In the middle row are the names of its properties. The plus signs next to each indicate the properties are public, not private. If they were private, negative signs would be used. Each public property (which is really just a variable) has a data type associated with it – MS Visio doesn’t provide the numeric data type we were used to seeing in Week1 for classes, so we are using VB data type capable of holding a fractional value -- a tank size could be 30.1 gallons, for example. The model property is a string, because it is a word, such as Corolla, or Accord if the user wants to use it. In the bottom row is the CalcGasMileage method – it too has a plus sign because it is accessible by modules outside the class (public). It accepts no arguments, as no parameters are listed in its parentheses. However, it does return a miles per gallon figure, which is a numeric data type. There is more to this class, however, than just the class diagram. The CalcGasMileage method has its own logic. We need to model this logic using a flowchart or pseudo code. The Logic of a Class Method: An Example Below is a flow chart of the CalcGasMileage method: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course BIS 311 taught by Professor Marshburn during the Fall '08 term at DeVry Cincinnati.

Page1 / 5

Week 2 How To Design and Implement A Class - 1 Designing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online