Multiple Choice -answer the easiest question 1st

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Advertisements

Big Ideas behind Inheritance. Can you think of some possible examples of inheritance hierarchies?
Strings Testing for equality with strings.
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Multiple Choice Solutions True/False a c b e d   T F.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
© A+ Computer Science - Inheritance © A+ Computer Science - Lab 20.
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
© A+ Computer Science - Which of the following statements assigns the letter S to the third row and first column of a two-dimensional.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
String Class. Variable Holds a primitive value or a reference to an object. Holds a primitive value or a reference to an object. A reference lets us know.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CSE 1201 Object Oriented Programming ArrayList 1.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
How to do well on the AP CS Free Response Questions
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Magpie Magpie is a lab that focuses on classes, randomness, and Strings. This lab will make sure that you.
Java for Beginners University Greenwich Computing At School DASCO
© A+ Computer Science - Elevens is a lab about classes and Lists. List is a major concept being tested by the Elevens lab. Elevens.
Linear Containers Some containers are called linear because their content (items) are stored in a single row (line). Which of the following are linear?
CMSC 202 ArrayList Aug 9, 2007.
Lecture 23:More on Interfaces
© A+ Computer Science - Magpie Chatbot Lab © A+ Computer Science -
Strings, Characters and Regular Expressions
Programming in Java Text Books :
More on Classes & Arrays
A+ Computer Science AP Review 2018 AP CS A EXAM
Modern Programming Tools And Techniques-I Lecture 11: String Handling
AP Java Unit 3 Strings & Arrays.
Chapter 7: Strings and Characters
Lesson A4 – Object Behavior
Can store many of the same kind of data together
Part a: Fundamentals & Class String
Writing Methods AP Computer Science A.
ArrayLists.
A+ Computer Science INPUT.
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
CMSC 202 ArrayList Aug 9, 2007.
© A+ Computer Science - What is a LOOP? © A+ Computer Science -
Can store many of the same kind of data together
© A+ Computer Science - OOP © A+ Computer Science -
The Matrix A b a d e a a a a a a a A b a d e a a a a a a a
CMSC 202 ArrayList Aug 9, 2007.
Methods Copying Autoboxing
Can store many of the same kind of data together
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
Review: libraries and packages
2009 Test Key.
A+ Computer Science PARAMETERS
A+ Computer Science AP Review 2019 AP CS A EXAM
What is a String? String s = "compsci"; s c o m p s i
Presentation transcript:

© A+ Computer Science - www.apluscompsci.com Multiple Choice -answer the easiest question 1st -cycle through the test more than once -use the test to take the test -save long tracing problems for last -bubble as you go -answer every question -keep track of your time - 90 minutes © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Free Response -Read all 4 questions before writing anything -answer the easiest question 1st -most times question 1 is the easiest -see if part B calls part A and so on -many times part C consists of A and B calls -write something on every question -write legibly / use PENCIL!!!!!!!!!! -keep track of your time © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Free Response -When writing methods -use parameter types and names as provided -do not redefine the parameters listed -do not redefine the methods provided -return from all return methods -return correct data type from return methods © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Free Response -When writing a class or methods for a class -know which methods you have -know which instance variables you have -check for public/private on methods/variables -return from all return methods -return correct data type from return methods © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Free Response -When extending a class -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Free Response -When extending abstract / implementing interface -know which methods the parent contains -have the original class where you can see it -make sure you have super calls -check for public/private on methods/variables -make super calls in sub class methods as needed -implement all abstract methods in sub class © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Make a Class public Triangle(int a, int b, int c) { sideA=a; sideB=b; sideC=c; } Constructors are similar to methods. Constructors set the properties of an object to an initial state. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Make a Class public void setSideA(int a ) { sideA=a; } Modifier methods are methods that change the properties of an object. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Make a Class public int getSideA() { return sideA; } Accessor methods are methods that retrieve or grant access to the properties of an object, but do not make any changes. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Make a Class public class Triangle { private int sideA; private int sideB; private int sideC; Instance variables store the state information for an object. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com String Love String s = "compsci"; 0 1 2 3 4 5 6 s c o m p s i A String is a group of characters. Strings are used to store words, which can consist of letters, numbers, and symbols. A string is a group of characters. The first character in the group is at spot 0. © A+ Computer Science - www.apluscompsci.com

frequently used methods © A+ Computer Science - www.apluscompsci.com String frequently used methods Name Use substring(x,y) returns a section of the string from x to y not including y substring(x) returns a section of the string from x to length-1 length() returns the # of chars charAt(x) returns the char at spot x indexOf(c) returns the loc of char c in the string, searching from spot 0 to spot length-1 lastIndexOf(c) returns the loc of char c in the string, searching from spot length-1 to spot 0 String is an immutable Object. String cannot be changed. All of the String methods are accessor method. All of the String methods are return methods. © A+ Computer Science - www.apluscompsci.com

frequently used methods © A+ Computer Science - www.apluscompsci.com String frequently used methods Name Use equals(s) checks if this string has same chars as s compareTo(s) compares this string and s for >,<, and == trim() removes leading and trailing whitespace replaceAll(x,y) returns a new String with all x changed to y toUpperCase() returns a new String with uppercase chars toLowerCase() returns a new String with lowercase chars The chart above lists some very common and very useful String class methods. equals() and compareTo() are used quite often. trim() and replaceAll() are very useful, but that widely used. toUpperCase() and toLowerCase() can be very useful in certain situations. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com String Love OUTPUT 4 -1 iga tors rule String sent = "alligators rule"; String find = "gato"; System.out.println( sent.indexOf( find ) ); System.out.println( sent.indexOf( "dog" ) ); System.out.println( sent.substring( 3 , 6 ) ); System.out.println( sent.substring( 6 ) ); © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ArrayList A typical ArrayList question involves putting something into an ArrayList and removing something from an ArrayList. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ArrayList Arraylist is a class that houses an array. An ArrayList can store any type. All ArrayLists store the first reference at spot / index position 0. ArrayList can store a reference to any type of Object. ArrayList was built using an array[] of object references. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ArrayList int[] nums = new int[10]; //Java int array 0 1 2 3 4 5 6 7 8 9 nums An array is a group of items all of the same type which are accessed through a single identifier. © A+ Computer Science - www.apluscompsci.com

frequently used methods © A+ Computer Science - www.apluscompsci.com ArrayList frequently used methods Name Use add(item) adds item to the end of the list add(spot,item) adds item at spot – shifts items up-> set(spot,item) put item at spot z[spot]=item get(spot) returns the item at spot return z[spot] size() returns the # of items in the list remove() removes an item from the list clear() removes all items from the list import java.util.ArrayList; © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ArrayList List<String> ray; ray = new ArrayList<String>(); ray.add("hello"); ray.add("whoot"); ray.add("contests"); out.println(ray.get(0).charAt(0)); out.println(ray.get(2).charAt(0)); OUTPUT h c In the example above, ray is an ArrayList that stores String references. Casting would not be required to call non-Object methods on ray. ray.add(0,"hello"); ray.add(1,"chicken"); out.println(ray.get(0).charAt(0)); out.println(ray.get(1).charAt(5)); ray stores String references. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices One question on the A test free response will require you to manipulate a 2-dimensional array or a GridWorld grid. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; 0 1 2 0 1 2 Each spot in an matrix stores the location/address of an array. mat[0] stores the location / address of a one-dimensional array. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; mat[0][1]=2; 0 1 2 2 0 1 2 Which array? Each spot in an matrix stores the location/address of an array. mat[0] stores the location / address of a one-dimensional array. mat[0][1]=2; This line sets mat[0] spot 1 to 2. Which spot? © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices 0 1 2 3 4 0 1 2 3 4 mat[2][2]=7; mat[0][3]=5; mat[4][1]=3 5 7 3 mat[2] stores the location / address of a one-dimensional array. mat[2][2]=7; This line sets mat[2] spot 2 to 7. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices A matrix is an array of arrays. int[][] mat = new int[3][3]; 0 1 2 # of arrays size of each array 0 1 2 © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Matrices int[][] mat = {{5,7},{5,3,4,6},{0,8,9}}; for( int[] row : mat ) { for( int num : row ) System.out.print( num + " "); } System.out.println(); The for each loop works quite well as tool to print a matrix. OUTPUT 5 7 5 3 4 6 0 8 9 © A+ Computer Science - www.apluscompsci.com