Presentation is loading. Please wait.

Presentation is loading. Please wait.

AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100.

Similar presentations


Presentation on theme: "AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100."— Presentation transcript:

1

2 AP Computer Science edition Review 1

3 ArrayListsWhile loopsString MethodsMethodsErrors 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500

4 ArrayLists - 100 Refer to an element in an array list.

5 ArrayLists - 200 Add an element to the beginning of an array list

6 ArrayLists - 300 Remove the last element in an array list

7 ArrayLists - 400 Sum up all elements in an array list using an enhanced for loop

8 ArrayLists - 500 Using a for loop, print out all the elements in reverse order

9 While loops - 100 What is the first step in creating a while loop?

10 While loops - 200 When should you use a while loop instead of a for loop?

11 While loops - 300 How many times would you loop here? int x = 10; while (true) { if ( x > 15) break; else x -= 1; }

12 While loops - 400 What would I code in the following loop header to break out if the score was not between 0 and 100? while ( _____________ ) { ……. }

13 While loops - 500 Using a while loop, continue printing out the elements in an integer array until the integer is greater than 10 and its an even number.

14 Strings - 100 Returns how many characters are in the string

15 Strings - 200 Returns true or false depending if the Strings contain the same word

16 Strings - 300 Allows the programmer to take pieces of strings and save them into new strings

17 Strings - 400 This method uses lexicographical analysis

18 Strings - 500 Allows the programmer to combine strings to form a single new string.

19 Methods - 100 A specialized method that constructs new objects

20 Methods - 200 A method that returns a value to the caller

21 Methods - 300 The information that is passed to the method

22 Methods - 400 What are the variables called that track key information about an object?

23 Methods - 500 A method in a class that is not used for an individual object

24 Errors -100 These extremely common errors will prevent the program from compiling

25 Errors - 200 These can cause the program to crash while running

26 Errors - 300 This occurs when the programmer misunderstands the program

27 Errors – 400 This occurs when a call to an array or a String has exceeded its length

28 Errors – 500 This occurs when an object name has been declared, but not initialized

29 Thanks

30 ArrayLists – 100 (solution) Refer to an element in an array list. ArrayList aList; aList = new ArrayList (); aList.get(0) refers to first element aList.get(i) refers to the i th element

31 ArrayLists – 200 (solution) Create an element at the beginning of an array list ArrayList aList; aList = new ArrayList (); aList.add(0, 25); //creates an element with value 25 and shifts all other elements up

32 ArrayLists – 300 (solution) Remove the last element in an array list If (aList.size() > 0) aList.remove(aList.size() – 1);

33 ArrayLists – 400 (solution) Sum up all elements in an array list using an enhanced for loop int sum = 0; for ( int e : aList ) { sum += e; }

34 ArrayLists – 500 (solution) Using a for loop, print out all the elements in reverse order for(int i = aList.size()-1; i >= 0; i--) { System.out.println(aList.get(i)); }

35 While loops – 100 (solution) What is the first step in creating a while loop? Determine what is true when the loop ends. This is usually easier than determine what needs to be true to keep looping.

36 While loops – 200 (solution) When should you use a while loop instead of a for loop? Use a while loop instead of a for loop when you don’t know how many times you need to loop (indefinite loop).

37 While loops – 300 (solution) How many times would you loop here? int x = 10; while (true) { if ( x > 15) break; else x -= 1; } Infinitely or until the computer ran out of memory.

38 While loops – 400 (solution) What would I code in the following loop header to break out if the score was not between 0 and 100? while ( score >= 0 && score <= 100 ) { ……. }

39 While loops – 500 (solution) Using a while loop, continue printing out the elements in an integer array until the integer is greater than 10 and its an even number. int i = 0; while ( a[i] <= 10 || a[i]%2 == 1 ) { System.out.println( a[i] ); i++; }

40 Strings – 100 (solution) Returns how many characters are in the string s.length();

41 Strings – 200 (solution) Returns true or false depending if the Strings contain the same word s.equals(word) if (s.equals(“cat”) { …… }

42 Strings – 300 (solution) Allows the programmer to take pieces of strings and save them into new strings String part = s.substring(2,5); Remember that subtracting 5-2 = 3 tells you that the substring is 3 characters.

43 Strings – 400 (solution) This method uses lexicographical analysis s.compareTo(“cat”); if it returns -1 then s < “cat” If it returns 0 then s = “cat” If it returns 1 then s > “cat”

44 Strings – 500 (solution) Allows the programmer to combine strings to form a single new string. Concatenation: String fullName = firstName + “ “ + lastName;

45 Methods – 100 (solution) A specialized method that constructs new objects The Constructor method has the same name as the class and is used to construct the object. One of its main functions is to initialize the instance variables.

46 Methods – 200 (solution) A method that returns a value to the caller A Return method returns a value to the calling class. The return statement is used to return the value and its data type must match that specified in the method’s signature line.

47 Methods – 300 (solution) The information that is passed to the method Parameters are passed to the method. There can be multiple parameters separated by commas.

48 Methods – 400 (solution) What are the variables called that track key information about an object? Instance variables store the important information about an object. They are normally private variables and are declared outside of your methods at the top of the class.

49 Methods – 500 (solution) A method in a class that is not used for an individual object Static methods are methods that don’t operate against individual objects. In fact, you don’t have to instantiate the object in order to use them.

50 Errors – 100 (solution) These extremely common errors will prevent the program from compiling Syntax errors

51 Errors – 200 (solution) These can cause the program to crash while running Runtime errors

52 Errors – 300 (solution) This occurs when the programmer misunderstands the program Logic errors

53 Errors – 400 (solution) This occurs when a call to an array or a String has exceeded its length Index out of bounds errors

54 Errors – 500 (solution) This occurs when an object name has been declared, but not initialized Null pointer exception


Download ppt "AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors 100 200 300 400 500 100 200 300 400 500 100 200 300 400 500 100."

Similar presentations


Ads by Google