9
1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

Embed Size (px)

Citation preview

Page 1: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

1

Building Java ProgramsChapters 1-5

Lecture 13: Midterm Review

Page 2: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

2

Page 3: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

3

Midterm TipsBring Husky Card, know your section and TAOpen book

No notes, calculators, phones, digital textbooks (Kindle, etc)10 point penalty for violating this rule

When instructor calls time, close your test10 point penalty for violating this ruleSeriously…nothing you write in a few seconds is worth 10

pointsYou must turn in a test to leave the room

Page 4: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

4

Midterm TipsThe only acceptable abbreviations

S.o.p (System.out.print)S.o.pln (System.out.println)S.o.pf (System.out.printf)A (ALWAYS)N (NEVER)S (SOMETIMES)

If you write A, N, or S and we can’t tell what it is, it is wrong

Page 5: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

5

Midterm TipsTest format

5 mechanical questions (60 points total) Expressions Parameter Mystery If/Else Mystery While Mystery Assertions

2 programming questions (15 points each)1 programming question (10 points)1 extra credit question (1 point)

Page 6: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

6

Midterm TipsNot covered:

Graphics, DrawingPanel, Color, RandomExpressions (question 1) resulting in boolean valuesNo writing methods that return boolean values

Programming QuestionsNot graded on style unless specifically mentioned in problem

If it works, full creditMethod header is worth 1 or 2 pointsLook for words that suggest different concepts

Repetition loops Conditions if/else

If we tell you not to do something in your solution…don’t do it

Page 7: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

7

isPowerOfTwoWrite a static method isPowerOfTwo that takes an

integer n as an argument, and that returns true if n is a power of two, and otherwise false. If n is zero or negative, return false. Note that isPowerOfTwo(1) should return true, since 20=1.

Practice-It

Page 8: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

8

speedingTicket Write a method speedingTicket that decides whether a given driver should be given a

speeding ticket from a police officer. The method accepts three parameters: the driver's car speed in miles per hour, as an integer; the current speed limit, as an integer; and whether or not the police officer has eaten a donut today, as a true/false value. (A police officer that has eaten a donut is happy, so he/she is less likely to give the driver a ticket.) Your method should return true if the driver should receive a speeding ticket, and false if not. A driver should be given a speeding ticket if any of the following conditions are met:

The officer has eaten a donut (true) and the driver's speed is at least 10 mph over the speeding limit.

The officer has not eaten a donut (false) and the driver's speed is at least 5 mph over or under the limit.

The driver is going 100 mph or faster, regardless of the speed limit or donut status. You may assume that the integers passed as parameters will be non-negative. Practice-It

Page 9: 1 Building Java Programs Chapters 1-5 Lecture 13: Midterm Review

9

firstNotIncludedWrite a method called firstNotIncluded that accepts two Strings as parameters. It should return the index of the first character in the second String that is not found in the first String. It should return -1 if all of the characters in the second String are found in the first String. Your method should ignore case.

For example, the call firstNotIncluded("aNt", "tan") should return -1 because all of the letters in "tan" can be found in "aNt" if we ignore case. The call firstNotIncluded("section", "tonsils") should return 5 because 'l' is the first character in "tonsils" that cannot be found in "section" and 'l' is at index 5 in "tonsils".