Back public class HelloWorld { public static void main ( String arg[] ) { Front Basic Setup. Java Quick Sheet. ~ 35 Flashcards. 1 AP CS - Rodriguez

Similar documents
CS1083 Week 2: Arrays, ArrayList

CS111: PROGRAMMING LANGUAGE II

AP CS Unit 7: Interfaces. Programs

Programming Assignment Unit 7

Chapter 4: Control structures. Repetition

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Chapter 4: Control structures

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

CSE 142 SPRING 2008 FINAL EXAM

Table of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited

boolean, char, class, const, double, else, final, float, for, if, import, int, long, new, public, return, static, throws, void, while

Object-Oriented Programming

1) Consider the following code segment, applied to list, an ArrayList of Integer values.

Warm up question. 2)Which of the following operators are defined on a half integer? Which of the following would it be useful to write as behaviors?

AP Computer Science Homework Set 1 Fundamentals

c) And last but not least, there are javadoc comments. See Weiss.

AP Computer Science A

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Simple Java Reference

CS111: PROGRAMMING LANGUAGE II

CS 106 Introduction to Computer Science I

AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s).

Program Fundamentals

Week 6: Review. Java is Case Sensitive

CSCI 161 Introduction to Computer Science

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

AP Computer Science Unit 1. Programs

AP COMPUTER SCIENCE A DIAGNOSTIC EXAM. Multiple Choice Section Time - 1 hour and 15 minutes Number of questions - 40 Percent of total grade - 50

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Final Exam. COMP Summer I June 26, points

Inheritance (Part 2) Notes Chapter 6

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

APCS Semester #1 Final Exam Practice Problems

AP CS Unit 3: Control Structures Notes

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Practice Midterm 1. Problem Points Score TOTAL 50

Introduction to the Java Basics: Control Flow Statements

Visit us at

Condi(onals and Loops

Variables and data types

AP Computer Science Homework Set 2 Class Design

Constructor. Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

Introduction to Programming Using Java (98-388)

The Java language has a wide variety of modifiers, including the following:

AP Computer Science Homework Set 1 Fundamentals

CS 307 Midterm 1[corrected] Spring 2008

Lecture 5: Methods CS2301

APCS Assessment Sheet Consider the following program segment int count = 1;

Homework Set 1- Fundamentals

Anatomy of a Class Encapsulation Anatomy of a Method

Index COPYRIGHTED MATERIAL

CompuScholar, Inc. 9th - 12th grades

Practice Midterm 1 Answer Key

CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2009

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Chapter 1 Introduction to java

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

More on variables and methods

AP CS Unit 6: Inheritance Notes

public static boolean isoutside(int min, int max, int value)

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

TeenCoder : Java Programming (ISBN )

Quarter 1 Practice Exam

Array Basics: Outline

University Interscholastic League. Computer Science Competition

CS302: Self Check Quiz 2

Introduction to Programming Written Examination

Lab Activity Plan. John Dalbey CPE /30/2013

Inheritance. Inheritance allows the following two changes in derived class: 1. add new members; 2. override existing (in base class) methods.

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

AP CS Unit 7: Arrays Exercises

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

1.1 Your First Program

Object Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes

RECURSION. Prof. Chris Jermaine

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Computer Science II (20073) Week 1: Review and Inheritance

CS 307 Midterm 1 Fall 2007

Lecture 14. 'for' loops and Arrays

COE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015

CS 112 Programming 2. Lecture 06. Inheritance & Polymorphism (1) Chapter 11 Inheritance and Polymorphism

AP COMPUTER SCIENCE A

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

CT 229 Java Syntax Continued

Recitation #2 Abstract Data Types, Collection Classes, and Linked List

CS 307 Midterm 2 Spring 2008

CS 302: Introduction to Programming in Java. Lecture 11 Yinggang Huang. CS302 Summer 2012

AP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested.

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

SPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each

Course Outline. Introduction to java

This exam is open book. Each question is worth 3 points.

Elementary Programming

Programming overview

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Lecture Set 4: More About Methods and More About Operators

COP 3330: Object Oriented Programming FALL 2017 STUDY UNION REVIEW CREDIT TO DR. GLINOS AND PROFESSOR WHITING FOR COURSE CONTENT

Transcription:

1 AP CS - Rodriguez Front Basic Setup Java Quick Sheet ~ 35 Flashcards Back public class HelloWorld public static void main ( String arg[] ) // end method main // end class HelloWorld Print Line System.out.println( "Hello everyone out there! "); System.out.print( Hello ); Concatenation System.out.println( "Hello, " + name +! How are you? ); Print Characters Increments/ Decrements Integers \t insert tab \n insert new line \" insert double quote \' insert single quote \\ insert backslash i--; i++; --i; ++i; i+=2; or i = i + 2 i*=3; or i = i * 3 int a = 21; Double Boolean Strings Arrays double b = 2.15 boolean ison = true; String name = new String( "Ms. R" ); String name = ""; int[] ListOfItems = new int[7]; String[] ListOfItems = "zero", "one", "two" boolean[] TFList = true, false, true, true; Array Length MySong[] playlist = new MySong[4]; int listlength = myarray.length; //Number of elements in array Boolean Operators < Less than > Greater than <= Less than or equal to >= Greater than or equal to == Equal to!= Not Equal to Comparison && "and" Both must be true "or" One must me true

If-Else Statement Comparing Strings Searching and Comparing Array of Strings Modulus 2 AP CS - Rodriguez if( a < b ) System.out.println( "a is " + a + " and is less than " + b ); else System.out.println( "a is greater or equal to b ); String name = new String( "Ms. R" ); if( name.equals( "Ms. R" ) ) System.out.println( "Username Correct" ); // end if for( int i =0; i<food.length; i++) if( food[index].equals( "Apple" ) ) System.out.println( "We found an apple!" ); // end if % Remainder Ex. 15 % 2 = 1 Ex. 3 % 10 = 3 Ex. 15 % 5 = 0 Ex. 20 % 3 = 2 Even numbers if( num % 2 = 0 ) Odd numbers if( num % 2!= 0 ) For Loop Initial condition increment/decrement i--, --i for(int i = 0; i < max; i++) <Code/statement> Ex. for(int i = 0; i < array.length; i++) System.out.print( array[i] ); While Loop (Array) int i = 0; while( i < songs.length ) System.out.print( songs[index] ); index++; //end while If Else if( counter%2 == 0 ) // System.out.println( counter + " is an even number" ); // end if else System.out.println( counter + " is an odd number" ); // end else

3 AP CS - Rodriguez Math Random //Math.random() returns a number from 0 to.999999 // Random number between two values (Min and Max) 1-10 int min = 1; int max = 11; //add one more to the max int randomnum = min + (int) ( Math.random() *( max - min ) ); Casting double num = 2.7; int newnum = (int) num; // this would make newnum 2 //it does NOT round up, it casts it off Array lengths Calling items in array Compound Assignment operators int index = 0; while( index < songs.length ) System.out.print( songs[index] ); index++; //end while x += 3; same as x = x + 3; x -= 3; same as x = x - 3; x *= y; same as x = x * y; x /= y; same as x = x / y; x %= y; same as x = x % y; x *= y + 1; same as x = x * (y + 1); String String name = new String( Rodriguez ); //index starts at 0 System.out.print( name.length() ) //prints 9 System.out.print( name.substring(3) ) //prints riguez System.out.print( name.substring(3, 6) )//prints rig (do NOT include 6 th index) System.out.print( name.substring( name.length() 1 ) ) // prints z, the last index System.out.print( name.substring(4, 5) )//prints i (do NOT include 5 th index) For each loop for( Type nickname : Array/List) <Code/statement> Ex. for( doubles num : MyFavNums) <Code/statement>

4 AP CS - Rodriguez 2D Array //(2D array with 5 rows and 4 cols) int[][] MyArray = new int[5][4] // The 2D Array is empty //myarray[row][col] //Fill up Array one by one myarray[0][0] = 1; myarray[0][1] = 12; myarray[1][0] = 15; myarray[4][3] = 13; //Access a value in the array System.out.print( myarray[3][4] ); // prints the item in row 3 col 4 int totalrows = myarray.length; // Number of rows int totalcols = myarray[0].length; // Number of columns Filling up a 2D array with Nested for loop Nested Loop (2D Array) Right to left Nested for each loop (2D Arrays) for( int row = 0; row < myarray.length; row++ ) for ( int col = 0; col <myarray[0].length; col++) myarray[row][col] = 2*(row)*(col); //you can put anything here for( int row = 0; row < myarray.length; row++ ) for ( int col = 0; col <myarray[0].length; col++) <Code/statement> System.out.printnl( ); //adds a new line for every row for (int[] row: MyArray) for (int col: row) System.out.print( row[col] );

5 AP CS - Rodriguez ArrayList **import java.util.arraylist; ArrayList<String> nums = new ArrayList<String>(); nums.add( zero ) nums.add( new String( "two" ) ); nums.get(0) //Gets element in index 0) nums.remove(0) //Removes elements at index 0) nums.set(1, one ) //Set index 2 to a new String) nums.size() //Gets size of ArrayList or the number of elements) nums.get(1).length() //Get the length of the item in index 1 one, // the length is 3 //Make an ArrayLust of objects ArrayList<MyDevice> inventory = new ArrayList<MyDevice>(); inventory.add( new MyPhone( 64, Blue ) ); Memory and color ArrayList of Objects Ex. ArrayList<MyDevice> inventory = new ArrayList<>(); inventory.add(new MyPhone( 64, Blue ) ); //Memory and color For loop ArrayList Find min or max in array of integers ArrayList<String> nums = new ArrayList<String>(); for(int i = 0; i < nums.size(); i++) System.out.print( array.get(i) ); //prints element in index i int max = 0; for(int i=0; i < myarray.length; i++) if( i == 0) max = myarray[0]; if( myarray[i] > max) max = myarray[i];

6 AP CS - Rodriguez The Big 3 1. instance variables 2. constructors (zero-arg and multi-arg) 3. tostring() method The Dynamic Duo 4. getter methods 5. setter methods The The Brain (public or private) 6. processor method(s) (algorithmic processing) Instance Variables Constructors Zeroargument Multiargument tostring() Getter Setter Methods are accessed by tostring() or item.getprice() or getprice() (if used within the class) public class Shoes // Instance variables private String brand; private int size; //Constructor (Zero-Argument) public Shoes() brand = new String("none"); size = 5; //Constructor (Multi-Argument) public Shoes( String brand, int size) this.brand = brand; this.size = size; //tostring() public String tostring() String output = new String(); output = "Brand: " + brand + "Size: " + size; return output; //Getter public int getsize() return size; //Getter public String getbrand() return brand; //Setter public void setsize( int size) this.size = size;

7 AP CS - Rodriguez Brain Example Brain Example Signature //Other Methods/ Brains public String wideaval() if(size > 5 && brand.equals("jordans") return "Does not come in wide sizes"; else return "Avaiable in wide"; //Another Brain example public double gettotal(int price) double total=price + (.08) *(price); //taxes if(size > 6) total += 9.99; //for shipping return total; Inheritance extends This extends a class to inherent instance variables but NOT methods Must us super(), super(args), super.tostring(), super.gettotal() to use super s methods Interface Abstract implements abstract This allows for multiple classes to have a similar method, connecttobluetooth() but each class can have a different code to implement it. Abstract Class: This makes a class abstract ( existing in thought or as an idea but not having a physical or concrete existence ). You cannot make an object in the driver of this class

8 AP CS - Rodriguez Unified Modeling Language (UML) Class Diagram