Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per.

Similar presentations


Presentation on theme: "Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per."— Presentation transcript:

1 Announcements Final Exam: TBD

2 Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per object) static method: no invoking object (invoke with className.method()) Example: Math class methods threeToFifth = Math.pow(3.0, 5.0);

3 Static Variable Example public class MyClass { … private final int STARTID = 1; //the following are one per object private int IDNum = -1; //the following are one per class private static int nextIDNum = STARTID; public MyClass() { … IDNum = nextIDNum; nextIDNum++; }

4 Client Program for MyClass public static void main(String [] args) { … myClass first = new myClass(); //IDNum is 1 myClass second = new myClass(); //IDNum is 2 }

5 Static Method Example public class MyClass { … private final int STARTID = 1; //the following are one per object private int IDNum = -1; //the following are one per class private static int nextIDNum = STARTID; … public static int GetNextID() { // Called by MyClass.GetNextID() return nextIDNum; }

6 Client Program for MyClass public static void main(String [] args) { … myClass first = new myClass(); //IDNum is 1 myClass second = new myClass(); //IDNum is 2 System.out.println(“Next ID Num is:” + MyClass.GetNextID()); //Displays ID 3 }

7 Other Class Methods boolean equals( objType comObj) –compares invoking object with passed object –Returns true if both are “equal”, false if not void display() –Displays attributes String toString() –Converts all attributes to String and returns String

8 public class MyClass { … private final int STARTID = 1; //the following are one per object private int IDNum = -1; //the following are one per class private static int nextIDNum = STARTID; … public boolean equals(MyClass compare) { if (IDNum == compare.IDNum) return true; else return false; }

9 Project Turn in to TA –.java File for main() –.java File for class –.doc “What I learned” file –.txt Data File Confirm that TA Received Your Program No Late Projects Accepted!

10 Documentation Comments: –Document Approach to Problem Outline Design Above main() and class Briefly Describe Methods –Comment Any Unobvious Code Analysis: –What Did You Learn from the Project? –What Went Wrong? What Went Right? –What Would You Do Differently?

11 Final Exam 2 Hours 200 Points 30% of Grade Must Take to Pass Course

12 Need to Know for Final Everything Through Exam 2 Plus: –Passing Arrays to Methods –Array Initialization –Classes Constructors Accessor Methods Mutator Methods toString() and equals() Methods

13 Final Exam 200 Points Total – 30% of Final Grade 90 points Matching or Short Answer or Multiple Choice (Terminology, Operators, JAVA Basics) 30 Points Program Output 80 Points Programming (Full Programs)

14 Final Exam Study Previous Exams and Quizzes Make Sure to Study Arrays, and Classes Have fun 8) !!

15 What Have You Learned? Logical Thinking, Design, Planning “Real World” Issues (Users, Run-time problems, “off-by-one”, Commenting, etc.) Programming: –Variables –Constants –Selection –Iteration –Files –Methods –Classes

16 Future cs116 Data Structures (lists, stacks) Searching and sorting Classes –Inheritance –Encapsulation –Templates


Download ppt "Announcements Final Exam: TBD. Static Variables and Methods static means “in class” methods and variables static variable: one per class (not one per."

Similar presentations


Ads by Google