Presentation is loading. Please wait.

Presentation is loading. Please wait.

HFJ CHAPTER 5 REVIEW Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is the purpose of.

Similar presentations


Presentation on theme: "HFJ CHAPTER 5 REVIEW Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is the purpose of."— Presentation transcript:

1

2 HFJ CHAPTER 5 REVIEW

3 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is the purpose of writing prepcode?

4 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is test code?

5 Prepcode and Testcode Prep code – a form of pseudocode, to help you focus on the logic without stressing about syntax Prepcode describes what to do, not how to do it Use prepcode to help design the test code Test code – a class or methods that will test the real code and validate that it’s doing the right thing Write test code before you implement the methods

6

7 Developing a Class Figure out what the class is supposed to do List the instance variables and methods (class diagram) Prep code Test code Implement the class/ write real code Test using the test code Debug and reimplement as needed (Test with real users)

8 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: int numRooms = Integer.parseInt(input);...

9 Converting a String to an int Parse - Analyze (a sentence) into its component parts and describe their syntactic roles. In this case we analyze a String and convert into an int if the String is an integer number. After it is converted, we store it as an int.

10 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: int numRooms = Integer.parseInt(input);...

11 Preconditions Important  Seen on the AP CS exam to reduce complexity of writing methods Preconditions are conditions that must be met in order for the code to work. Usually specify the type of inputs so that we don’t have to deal with invalid inputs

12 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: int randomNum = (int)(Math.random() * 5)...

13 Type casting Forces the expression after the type cast to become the type specified int randomNum = (int)(Math.random() * 5); (Math.random() * 5) generates a random double between 0 and 5 The (int) type cast cuts off the decimal part of the number Left with 0, 1, 2, 3, or 4

14 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: Which of these is not a loop?

15 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: Which of these is not a part of a for lo...

16 For loops While loops int i = 0; while (i < 100) { //repeated code i++; } For loops for(int i = 0; i<100; i++) { //repeated code }

17 Hw Q7 int[] someNums = new int[6]; //someNums is filled with random ints for(int i = 0; i

18 Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: Which of these is not part of a for-each...

19 For-each loops While loop int[] locationCells = new int[100]; int i = 0; while (i < 100) { System.out.println (locationCells[i]); i++; } For-each loop for(int cell : locationCells) { System.out.println(cell); }

20 For-each loops For loop for(int i = 0; i<100; i++) { System.out.println (locationCells[i]); } For-each loop for(int cell : locationCells) { System.out.println(cell); }

21 Hw Q8 For loop for(int i = 0; i

22 Hw Q9 For loop for(int index = 0; index < dailyTemps.length; index++) { System.out.println (dailyTemps[index]); } For-each loop for(int temp : dailyTemps) { System.out.println (temp); }

23 Hw Q10 – for loop While loop int index = 0; while(index

24 Hw Q10 – for-each loop For loop for(int index = 0; index < cities.length; index++) { System.out.println (cities[index]); } For-each loop for(int city : cities) { System.out.println(city); }

25 For loop vs. for-each loop For loop Has an index  useful for setting data that depends on the index Initialization, boolean test, and iteration expression are all in one line For-each loop Easier to write when simply accessing data from an array Not much better than a while loop if not accessing array data

26 For loop vs. for-each loop For loop for(int i = 0; i<100; i++) { locationCells[i] = i; } For-each loop int i = 0; for(int cell : locationCells) { cell = i; i++; }

27 While loop vs. for-each loop While loop int i = 0; while(i < locationCells.length) { locationCells[i] = i; i++; } For-each loop int i = 0; for(int cell : locationCells) { cell = i; i++; }

28 Game Lab Q2 public void printLocations() { if (locationCells == null) { System.out.println(“Please set my locations”); } else { for(int loc : locationCells) { System.out.println(loc); } } }


Download ppt "HFJ CHAPTER 5 REVIEW Don’t forget: You can copy- paste this slide into other presentations, and move or resize the poll. Poll: What is the purpose of."

Similar presentations


Ads by Google