Ms Gold's

Computer Science Classes at Marshfield High School

AP Java Programming Assignments for

last updated 3/11/10

Link to Lesson Plans

AP Java 2009-10

Link to Current Work

How to Download GridWorld.

First unzip the GridWorld.zip file it 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.

Resources

Java 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

 

  • Unit 1 - Introduction to Java and Object Oriented Programming
    • For the first half of the school year the class will be divided into groups based on each student's level of comfort with java. The group you are assigned to is fluid, and is based on both the students and my opinion.
    • Introduction to class
  • Objective - is to introduce the tools that we will be using in the class
  • Lesson 2
    • Read Chapter 1
    • eIMACs - Introduction ->Welcome
      • Everyone
        • Tools - (Eclipse - Java sdk 5)
          • set up Eclipse and compile and run "Hello World"
          • find the College Board Site and get to know it
          • find the javaBat link and do a quick exercise
          • go through all links on Web site. - READ THEM
    • Assessment - Graded as a Lab Assignment
  • Lesson 3 9/8
    • Objective Review Introduction to Java - JVM, Primitives and Casting
    • In Journal
      • Create a pathname for journal H:/APJava/journal/firstInitialLastnameJournal.doc
      • put date and include what you accomplished:
        • Ran a program in Eclipse on the H drive in a directory called H:/APJava/workspace
        • Found the College Board site
        • Found and done one exercise in JavaBat
        • Gone through the links on the Web site.
    • Objective - How the Java Run Time Environment Works and memorize the 8 Java Primitives
    • Lecture
      • 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 amount of correct answers on the test
    • Computer
Lesson 6 - Week of 10/22
Lesson 6 Week of 11/9
Continue to finish Chapter 3, 4 and 8 problems. This includes reading the Chapters at home
Read Chapter 1 and 2 in Be Prepared for the AP Computer Science Exam in Java and do the exercises
If any of you finish before I come back continue with Emac 6 through 11 (give recursion a try!)
Know Table 1 Primitive Type Chapter 4
Horstmann, Java Book, Chapter 2 Number Types
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 floatingpoint 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 Overflows

A 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-727379968

The 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.99999999999994

This 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; // OK

But the opposite assignment is an error: You cannot assign a floating-point expression to an integer variable.

double balance = 13.75;
int dollars = balance; //Error

To 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.

11/22 Add Scanner Class to 4.11 or 8.3 Horstmann Java Book, 4.7

After Vacation - Stop What you are Doing and Start

2 weeks - 1/5 - 1/18

  • At home - Read Chapter 5 (Conditionals) and Chapter 6 (Iterations) - Horstmann
  • Up front in class do - Exercises R5.9, R5.10 and R5.14
  • Programming Exercises P5.2
  • Emac - Labs and Tests 6 (Program Control), 7 (While Loops), and 8 (For Loops)
  • Exercises P6.3, P6.4 and P6.5
  • Array Lists For Vacation

    Review 2/22
     

    Sorting and Searching

    3/4 - 3/19 (Searching and Sorting, Comparable Interface, and Generics)

    **Code for Selection, Bubble, and Insertion **

    Homework Assignments due 3/16 -

    Test 3/18 on code for Select, Bubble, Insertion, and Merge Sort - In addition will be asked Big-Oh questions.

    Completion of your homework is part of your grade, and will be considered a lab assignment. Lab assignments are worth %15 of your grade

     

    3/22 First half of AP Test

    3/24 - 4/16 GridWorld

    4/16 GridWorld Test

    4/27 Second Half of AP Test

    4/29 - 5/7 Testing, Testing and Testing

    *******************************************************************************************************************************

    Important Links

    The Google Highly Open Participation Contest / Open Source Projects new link

    GridWorld Quick Reference new link

    The unofficial AP Java Schedule new link

    Quick Link to DeMorgans

    Bank Account Example and Bank Account Tester

    AP Java Subset for A

    AP Java Subset for AB

    OO Vocabulary List

    JavaBat- Java Practice Problems

    AP Java online Course eimacs.com

    Sun Java API's 1.5.0

    Java cscie160 -For Distributed Programming

    College Board Information

    Sun the Really Big Index

    Sun OO Tutorials

    Sun Java Package Tutorial

    How to Write Doc Comments for the Javadoc Tool

    Java Language Coding Guidelines

    Lessons

    Tutorials

    Object Oriented Vocabulary List

    Important Links

    3D Mandelbrot (fractal) images

    Marble Madness - Understanding Binary Math

    How to make a Marble Machine

    GridWorld Class Overvie Picture

    Coding Style

    OO Vocabulary List

    AP Java online Course eimacs.com

    JavaBat- Java Practice Problems

    Quick Link to DeMorgans

    Open Source Projects

    GridWorld Quick Reference

    ***Sorting Code - Side by Side - Selection - Bubble - Insertion *

    Bank Account Example and Bank Account Tester

    AP Java Subset for A

    Sun Java API's 5 (the test is still using version 5 of the api)

    Java cscie160 -For Distributed Programming

    College Board Information

    Sun the Really Big Index

    Sun OO Tutorials

    Sun Java Package Tutorial

    Link to Horstmann Chapter 1 power point

    How to Write Doc Comments for the Javadoc Tool

    Java Language Coding Guidelines

    Computer Employment Figures