Presentation is loading. Please wait.

Presentation is loading. Please wait.

Building Java Programs

Similar presentations


Presentation on theme: "Building Java Programs"— Presentation transcript:

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

2

3 Midterm Tips Bring Husky Card, know your section and TA Open book
No notes, calculators, phones, digital textbooks (Kindle, etc) 10 point penalty for violating this rule When instructor calls time, close your test Seriously…nothing you write in a few seconds is worth 10 points You must turn in a test to leave the room

4 Midterm Tips The 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

5 Midterm Tips Test 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)

6 Midterm Tips Not covered: Programming Questions
Graphics, DrawingPanel, Color, Random Expressions (question 1) resulting in boolean values No writing methods that return boolean values Programming Questions Not graded on style unless specifically mentioned in problem If it works, full credit Method header is worth 1 or 2 points Look 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

7 isPowerOfTwo Write 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

8 speedingTicket Practice-It
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

9 firstNotIncluded Write 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".


Download ppt "Building Java Programs"

Similar presentations


Ads by Google