Presentation is loading. Please wait.

Presentation is loading. Please wait.

COP 2800 Lake Sumter State College Mark Wilson, Instructor.

Similar presentations


Presentation on theme: "COP 2800 Lake Sumter State College Mark Wilson, Instructor."— Presentation transcript:

1 COP 2800 Lake Sumter State College Mark Wilson, Instructor

2 Software Development Process

3  Extract requirements  Define an architecture  Implement the design  Code  Test  Repeat

4  DRY: Don’t repeat yourself  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

5  Occam’s Razor: “Entities must not be multiplied beyond necessity”  Keep It Simple, Stupid

6  “You Ain’t Gonna Need It”

7  Use only as many variables as necessary and no more.  Perform a given function in only one place.  Smaller classes and methods provide greater flexibility  If it isn’t in the specification, don’t put it in.

8 Arrays

9  Index is zero based

10  Any of the primitive types Byte Char Short Int Long String Float Double Boolean  Object reference Object reference is a collection of bits Acts like a pointer but details are JVM specific  Contents of the array must agree with the array type

11  Arrays are always objects  Arrays may contain primitives  Arrays may contain object references  Arrays have an attribute…sort of length  Arrays have methods: asList binarySearch copyOf copyOf Range deepEquals deepHashCode deepToString equals fill hashCode sort toString

12 type name [size]; int scores [10]; type name [] = {value, value, … value}; int scores [] = {1,2,3,4,5,6,7,8,9,10}; type[] name; name = new type[size]; int[] scores; Scores = new int[10];

13  Works like an array of (array) objects type[size][size] name; String[][] names = { {“Mr. “, “Mrs. “, “Ms. “}, {“Smith”, “Jones”} };

14 ClassName[] Name; Name = new ClassName[number]; Bicycles[] MyBikes; //declare Bicycle array variable MyBikes = new Bicycles[5]; //create a Bicycle array with 5 elements //all the references are null MyBikes[0] = new Bicycle; //create a Bicycle object in element 0 MyBikes[0].make = “Schwinn”; //assign the value “Schwinn” to the //make instance variable

15 Attributes, Behaviors and Instances

16  State = Characteristics = Attributes = Instance Variables  Behavior = Methods  Methods use Instance Variables  Class is a blueprint for Objects

17 Instance VariableLocal Variable DeclarationDeclared in class but, not in methods Declared in methods but, not in class Initial valueZero or null by default Must be set before use in order to compile ScopeKnown to entire classKnown only within the scope where set

18  Methods have return type Primitives Class ‘void’ – no value it returned  A method uses parameters  A caller passes arguments  Methods may return values  Methods with a type (not void) must return a value of that type  This constitutes an interface contract Callers must provide parameters a method expects Methods, if typed, must return a value  As long as the interface contract is respected, the method is free to accomplish its function any way it wishes

19  “Data hiding” allows methods to change  Keep instance variables “ private ”  Use public methods to access instance variables  Accessors == Getters  Mutators == Setters

20  Refactor your Nim program to employ objects and encapsulation. Employ DRY and Occam’s Razor in your design. Think about super classes and their potential role. Also consider future reuse. Game play should remain the same.  The program class containing ‘main’ is necessary but not sufficient.  Due 2359 the day before the next class.


Download ppt "COP 2800 Lake Sumter State College Mark Wilson, Instructor."

Similar presentations


Ads by Google