cse 115 / 503 introduction to computer science i · lab 12 is due on friday at 8:00 pm for...

23
‘- 1 Dr. Carl Alphonce Dr. Jesse Hartloff CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I

Upload: others

Post on 07-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

1

Dr. Carl AlphonceDr. Jesse Hartloff

CSE 115 / 503INTRODUCTION TO COMPUTER SCIENCE I

Page 2: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

2

Announcements

Lab 12 is due on Friday at 8:00 PM for everyone.

Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat these times as additional office hours.

LAST: Review/Extra Help session – 7:00 PM to 9:00 PM: Monday 12/11 in Davis 113A

Page 3: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

3

End-of-semester plan

12/06 Exam Review, part 2 (Q&A)

12/08 Activity to replace lowest lab score.

Page 4: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

4

Today

HW3 hints

Lab 12 hints

General exam Q&A

Page 5: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

5

HW3 hints

getTile

setCity

tiles

moving the map

zooming the map

Page 6: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

6

getTile

Maps from a City (with latitude and longitude) and a zoom level to a Tile in the grid for that zoom level.

getTileCity

ZoomTile

Page 7: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

7

setCity

Sets the _primaryTile for the visualization. The _primaryTile is the one in the center of the 3x3 grid of 9 tiles.

Page 8: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

8

tiles

Generates the 9 tiles to be display. Must NOT change the _primaryTile.

(x-1,y-1) (x,y-1) (x+1,y-1)

(x-1,y) (x,y) (x+1,y)

(x-1,y+1) (x,y+1) (x+1,y+1)

Page 9: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

9

Moving the map

Given a _primaryTile,if we move North…

(x-1,y-2) (x,y-2) (x+1,y-2)

(x-1,y-1) (x,y-1) (x+1,y-1)

(x-1,y) (x,y) (x+1,y)

(x-1,y+1) (x,y+1) (x+1,y+1)

Page 10: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

10

Moving the map

…we set a new value for _primaryTileand recompute the 3x3 grid about thatnew center tile.

Re-setting the _primaryTile in tiles(), e.g. by calling setCity(…), re-centers the map on (x,y) rather than (x,y-1).

This is the cause of many “off by one” errors in the ArrayList returned by tiles().

(x-1,y-2) (x,y-2) (x+1,y-2)

(x-1,y-1) (x,y-1) (x+1,y-1)

(x-1,y) (x,y) (x+1,y)

(x-1,y+1) (x,y+1) (x+1,y+1)

Page 11: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

11

Zooming in

Given a _primaryTile, at zoom level Nif we zoom in…

(x,y)

Page 12: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

12

Zooming in

…at zoom level N+1 that one tile is represented by four:

Page 13: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

13

Zooming in

A new _primaryTile must be chosen, but which of the four should it be?The one that contains the city. Use setCity(…) to determine which Tile at the current zoom level contains the city.

Page 14: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

14

Zooming in

For example, if the city was located here on the original tile:

Page 15: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

15

Zooming in

Then the new _primaryTile will be the one in the lower right corner:

Page 16: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

16

Lab 12 hints

Common problem

Use an appropriate data structure

Avoid recomputation

Page 17: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

17

Common problemAn error occurred while parsing the autoresult returned by the Autograder.

Error message: 795: unexpected token at ''

Autograder [Wed Dec 6 10:41:44 2017]: Received job [email protected]:806Autograder [Wed Dec 6 10:44:57 2017]: Success: Autodriver returned normallyAutograder [Wed Dec 6 10:44:57 2017]: Here is the output from the autograder:---Autodriver: Job timed out after 180 seconds

Page 18: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

18

Common problemAn error occurred while parsing the autoresult returned by the Autograder.

Error message: 795: unexpected token at ''

Autograder [Wed Dec 6 10:41:44 2017]: Received job [email protected]:806Autograder [Wed Dec 6 10:44:57 2017]: Success: Autodriver returned normallyAutograder [Wed Dec 6 10:44:57 2017]: Here is the output from the autograder:---Autodriver: Job timed out after 180 seconds

Page 19: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

19

Use an appropriate data structure

We’ve discussed many data structures during the semester. One in particular is appropriate for storing pairs of values (e.g. word-count pairings or character-count pairings).

Any ideas?

Page 20: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

20

Use an appropriate data structure

We’ve discussed many data structures during the semester. One in particular is appropriate for storing pairs of values (e.g. word-count pairings or character-count pairings).

Any ideas?

How about:

HashMap<String,Integer>

HashMap<Character,Integer>

Page 21: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

21

Avoid recomputation

Many submissions do all the counting of words (or characters) in the wordCount (or charCount) methods.

However, there is no need to re-compute the counts each time one of these methods is called.

What else could you do?

Page 22: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

22

Avoid recomputation

Many submissions do all the counting of words (or characters) in the wordCount (or charCount) methods.

However, there is no need to re-compute the counts each time one of these methods is called.

What else could you do?

You could count the words and characters as you read data from the file, and store those counts in your chosen data structures.

Page 23: CSE 115 / 503 INTRODUCTION TO COMPUTER SCIENCE I · Lab 12 is due on Friday at 8:00 PM for everyone. Baldy 21 is staffed as usual M-F this week, but there is no instruction. Treat

‘-

23

Avoid recomputation

For example, my wordCount method just looks up the correct value in the map:

@Override public int wordCount(String w) {if (_wordCounts.containsKey(w)) {

return _wordCounts.get(w);}else {

return -1;}

}