AP Computer Science A

Download Report

Transcript AP Computer Science A

Welcome to AP Computer Science A
• We use the Java language, but this class is much more rigorous than
Intro to Java
• More programming, but also more theory
• Difficult material…expect to study/practice at home if you want to
succeed
• AP Exam: May 2016… college credit  save $$ and time, impressive
on application, be more prepared for college
• cbsd.org  teacher websites  Quinn
– Notes, assignments, and test/quiz dates will be posted here. When you miss
class, it is YOUR responsibility to read the notes and complete the assignments.
Do not…
• Copy code/files
• Google how to do something
• Play games / do anything before all
assignments are done
• Ask “did you grade the tests yet?” or any
variation thereof
• Listen to the band Third Eye Blind
Don’t be “that guy”
• Rules for naming a file
– Begin with a capital letter
– No spaces or punctuation
– Cannot begin with a number
– Each new word starts with a capital letter
Basic output
•
•
•
•
•
•
To display text: System.out.println(“ “);
To go to the next line: put \n between the quotes
System.out.print(“ “);  do not go to next line
Java is case-sensitive
Semi-colons after (almost) every line of code
Demo: HelloWorld
Variables
• Variables are memory containers in which info is
stored
• They can hold numbers, letters, words, phrases, etc
• integers are whole numbers (no decimals)
• First, declare the variable – specify the type of info
the variable will hold, and give the variable a name
int x = 0;
• Setting it equal to zero is called initializing the
variable (giving it an initial value)
• Integers are usually initialized to 0, although there
are exceptions to this rule
• Demo
• You give a variable a value by using =, which is
called the assignment operator.
• Important: = does not mean “is equal to!”
• What it really means is “Take what is on the right
side of the equals sign and assign it to what is on
the left side.”
Rules for naming variables
•
•
•
•
•
•
Use meaningful names
Cannot start with a number
Numbers and letters only
Start with a lowercase letter
then capitalize the first letter of other words
Examples:
highScore
avgTestScore
Other types of variables
• Double (also known as “floating point number”)
– allows decimals
– much more useful than integers, but takes up more memory
• char
– A single character
– You must put the character in single quotes, if you are giving a
char value in your code
example: char myGrade = ‘ ’;
• String
– Words, phrases, sentences
– Capitalize String
– Use double quotes
example: String firstName= “”;
• Demo
Assignments
• (MyInfo)
–
Declare and initialize variables that will hold…
•
•
•
•
Your age
7 numbers
The average of those 7 numbers
The sum, difference, product, and quotient of the first and last
numbers
• your middle initial
• Your favorite book
– Store data in these variables.
– Then display this information. (Example: “The
average is 3.4.”)