Top Banner
Final Review
44

Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

Dec 18, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

Final Review

Page 2: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

2

Final Details

Monday, December 11th

7:00pm – 10:00pm HCC 1325

Page 3: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

3

Sections Covered - Detailed View 1.1-1.2, 1.4-1.6 2.1-2.6 3.1-3.3, 3.6-3.8 [covered 3.4, 3.5 in class] 4.1-4.4 [covered 4.5 in class] 5.1-5.5, 5.7-5.8 [(basically) covered 5.6 in class] 6.1-6.5, 6.7, 6.8 [covered 6.9 in class] 7.1-7.2, 7.6-7.7 [covered 7.4 in class] 8.1-8.5 9.1-9.5 10.1-10.6 11.1-11.3 some parts of 12 covered in class notes

Page 4: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

4

Sections Covered - Broadly

Chapters 1-11 (except for Graphics track) … with minor exceptions…

Page 5: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

5

Other Topics (from before midterm) Running time / Big O notation Working with references handout

including null/this Merge sort Command line arguments printf

Page 6: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

6

Other Topics (after midterm)

More detailed treatment of some topics polymorphism (e.g. covered Collections) file output (e.g. covered buffers and generic

Writers) File input

Call Stack Scanning tokens Regular Expressions

Page 7: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

7

Chapter 1

Computer processing The Java Programming Language Program Development Object-Oriented Programming

(very basic)

Page 8: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

8

Chapter 2

Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs

Page 9: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

9

Chapter 3

Creating Objects The String Class Packages Formatting Output

(plus more detailed coverage of printf) Enumerated Types Wrapper Classes

Page 10: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

10

Chapter 4

Anatomy of a Class Encapsulation Anatomy of a Method

Page 11: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

11

Chapter 5

The if Statement and Conditions Other Conditional Statements Comparing Data The while Statement Other Repetition Statements

Page 12: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

12

Chapter 6

Software Development Activities Identifying Classes and Objects Static Variables and Methods Class Relationships Interfaces Method Design Testing

(covered the same material in class)

Page 13: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

13

Chapter 7

Declaring and Using Arrays Two-Dimensional Arrays The ArrayList Class

Page 14: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

14

Chapter 8

Creating subclasses Overriding methods Class hierarchies Inheritance and visibility Designing for inheritance

Page 15: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

15

Chapter 9

Polymorphism polymorphic references through inheritance through interfaces

Searching linear search binary search

Sorting insertion sort selection sort merge sort

Page 16: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

16

Chapter 10

Exception Handling The try-catch Statement Exception Classes I/O Exceptions

Page 17: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

17

Chapter 11

Recursive Thinking Recursive Programming Using Recursion

Page 18: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

18

Running Time – Big-O

For a parameter n… e.g. the length of a string or size of an array

… count the number of steps performed… loop through n elements = n steps loop inside a loop = n2 steps

Ignore constants… coefficients… 3n + 2 steps = O(n) n2 /2 steps = O(n2) “cutting problem in half at each step” = O(log n)

Page 19: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

19

Working with References

null reference Object variable not assigned anything When does this cause an exception?

this reference When does this simplify code?

Page 20: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

20

File I/O

Where do the exceptions happen? How do we handle them?

Why do we want to buffer? How do we buffer? Using Scanner

with default tokens with defined tokens

Page 21: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

21

Regular Expressions

Given regular expression yes/no matching questions give informal description

Given informal description write regular expression pass appropriately to Scanner

Page 22: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

22

What Kind of Questions?

Look at the exercises in the text finding errors in code finding differences in code explaining/defining concepts predicting output of code writing methods or classes specifying/justifying design from requirements

Page 23: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

23

What Kind of Questions?

Similar format for lecture material e.g. specify running time e.g. find null reference problem

Using regular expressions Predicting tokens parsed Describe call stack

including exceptions explain stack trace

Page 24: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

24

It May Be on the Test if…

It is in the text It is in the lecture notes It is something I said in class or wrote on the

blackboard It was part of a lab/assignment

Page 25: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

25

What Code Do You Need to Know? Officially: everything as per previous slide Unofficially:

I try to only assume you know “important” methods and classes

… but I decide what is “important” in general… little used methods that occur rarely

in the notes will be given implicitly but you should know enough code to solve

problems without help/look-up

Page 26: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

26

Examples

There will be definitions (again) abstract class checked exception final method overridden method

Page 27: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

27

Examples

There may be explanations required… Explain why a static method cannot refer to an

instance variable. Give two differences between an abstract class

and an interface.

Page 28: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

28

Examples

Draw a UML diagram for a single class hierarchy representing these animals, with abstract classes grouping animal types parrot gorilla horse bat penguin

Add an interface for flyers

Page 29: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

29

Examples

Correct the problemsFlyer polly = new Parrot();

Animal koko = new Gorilla();

Gorilla junior = koko.makeOffspring();

polly.layEgg();

Page 30: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

30

Examples

Define appropriate classes and public methods for the given requirements. Every salesperson will be assigned a unique ID

number, and a numbered office with a phone. Salespeople will sell vacuum cleaners at a fixed price. When inventory runs out, the top salesperson will be designated employee of the month.

Page 31: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

31

Examples

Find the exception in this code, and handle it.public static void main(String[] args)

{

FileWriter fileout = new FileWriter(“names.txt”);

if(fileout!=null)

fileout.write(“John Smith”);

else

System.out.println(“No name written to file”);

}

Page 32: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

32

Examples

Find the exception in this code, and handle it.public static void main(String[] args)

{

Student s = new Student(4533453,”tsmith”);

String fname = s.getFirstName();

System.out.println(fname);

}

Page 33: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

33

Examples

Given this information in file.txt:

7 | 5 | 5p ,| 4 Write the code that will print these tokens to

the screen using a Scanner/delimiter: “7 | 5 | 5” and “ , | 4” “7 | “ and “ | “ and “p ,| 4”

Page 34: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

34

Solution

Scanner filein = new Scanner(

new File(“file.txt”)

).useDelimiter(“p”);

while(filein.hasNext())

{

System.out.println(filein.next());

}

“5”

Page 35: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

35

Examples

Yes or no expression matching [1-7]*a? 43 (17)+(17a)? 17a [abc][def](di)? bed [123]+(45)?a* 12312345aaaa [ab][bc][cde]* abcde [A-C]DEF? ABCDE [truck].[stop]+ trstopstop

yes

yes

yes

no

no

yes

no

Page 36: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

36

Examples

Describe the strings matching the expressions (cat)+ [cat][cat] cat? [ca]?t* (c?a+)t? [c-t]a?[c-t]*

Page 37: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

37

Examples

What is the value in variable temp after:int temp = 30;String stemp = temp + “12”;temp = temp + Integer.parseInt(stemp);

Again:Collection<Integer> l = new

ArrayList<Integer>; int temp = 40;l.add(40);temp = l.size();

Page 38: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

38

Examples

Write a method that picks a random character in the string “string”.

Page 39: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

39

Examples

What is wrong with this? How can it be corrected?

int count=1,max=0;

while(count=max)

{

System.out.println(count);

count-=2;

}

Page 40: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

40

Examples

A LinkedList implements Collection Write a method that adds every word in the

sentence “This is a sentence” to a LinkedList, then prints the size.

Page 41: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

41

Examples

Given double[] input, write a method that returns the highest value

Page 42: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

42

Examples

Write a class NamedArrayList that extends ArrayList by adding a name for the array list in the first position.

Page 43: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

43

Examples

What is wrong with these declarations:

char[] chars = {“d”, “a”, “b”}; String[] = new String[5]; Scanner[] sc = new Scanner(5);

Page 44: Final Review. 2 Final Details Monday, December 11 th 7:00pm – 10:00pm HCC 1325.

44

Examples

Write a recursive function that returns true if the input is a power of 3.

Write a recursive function that returns true if a string contains only the letter ‘s’.