|
Computer Science Classes at Marshfield High School |
ResourcesJava Concepts, Cay Horstmann
Be Prepared for the AP Computer Science Exam in Java, Maria Litvin
AP Java - Maria Litvin
www.eimacs.com
GridWorld - AP Collegeboard
Sign on to Imacs - http://users.eimacs.com/
- username = first initial concantenated with last name (for example alovell) with a password= student - for Derek your user name is devozzella and Dominic is dovozzella.
- change your password to something you will remember
- Continue working on P2.7 - create a method called getRandom where repetitions of numbers of not allowed). Print out the results in main.
- Do Excercises from chapter 2 in your AP/Exercises folder R2.1,R2.2. R2.3, R2.4, R2.9, R2.10 and explain what an accessor and mutator method, 2.12, 2.13
- ****Hand in at the end of the day and EVERY DAY a list of what you have accomplished. These will be checked every class!
Unit 1 -
Introduction to Java and Object Oriented Programming Lesson 1 BasicComputerStructures.htm
Name, web-site, and email address on the board Review last year's Asteroid Game
Brain Storm the class structure of a Asteroid Game Compare the class design to how it would be designed in Game MakerLesson 2
Lecture
Go through Class Power Point Link to Power Point Procedures, Schedules, and Assessments Hand out Books Basic Review of Java Code StructureThe file name must be the same name as the class name. For example, in the following case the class name is Sum10, so the corresponding filename is Sum10.java. All class names by convention begin with a capital letter.
All code in java is put in classes, and for the most part each class is in it's own file./**
* Computes the sum of the first ten positive integers,
* 1 + 2 + ... + 10. (comments)
*/
public class Sum10 // class definition public is it's scope
{public static void main(String[] args)// every java application must have one main method
{
System.out.println(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10);// every java statement ends in with a semi-colon}//brackets are delimiters in Java
} //Note indent is very important for readingSystem.out (Object Name) . println (method name) ("Hello World") (parameters); // break down of the statement to print out Hello World to the console with a newline.How to find your java files
You can find your files in your workspace folder of Eclipse->ProjectName->src (here you will find your *.java files) in the ProjectName->bin (you will find your *.class files) Finish up Asteroid discussion How to set up eclipse -Steps to Running Eclipse and Writing Hello World Load and Run a stripped down Asteroid Game - thanks to Beginning Java Game Programming Second Edition, Jonathan S. Harbour, University of Advancing Technology (Chapter 3)
Open Eclipse and create a project called Asteroids download the following 5 files into your workspace project directory->src
In Eclipse right click to refresh your project From the Run Menu click on Run Configurations then pick the Parameters tab. Set Width = 800 and Height= 600 Now you should be able to run your Asteroids projest as a Java Applet. If not as for your neighbors help or my help. Computer
Your assignment is to make the ship travel continuously around the rectangle. Create two ships that wrap around the canvas using one constructor and one drawShip method. Hint use a parameter. Create two constructors one which creates a ship with a default size, and one constructor where the user can create a ship of any size. Have a ship travel in a circle. This can be in a separate project, or a separate drawShip Method, but the same constructor. Using Sine and Cosine to create interesting looking graphics. You can use the Trig.java program as a beginning. Trig.java and ExplodeOne.java
Angle Sine Cosine 0 0 1 90 1 0 180 0 -1 270 -1 0 360 1 1
- Lesson 3
- Objective Review Introduction to Java - JVM, Primitives and Casting
- Write a weekly Journal at H:/APJava/journal/firstInitialLastnameJournalDate.doc
- Ran a program in Eclipse on the H drive in a directory called H:/APJava/workspace
- Find the College Board site
- Find and do one exercise in JavaBat
- Go through the links on the Web site.
Objective - How the Java Run Time Environment Works and memorize the 8 Java Primitives
Lecture 4
JVM- A program written in Java receives services from the Java Runtime Environment (JRE) software by issuing commands to, and receiving the expected results from, the Java software. By providing these services to the program, the Java software is acting as a "virtual machine", taking the place of the operating system or hardware for which the program would ordinarily be tailored. from the Wikipedia explanation of the Java Virtual Machine - read more of this
8 Primitive data types in java
byte 0 short 0 int 0 long 0L float 0.0f double 0.0d boolean false char '\u000'
- Casting is converting one data type to another. There is two kinds of casting one between primitives numeric types and Objects. Casting between primitives numeric types is used to convert larger values, such as double values, to smaller values such as doubles to integers. For Objects All classes are child classes of java.lang.Object, so you can freely cast any class to Object class, or any class within the same family.
- Link to Chapter One Power Point Slides
- Objective - If you know the java primitive and conversion rules you are guaranteed a certain number of correct answers on the AP test
- On the Computer
- review of Coding Guidelines Java Language Coding Guideline
- eImacs AP Java online Course eimacs.com All exercises and tests through and including Test 2
Make sure all work is in H://AP/workspace - I will be copying your workspace onto my flashdrive to grade you. If your work is not in the correct space you will receive a zero for the assignment.
Lesson 5
- Assignment 2- Chapter 2
Types of Variables in Java - link to java.sun.com tutorials - Make sure you know the difference betweenn these types of variablesInstance Variables (Non-Static Fields)
Class Variables (Static Fields) Local Variables Parameters
A type's fields, methods, and nested types are collectively called its members. Chapter 2 Using Objects - READ CHAPTER 2 - READ IT, KNOW IT!
Complete ALL Chapter 2 Review Questions Programming Exercise P2.10 in Chapter 2 of Big Java.
- Chapter 3 Implementing Classes - READ CHAPTER 3 - READ IT, KNOW IT
- Link to Review of Chapter 3 - Implementing Classes
- Chapter 3 - All Review Questons Big Java
- Chapter 3 - All Programming Exercises Big Java
- Take Test 1 and Test 2 on eimacs ( IMAC Tests Count)
- Review Java number conversion rules
Week Starting Mid October
- How to Specify a Public Interface
Java has separate types for integers and floating-point numbers . Integers are whole numbers; floating-point numbers can have fractional parts. For example, 13 is an integer and 1.3 is a floating-point number.
The double type denotes floating-point numbers that can have fractional parts.The name “floating-point” describes the representation of the number in the computer as a sequence of the significant digits and an indication of the position of the decimal point. For example, the numbers 13000, 1.3, 0.00013 all have the same decimal digits: 13. When a floating-point number is multiplied or divided by 10, only the position of the decimal point changes; it “floats”. This representation is related to the “scientific” notation 1.3 × 10-4. (Actually, the computer represents numbers in base 2, not base 10, but the principle is the same.)
If you need to process numbers with a fractional part, you should use the type called double, which stands for “double precision floating-point number”. Think of a number in double format as any number that can appear in the display panel of a calculator, such as 1.3 or -0.333333333.
Do not use commas when you write numbers in Java. For example, 13,000 must be written as 13000. To write numbers in exponential notation in Java, use the notation En instead of “×10n”. For example, 1.3 × 10-4 is written as 1.3E-4.
You may wonder why Java has separate integer and floating-point number types. Pocket calculators don't need a separate integer type; they use floating-point numbers for all calculations. However, integers have several advantages over floating point numbers. They take less storage space, are processed faster, and don't cause rounding errors. You will want to use the int type for quantities that can never have fractional parts, such as the length of a string. Use the double type for quantities that can have fractional parts, such as a grade point average.
Horstmann Java Book, Chapter 4 Number Types 4.1(for more information read advanced topic 4.1, 4,2 and Random fact 4.1)Numerical Computational OverflowsA numeric computation overflows if the result falls outside the range for the number type.
Each of the integer types has a different range—Advanced Topic 4.2 explains why the range limits are related to powers of two. Generally, you will use the int type for integer quantities. However, occasionally, calculations involving integers can overflow. This happens if the result of a computation exceeds the range for the number type. For example:
int n = 1000000;
System.out.println(n * n); // Prints-727379968The product n * n is 1012, which is larger than the largest integer (about 2 · 109). The result is truncated to fit into an int, yielding a value that is completely wrong. Unfortunately, there is no warning when an integer overflow occurs.
If you run into this problem, the simplest remedy is to use the long type. Advanced Topic 4.1 shows you how to use the arbitary-precision BigInteger type in the unlikely event that even the long type overflows.
Overflow is not usually a problem for double-precision floating-point numbers. The double type has a range of about ±10308 and about 15 significant digits. However, you want to avoid the float type—it has less than 7 significant digits. (Some programmers use float to save on memory if they need to store a huge set of numbers that do not require much precision.)
Rounding errors occur when an exact conversion between numbers is not possible.Rounding errors are a more serious issue with floating-point values. Rounding errors can occur when you convert between binary and decimal numbers, or between integers and floating-point numbers. When a value cannot be converted exactly, it is rounded to the nearest match. Consider this example:
double f = 4.35;
System.out.println(100 * f); // Prints 434.99999999999994This problem is caused because computers represent numbers in the binary number system. In the binary number system, there is no exact representation of the fraction 1/10, just as there is no exact representation of the fraction 1/3 = 0.33333 in the decimal number system. (See Advanced Topic 4.2 for more information.)
For this reason, the double type is not appropriate for financial calculations. In this book, we will continue to use double values for bank balances and other financial quantities so that we keep our programs as simple as possible. However, professional programs need to use the BigDecimal type for this purpose —see Advanced Topic 4.1.
In Java, it is legal to assign an integer value to a floating-point variable:
int dollars = 100;
double balance = dollars; // OKBut the opposite assignment is an error: You cannot assign a floating-point expression to an integer variable.
double balance = 13.75;
int dollars = balance; //ErrorTo overcome this problem, you can convert the floating-point value to an integer with a cast:
int dollars = (int) balance;
You use a cast (typeName) to convert a value to a different type.The cast (int) converts the floating-point value balance to an integer by discarding the fractional part. For example, if balance is 13.75, then dollars is set to 13.
The cast tells the compiler that you agree to information loss, in this case, to the loss of the fractional part. You can also cast to other types, such as (float) or (byte).
Use the Math.round method to round a floating-point number to the nearest integer.If you want to round a floating-point number to the nearest whole number, use the Math.round method. This method returns a long integer, because large floating-point numbers cannot be stored in an int.
long rounded = Math.round(balance);
If balance is 13.75, then rounded is set to 14.
*****************************************************************************************************************************************************
Beginning November
Chapter 4, 5, 6 and 7 ( up to Arrays)
Read Chapter 4 Link to Chapter 4 Power Point for additional reference Complete exercises (use the Scanner Class for input) 4.1, 4.4, 4.7, 4.11, 4.12, 4.17 emacs
Strings1,2 Concatenation1,2 String Methods1,2,3 Displaying Messages Converting Between Numbers and Strings Lab 3: Strings 1 Quick Reference 3 Test 3 Booleans Relational Operators1,2 Comparing Strings1,2,3 Logical Operators1,2,3,4,5 Lab 4: Booleans Quick Reference 4 Test 4
Chapter 5 (Conditionals) and Chapter 6 (Iterations) - Horstmann
Exercises R5.9, R5.10 and R5.14 Programming Exercises P5.2 Chapter 6 +Emac - Labs and Tests 6 (Program Control), 7 (While Loops), and 8 (For Loops) Exercises P6.3, P6.4 and P6.5Up to Thanksgiving
General link for Downloading Gridworld zip file and link to Student Manual
Instructions for after you have downloaded GridWorld
First unzip the GridWorld.zip file into your Eclipse workspace. Don't make a directory the zip will make it for you. This directory will be called GridWorldCode. In Eclipse create a java project called GridWorldCode. Then run firstProject - BugRunner as a Java Application.
To Do:
Download, Build and run GridWorld
Complete Part One and Two of the Case Study
StringsArray and ArrayListsWhen finished with the Array problems in your book start eimacs on ArrayLists. You can find the ArrayLists in the EIMACS table of contents at Obect Oriented Programming-> Simple Objects-> 1- 11. Complete enough of the eimac problem sets until you are comfortable doing the ArrayList problems in your Horstmann book.
- Review Exercises R7.3, R7.5, R7.8, R7.9, R7.16, R7.17, R7.11, and R7.12. Must be saved in a file in your APJava folder and Programming Exercises TicTacToe, P7.10, P7.11, and P7.12
- in eimacs review Arrays Java Basics->Variables and Expression->Arrays 1 through 8
- eimacs go over ArrayLists in Obect Oriented Programming Simple Objects 1 through 11 ( you don't have much time to go ove.
Start Recursion - Chapter 13 in Horstmann - Eimacs - Recursive Methods 1 though 4, Lab 13 and Test 11. If you want extra credit do 0 Gridworld Board Game - Watch Video for Game of Fifteen
ArrayList methods and Facts
ArrayLists <String> myArrayList = new ArrrayList <String>();
No Primitives
add(E o) - appends to the end of this list add(int index, E element) - inserts the specified element at the specified position in the list clear() - removes all elements from the list contains(object elem) - Returns true if this list contains a specfied element get(int index) - Returns the element at the specified position in the list indexOf(Object elem) - Searches the first occurence of the given argument, testing for equality using the equals method Iterator <E> iterator() - Returns an iterator over the elements in this list in proper sequence. isEmpty() - Tests if this list has no elements public interface ListIterator extends Iterator -An iterator for lists that allows the progrmmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator;s current position in the list. A ListIteratior has not current element; its cursor position alsways lies between the element that would be returned by a call to previous() and that would be returned by a call to next(). In a list of length n, there are n+1 values, from 0 to n, inclusive. remove(int index) - Removes the element at the specified position in this list. remove(Object o) - Removes a single instance of the specified element from the list, if it is present (optional operation) set(index, E element) - Replaces the number of elements in this list size() - Returns the number of elements in the list.
***********************************************************************************************
Examples of wrapper Classes
Integer Double Autoboxing and Auto-Unboxing - automaticall wraps and unwraps primitives. (You don't need to cast ints) Vocabulary to know
- Array
- ArrayIndexOutofBoundsException
- Autoboxing and Auto-unboxing
- Collection
- Dynamic Array
- Element
- Generics
- Index
- Linear search
- Interface List <E> - In Java list is a collection that remembers the order of its elements. (Cay Horstmann- Java for Everyone)
- ListIterator
- TraversiJng
- Type parameter
- Wrapper class
Sorting and Searching
Read and Answer all GridWorld Questions http://www.collegeboard.com/prod_downloads/student/testing/ap/compsci_a/ap07_gridworld_casestudy_3.pdf
Chapter 14
Sorting - P14.2, P14.4, Searching - P14.8 Analyzing the Performance of Sort Algorithms (You are responsible for knowing this emacs on searching and sorting Comparator Interface A Class - 14.13
Grid World Chapter 3 , Question Sets 3 through Set 6. Read AP Scoring InformationWhat AP scores representEach AP Exam score is a weighted combination of the student's score on the multiple-choice section and the free-response section. The final score is reported on a 5-point scale:5 = extremely well qualified to receive college credit and/or placement
4 = well qualified to receive college credit and/or placement
3 = qualified to receive college credit and/or placement
2 = possibly qualified to receive college credit and/or placement
1 = no recommendation for receiving college credit and/or placementPeriodically, the AP Program conducts college comparability studies for each AP subject by administering a portion of the AP Exam to college students enrolled in equivalent courses. The Program then compares the performance of these students on the sample AP Exam with their actual course scores. Results indicate that:* AP Exam scores of 5 are equivalent to grades of A in the corresponding college course.
* AP Exam scores of 4 are equivalent to grades of A-, B+, and B in college.
* AP Exam scores of 3 are equivalent to grades of B-, C+, and C in college.*******************************************************************************************************************************
Vocabulary
Encapsulation Polymorphism API Documentation accessor and mutator class constructor implicit parameter parameter method new object and object reference overloading primitive typeHow to Download GridWorld.
First unzip the GridWorld.zip file into your Eclipse workspace. Don't make a directory the zip will make it for you. This directory will be called GridWorldCode. In Eclipse create a java project called GridWorldCode. Then run firstProject - BugRunner as a Java Application.
Important LinksSun Java API's 1.7.0 updated
3D Mandelbrot (fractal) images
Marble Madness - Understanding Binary Math
Object Oriented Vocabulary List
Encapsulation Polymorphism API Documentation accessor and mutator class constructor implicit parameter parameter method new object object reference overloading primitive typeMathematical Definition of reciprocal is a number that you multiply by so that the result equals 1. The easiest way to find it is to just flip the fraction over.Here's an example: What is the reciprocal of 3?
3 is the same as 3/1, so we flip and the reciprocal is 1/3Reciprocal of 4/5 is 5/4
Change to a fraction --> 5/2, then flip --> 2/5"Transformations are used to convert coordinates in the coordinate system used to describe the world into the coordinate system used by the display screen as seen from the eye point. The world tends to be described in units like feet or millimeters while the screen is measured in pixels." From Doing it Fast - on Game Programming by Bob Pendleton