Download presentation
Presentation is loading. Please wait.
1
CS 200 Additional Topics and Review
Jim Williams, PhD
2
Week 14 Final Exam: Conflict Alternatives Emailed
Monday, December 17th, 2:45 – 4:45 pm, Location? BP2 Eliza due Thursday Team Lab: Object-Oriented Space Game TA Evaluation Hours Last Week & CS 300? My office hours change: Wed. 9:00 to 10:30 Lecture: UML, Additional Topics
3
Lots of Jobs if you understand Programming
Software Developer/Programmer/Software Engineer Testing/Quality Assurance Technical Support Technical Writing Business/Systems Analyst Software Architect Product Manager Project Manager Development Manager Technical Sales Marketing
4
Analysis and Design Analysis: Describing the Problem
Design: Describing a Solution
5
UML Diagrams UML (Unified Modeling Language)
Many diagrams with lots of details Goal in CS 200 is to recognize: Use Case Diagram Class Diagram Object Diagram Activity Diagram/Control Flow
6
UML Diagrams: References
Examples of Diagrams: Simple Drawing Tool:
7
Use Case Behavior diagram
How external users (actors) interact with the system.
8
Class Diagram Shows structure of a system with features, constraints and relationships. Independent of time.
9
Object Diagram A snapshot of a system at a point in time.
Instances of classes with specific attribute values.
10
Activity Diagram (Control Flow)
Behavior diagram Shows flow of control emphasizing sequence and conditions
11
What Kind of Diagram is this?
Use Case Diagram Class Diagram Object Diagram Activity Diagram/Control Flow
12
What Kind of Diagram is this?
Use Case Diagram Class Diagram Object Diagram Activity Diagram/Control Flow
13
What Kind of Diagram is this?
Use Case Diagram Class Diagram Object Diagram Activity Diagram/Control Flow
14
What Kind of Diagram is this?
Use Case Diagram Class Diagram Object Diagram Activity Diagram/Control Flow
15
Space Game Apply UML
16
Today Next Week: Review on Tuesday, last lecture
TA Final Exam Course Evaluations: aefis Lecture: Recursion, Survey, Inheritance
17
Recursive Algorithm Repeated applications of an algorithm on smaller versions of the same problem. Eventually reach a base case which is simply solved.
18
Recall Fibonacci Sequence
… First 2: 1, (base case) Following numbers: sum of previous 2 Example: If we want to find the 5th number: 5th = 4th + 3rd (recursive step)
19
Recursive Solution Base case: Can be simply solved Recursive step:
Break into smaller problems static int fib(int num) { if ( num <= 1) return 1; //base case else return fib( num -1) + fib( num -2); } public static void main(String[] args) { System.out.println("fibonacci 4: " + fib(4));
20
Iterative solution public static void main(String[] args) {
int n = 10; int [] fib = new int[n]; fib[0] = 1; fib[1] = 1; for (int i = 2; i < n; i++) { fib[i] = fib[i-1] + fib[i-2]; } System.out.println("fib "+n+"= " + fib[n-1]);
21
Iteration vs Recursion
Each may be better (simpler, clearer, more efficient) for a problem. Some problems, such as navigating trees, recursion is frequently a helpful and elegant solution.
22
Application: What does this do?
public class Show { public static void show(File file, String depth) { System.out.printf("%s%s\n", depth, file.getName()); if ( file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { show(files[i], depth + " "); } public static void main(String[] args) { File file = new File("."); show(file, " "); import java.io.File; public class Show { public static void show(File file, String depth) { System.out.printf("%s%s\n", depth, file.getName()); if ( file.isDirectory()) { File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { show(files[i], depth + " "); } public static void main(String[] args) { File file = new File("."); show(file, " ");
23
How does recursion end? try it.
24
Recent Course Improvements
Redesign of Intro Course (CS302 -> CS200) Study Cycle Problem Solving Tips Team Labs as study groups emphasize reading Java, unexpected behavior Projects emphasize incremental development & testing Increased assistants and office hours
25
Recent Results Solid preparation for CS300 (our top goal)
25% decrease in DFDrop rate from 4+ years ago Fall 2017 No DF Drop bias for gender, 1st gen No grade bias based on experience
26
Changes Possible Computer Science is influencing every field, including education. This potential seems exciting but not clear if what ways education will be positively influenced.
27
Course Survey What would you expect in order to rate course in the top rating (7) of each category? Lecture, Homework, Projects, Materials, Feedback Instructor: Overall, Responsiveness, Environment Recommend Course Please! describe in the open ended notes.
28
Course Evaluations
29
Inheritance & Polymorphism
Animal Demo
30
is-a vs has-a Relationships
is-a: inheritance class Dog extends Animal { } has-a: composition class Car { Engine engine; Wheel [] wheels; }
31
The 2nd toString method is ________
Overriding Overloading public class Cup { private String owner; public String toString() { return this.owner; } public String toString(String type) { return type; try it.
32
Course Review Key Principles, Tools, Diagrams, Data Types, Operators, Keywords, Control Flow, Programming Paradigms, Debugging Techniques, File Input/Output, Commenting & Style, Unit Testing, Memory, Best Practices, Learning Programming
33
Tools zyBooks, JavaVisualizer, DiffChecker, Command Prompt, notepad, javac, java, Eclipse IDE (editor, compiler, vm, debugger)
34
Diagrams truth tables, memory model diagrams, control flow charts (activity diagrams), class diagrams, object diagrams, and use-case diagrams.
35
Data Types Primitive & Reference Primitive: 8
Reference: existing, classes you write.
36
Operators
37
Evaluating Java Expressions
Precedence Associativity Sub-expressions left-to-right
38
Key Principles Algorithms Abstraction
39
Control Flow Sequence Methods Conditionals Loops
40
Data Structures Arrays: single and multi-dimensional ArrayLists
ArrayLists of Arrays
41
Development Process Edit-Compile-Run cycle
Analysis - understand the problem Design - pseudocode
42
Best Practices Incremental, systematic, frequent deliverables Test frequently Test bench with testing methods
43
Debugging Techniques Stepping through in Java Visualizer
print statements to verify and narrow down problem print statements with DEBUG flag Eclipse debugger
44
Programming Paradigms
Structured Programming Object-Oriented Programming (brief)
45
Program Commenting & Style
46
Learning to Program Read and Write code
Lots of interrelated concepts that build on each other. High level educational skills on Bloom's taxonomy
47
Applied Study Cycle frequent, varied interactions with material
48
zyBooks Participation Activities
Assigned readings with small activities due before lecture
49
Lecture - Activities Definitions & Explanations Drawing Diagrams
Demonstration Stories Retrieval Practice Questions, including TopHat
50
zyBooks Challenge Activities
Application of previous week's material to small programs.
51
Team Lab Weekly paired and small group study with mentor nearby.
Required interaction with mentor on key topics. Variety of activities to learn Terms, Read, Write, Test & Debug code.
52
Weekly Programs Application of programming concepts to design algorithms and write code to solve problems. Small programs early, large programs with milestones later. Incrementally developing skills on larger and more complex programs.
53
Exams Assess careful reading and tracing skills.
54
Brainstorm on Improving Course
55
Notes Final Exam: Monday, December 17th, 2:45 – 4:45 pm Course Survey
Today: Review
56
Study Tips Labs are essentially weekly Study Guides
Trace and Explain are intended to teach specific concepts and challenging aspects. Preparing to teach is a very effective way to learn. Imagine you are preparing yourself to teach this material to others this summer or soon. Go through the labs, explaining to someone (maybe imaginary) what each trace and explain segment is doing.
57
Exam Tips Come early, many to scan in.
Assume there is a bug in each code segment You have to be able to determine what it is and explain exactly how it currently works in order to fix it.
58
Memory areas static: holds static variables when class is loaded into memory. heap: where instances/objects are allocated stack: where local variables and parameters are allocated each time a method is called.
59
Memory public class M { int varName = 1; static int cVar = 2;
public M(int varName ) { this.varName = varName; } public static void main(String []args) { M[] varName = new M[3]; varName[0] = new M(3); varName[1] = new M(4);
60
How many Bug instances in list?
2 2 copies of reference to 1 bug none, error, no list 3 ArrayList<Bug> list; list = new ArrayList<Bug>(); list.add( new Bug()); Bug aBug = new Bug(); list.add( aBug); list.add( 0, aBug); import java.util.ArrayList; class Bug { private static int count = 0; private final int id; Bug() { id = ++count; } public String toString() { return "Bug:" + id; public class ClassNameHere { public static void main(String[] args) { ArrayList<Bug> list = new ArrayList<>(); list.add( new Bug()); Bug aBug = new Bug(); list.add( aBug); list.add( 0, aBug); System.out.println( list);
61
Exceptions new Exception() //records the stack trace
throw //starts live exception handling throws //method may throw an exception try-catch //stops live exception handling finally //code to always execute
62
Exception Handling 3 Categories Error - internal system errors
Unchecked Exceptions RuntimeException Checked Exceptions Exception
63
Programming Process & Errors
Naming/Saving Syntax/Compile time Runtime & Logic Users Editor (Virtual) Machine Compiler Hello.java Hello.class Computer Files Programmer
64
Classes Class vs Instance Members (from docs) Creating your own
65
CS 300 Suggestion Setup your own weekly study group reviewing & discussing previous weeks material.
66
Good Luck on Exam! Have a Great Summer!
67
Which is false? every instance will have the exact same toppings
toppings is a class variable can be accessed by any method cannot be changed class Pizza { static String toppings; } A, B & C are true D is false since toppings would have to be 'final' to not be changed.
68
toppings is a(n) instance (non-static) variable class Pizza {
private String toppings; public String getToppings() { if ( toppings == null) toppings = "no toppings"; return toppings; } instance (non-static) variable class (static) variable parameter local variable A is true, B, C and D are false
69
getToppings() is a(n) method getter class Pizza {
private String toppings; public String getToppings() { if ( toppings == null) toppings = "no toppings"; return toppings; } method getter accessor provides read-only access to toppings field All of the above All are true.
70
The visibility modifier private is
appropriate should be public doesn't allow a user of this class to change the field (attribute) directly allows only methods within this class to change the field. class Pizza { private String toppings; public String getToppings() { if ( toppings == null) toppings = "no toppings"; return toppings; } A, C & D are true B is false
71
Which is false? is a class method class Pizza {
can change toppings (write access) is a setter is a mutator class Pizza { private String toppings; public void setToppings( String tops) { if ( tops != null && tops.length() > 0) toppings = tops; } B, C and D are all true. A is false as setToppings does not have the 'static' keyword in the header before void.
72
Does this print true or false?
class Person { private boolean something = false; boolean getThing(boolean something) { return this.something; } public static void main(String []args) { Person p = new Person(); System.out.println( p.getThing( true)); true false error/other try it and see.
73
Which is true? class Light { } // in some method
error - no constructor Object classes' toString() will be called an instance of Light has nothing in it error class Light { } // in some method Light aLight = new Light(); System.out.println( aLight); A: false, since there is no constructor the default, no-arg constructor is provided by the compiler best answer: B: Object classes' toString() will be called C: false, since Light implicitly extends from Object and therefore when instantiated has all the instance fields of class Object within it. D: no error noted, although code isn't complete as shown, but with reasonable assumptions should run.
74
What will print out? 1 can't access a private field outside the class
1 can't access a private field outside the class error class Employee { private static int employeeCount = 0; private final int id; Employee() { this.id = ++employeeCount; } public static void main(String []args) { Employee anEmployee = new Employee(); System.out.println( anEmployee.id); try it and see
75
Does this print 0, 1, other or error?
public class Person { static int count = 0; private int id; Person() { this.id = ++count; } public static void main(String []args) { System.out.println( Person.count); 1 other error try it and see
76
What will print out? 1 can't access a private field outside the class
1 can't access a private field outside the class error class Employee { private static int employeeCount = 0; private final int id; Employee() { this.id = employeeCount++; } public static void main(String []args) { Employee anEmployee = new Employee(); System.out.println( anEmployee.id); try it and see
77
Bike Design a bike class. Instance Fields: numWheels, Color, unique id
Class Field: numBikesCreated, used to assign unique id’s to each bike. Constructor: numWheels and Color, automatically sets the unique identifier. Instance Methods: Number of Wheels and id can be accessed but not changed. Color can be changed. Add a toString() method to return all instance field values in String form. Class Method: returns the number of bikes created. Draw the UML diagram and then write the code. Create a BikeShop class that creates 10 bikes and stores in an array. Print out each bike’s number of wheels, color and id using the toString method. Can you write the code and draw the diagram?
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.