Sunday, November 25, 2012

I Will be Out on Monday

Due to a death in my family, I will be out on Monday but will return to school first thing on Tuesday morning. All your assignments that were previously due Monday (the 5 free-response questions and all the ArrayList problems on practice-it) are now due on Tuesday instead of Monday.

Mr. Sarkar

Tuesday, November 20, 2012

ArrayList Problems Now Due after Thanksgiving

Most of you are struggling with the ArrayList problems so I have moved the due date to after Thanksgiving break. Remember that in addition to these problems you also need to do three FRQ problems from the 2009 exam (this is the Juno assignment 99.23) and any two other FRQ's from previous exams. These are due after the break as well.

Sunday, November 18, 2012

Initialization of an ArrayList

When we declare and define a traditional array like this:

int [] x = new int [5];

The compiler creates an array of 5 integers and initializes them all to zero (which is the default initialization for integers).

But when we declare and define an ArrayList like this:

ArrayList<Integer> y = new ArrayList<Integer>(5);

Although the compiler sets aside the memory to hold 5 Integers, no actual Integers are created. Furthermore, not even pointers for these Integers are created (not even null pointers). Thus, if we try to print one of the elements, such as the first element in this ArrayList:

System.out.println(y.get(0));

The code will compile but a run time error of "ArrayIndexOutOfBounds" will be produced. That is because the ArrayList currently has a size of 0 (not 5) because no elements have been yet loaded into it.

Hopefully, this is clear.

Mr. Sarkar

Thursday, November 15, 2012

Using For-Each Loops with Strings

Someone in class today asked if it was possible to use for-each loops in java with Strings. The answer is "yes," and "no." You can use the for-each loop to parse an array of Strings but you cannot use it to parse as single String. Here is an example of a legal use of a for-each loop for a String array:

String array[] = {"Hi", "There", "My", "Son"};
for(String x : array)
     System.out.print(x);


The above example will print:

HiThereMySon

Mr. Sarkar

Wednesday, November 14, 2012

Where the for-each is appropriate


Although the enhanced for loop can make code much clearer, it can't be used in some common situations.

  • Only access. Elements can not be assigned to, eg, not to increment each element in a collection.
  • Only single structure. It's not possible to traverse two structures at once, eg, to compare two arrays.
  • Only single element. Use only for single element access, eg, not to compare successive elements.
  • Only forward. It's possible to iterate only forward by single steps.
  • At least Java 5. Don't use it if you need compatibility with versions before Java 5.

Monday, October 8, 2012

Hints on Array Problems

Many of you are struggling on the array problems. In this post, I have provided some hints on some of the solutions. In some cases, I provide you with an algorithm to help you find a solution. For some others, I give you pieces of code.

 First, here is how you parse an array of unknown length. Lets say you have an array called a. Here is a loop that prints every element, one per line:

          for (int i=0; i < a.length; ++i)
         { 
               System.out.println(a[i]);
         }


Notice we use the length attribute of array a to figure out how many times we need to run through the loop. That means this loop will work for any length array.

Ok, now for some help on individual problems:

7.4: create an integer called previousValue and set it initially to be equal to the first element of the array. Then set up a loop to parse the array from the second element to the last element. If the current element being checked is smaller than the previousValue immediately return false. Otherwise, update previousValue to the current element and go to the next element in the loop. If you make it through the entire loop without getting to the return false statement, just return true.

7.11: Its important to understand that the printBackwards() method does not return a value. It justs prints some stuff. The trick here is to parse the array from the largest index to the smallest. So use a loop like this:

          for (int i=a.length-1; i >=0; --i)    // i is the index of the next element from biggest to zero
         { 
               // add print statements here
         }

7.1:  Create an integer called returnValue and set it equal to -1. Parse the array from start to finish. If the target is located, update the returnValue to the current index. If the target is in the array multiple times, the returnValue will simply get updated multiple times. After parsing the entire array, just return returnValue;

7.2:  Parse the array and locate the largest element. Parse the array and locate the smallest element. subtract the two answers and add one. Return that as the final answer.

7.3: Create an integer called returnValue and initialize it to zero. Parse the array. For each element, check to see if it is greater than equal to the minimum value AND less than or equal to the max value. If so, increment the returnValue. After parsing the entire array, return the returnValue.

Array Deadlines Extended Again

The deadlines for the practice-it array problems have been extended (again) to 10/10 (the day of our test). They will be due on midnight that day. My suggestion is to submit on the practice-it site whatever you have at that time (even if it doesn't work) because I will not be extending the deadline for the class any further. Some have asked for after-school help on Tuesday - you are welcome to come to 429 - but I have to give preference to the Algebra kids who show up on that day. On Sunday (yesterday) around midnight, I logged into practice-it to see how far along the class was on these problems and was disappointed to see so many of you had barely started. Mr. Sarkar

Wednesday, October 3, 2012

Array Homework Deadlines

I've pushed out the deadlines for the array homework given how much Practice-It has been down. The new deadlines are listed right next to the titles on Juno for each assignment. Also, I've eliminated Problem Set D and replaced it with a group of problems on Coding Bat. The Coding Bat problems (which we started in class today) are due midnight on Friday. All the other array homework is due Tuesday, when you get back from the three-day weekend. Mr. Sarkar

Tuesday, October 2, 2012

Practice It is Down Again

The Practice-It site is down again. So I have extended the deadlines for all the array problems. The new deadlines are listed in the names of the corresponding Juno assignments. You are still strongly encouraged to check back frequently to see when the site comes back up and try to get ahead of the deadlines. Sorry for this inconvenience. Mr. Sarkar

Monday, October 1, 2012

instanceof Operator

Some of you were absent or need a refresher on the instanceof operator in Java. Unlike most other java topics, instanceof did not have any good videos on youtube. So I have made the following tutorial to help you:

Mr. Sarkar


Friday, September 28, 2012

How to Create a Simple Yes/No Dialog with a User

One of the students today in class asked me if there was some easy way to limit the choice of responses from the user when starting the Last-Coin Game. Here is a short program which demonstrates how the built-in dialog features of java can be used.

You are welcome to use this feature in your program for the Last-Coin Game (or you can come up with your own).


import javax.swing.JOptionPane;


public class YesNoDemo {

public static void main(String[] args) {


int response = JOptionPane.showConfirmDialog(null, "Click Yes or No",
                                       "Do you want to go first?", JOptionPane.YES_NO_OPTION);

if (response == JOptionPane.YES_OPTION)
System.out.println("User wants to go first");
else
System.out.println("User wants computer to go first");

}

}

Tuesday, September 25, 2012

How to Create an Unbounded Grid in GridWorld

You may find it convenient to change over from a simlple (bounded) grid to an unbounded grid to help you test your SpiralBug, etc. The way to do this is to add this 2nd line of code to the tester class right after you create the world:

ActorWorld world = new ActorWorld(); // this is the line of code you already have in your tester class
world.setGrid(new UnboundedGrid());  // this is the line of code you need to add

It will then be easier to see the spiraling patterns.

You will also need to add these import statements to the top of your code:


import info.gridworld.grid.*;
import info.gridworld.world.*;

Mr. Sarkar

Saturday, September 22, 2012

New Deadline for Latest Homework Assignment

The deadline for the Bug Variations (both the ones I assigned - RetroBug, RectangleBug, and MonotoneBug) and the Juno Assignment: GridWorld Part 2: Bug Variations is being extended.

The deadline which was previously this Monday is now being extended to Friday (9/28).

Mr. Sarkar

Monday, September 17, 2012

New Policy for Submitting Computer Projects

The emailing of screen shots is not working out well for grading your projects. 

In the future, when submitting projects, please follow these protocols:

For Coding Bat and Practice It Projects/Assignments


Enable teacher sharing and do nothing else. Do not email projects or submit paper. I will go on Coding Bat and Practice It and look at your work.

For All Other Computer Projects


You have three choices for submission:

  1. You can submit the project on paper. Please include a copy of the output attached to your documented code.
  2. You can email me your project (and the output) in a Microsoft Word document.
  3. You can email me your project(and the output) in a PDF file.
Mr. Sarkar


Thursday, September 6, 2012

Computer Art for the Lab

If some of you could print a full color copy of your "House With Sunrise," I will pin them up in the lab to shock and awe the other other classes that use the lab.

Extra credit for this? No. But you will have my thanks.

Mr. Sarkar

Friday, August 31, 2012

Emailing Programs Instead of Paper Submission

Looks like all the tree huggers in the class would rather submit their screen shots by email than paper copies. That is ok with me. Some of the ones I have received, however, are illegible. Please try to increase the font size on your screen before taking the picture if possible.

Mr. Sarkar

Incorrent Answer to Juno Problem

One of the problems in tonight's juno assignment had the wrong answer. The question was, "Which detects syntax errors." The right answer is the compiler, not the operating system. This has been fixed.

Mr. Sarkar

Thursday, August 30, 2012

Video Describing How to Build "Hello World" Program


This video which is on youtube is well suited to help you get started with your hello world program if you need extra help.

Mr. Sarkar

How to Build and Run "Hello, world" Program

There was not much time at the end of class so I rushed through the process of how to write your first program. I'm adding some additional  instructions here. But you are encouraged to go on youtube and find some videos to help you as well.


  1. double click on the BlueJ icon to launch BlueJ
  2. click on Project and open a new project
  3. enter a file name for your project (maybe call it "Project 1")
  4. BlueJ window should now be open
  5. click on New Class to create a new class
  6. enter "Hello"
  7. double click on the Hello box in BlueJ 
  8. you should now see the code for Hello
  9. replace all the code in this window with what i showed in class.
  10. hit the compile button
  11. return to the main BlueJ window, right mouse click on the Hello box and select main()
  12. when it asks for args, just hit OK
  13. you should see Hello World printed on the console window
I promise to go over this in class step by step tomorrow as well.

Mr. Sarkar

Tuesday, August 28, 2012

First Day of Class

Hopefully, all of you enjoyed the first day of Computer class as much as I did.

Your first real JUNO homework assignment is ready. You should see it as soon as you log into junoed.com.

If you have any problems, do not hesitate to email me.

Mr. Sarkar

Thursday, August 9, 2012

If your name is not on this list, you need to set up Juno

The following students have established Juno accounts:

Liam Alcin has successfully signed up for Juno
Karl Jiang has sucessfully signed up for Juno
Christopher Kober has successfully signed up for Juno
Luis Kumanduri has successfully signed up for Juno
Michelle Chen has successfully signed up for Juno
Silvana Lopez has successfully signed up for Juno
Stephanie Ego has successfully signed up for Juno
Krzysztof Mazur has successfully signed up for Juno
Aleksandra Pasciak has successfully signed up for Juno
Charles Gorski has successfully signed up for Juno
Jesus Pulido has successfully signed up for Juno
Alex Huntoon has successfully signed up for Juno
Fabio Jaime has successfully signed up for Juno
Caitlin Smith has successfully signed up for Juno
Jonathan Xu has successfully signed up for Juno
Michelle Yang has successfully signed up for Juno

Summer is Almost Over. YIKES!

Just a gentle reminder that summer is almost over. So if you have been procrastinating on your summer packet for AP Computer Science, now would be a good time to get going. Looking forward to seeing all of you in three weeks!

Thursday, June 21, 2012

Temporary Login Codes for JunoED.com

We will be using a website called JunoED.com for most of our homework assignments. Please find your name on this list and write down your temporary login code. You will need it the first time you log into Juno. If you do not see your name on this list, send an email to csarkar@ci.stamford.ct.us and I will create an account on Juno for you.

Diya Banerjee
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-54-3759

Ricardo Bannon
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-55-2465

John Luders
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-65-9685

Jon Frascatore
Your username is 1093321.
If you don't see your classes, Logout, click
"Sign Up", and enter temp code 2625-22-4572

Arnoldo Gonzales
Your username is Arnaldo.
If you don't see your classes, Logout, click
"Sign Up", and enter temp code 2625-43-2707

Jonathan Gonzales
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-57-0756

Jordan Pielert
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-67-1860

Estephany Ramos
Your username is Steph123.
If you don't see your classes, Logout, click
"Sign Up", and enter temp code 2625-78-8284

Krzysztof Witek
1. Go to JunoEd.com
2. Click "Sign Up"
3. Your temp code is 5823-69-9283

Tuesday, June 19, 2012

Summer Assignments for AP Computer Science Ready to Go Now!

Please note that the on-line Juno Summer assignments for Westhill's AP Computer Science Class for the fall of 2012 are now available. You should see five summer assignments when you log into JunoED.com.

Monday, June 18, 2012

Summer 2012 Assignment for Fall 2012 Class

Here is  a list of four tasks you have to do over this summer to get ready for our AP Computer Science class in the fall:
  1. Register for this blog. Look for instructions to the right of this page.
  2. Post a comment on this blog introducing yourself, letting your peers know you have successfully registered.
  3.   We will use Juno for most of our on-line homework assignments throughout the year. Log into your already-created JunoED.com account using the temporary login code found on the June 21st, post titled "Temporary Log In Codes for JunoED.com," on this blog. Update your login and password as required the first time you log into JunoED.com. Then do all the summer assignments listed on Juno.  Hint: Although Juno works with Internet Explorer, it works much better with Chrome, Firefox or Safari. I strongly suggest you use one of these browsers.
  4. You must also download and install Java and BlueJ (both free) on your home computer or laptop. Java is the programming language we will be using in the course. BlueJ is a set of development tools we will use to help you learn Java. Both pieces of software work on both Windows and Apple machines. Instructions for downloading the software may be found on the following YouTube videos.
The first two videos, below, demonstrate how to download Java and BlueJ, respectively, on Windows machines. The third video teaches you how to download BlueJ on a Mac (Java already comes preinstalled on Macs).

            This first video will show you how to download Java on to your Windows PC or laptop:



            
             Also follow these instructions to download BlueJ if you own a Windows PC or laptop:





            Follow the following instructions for downloading BlueJ if you own an Apple PC or laptop:




All of the above need to be done before the first day of class or you will already be behind. Feel free to email me at csarkar@ci.stamford.ct.us if you have any questions. (Do not use the yahoo email listed on the top of this blog).

I am excited about teaching this course starting in the Fall of 2012. Looking forward to meeting all of you.

Mr. Sarkar
csarkar@ci.stamford.ct.us
Westhill High School

Sunday, June 17, 2012

Welcome to AP Computer Science

Welcome to my class. We will use this blog as one of many ways to communicate. Initially, the summer assignment will be posted here. You can always contact me by email at csarkar@ci.stamford.ct.us. (Please do not use the yahoo email address listed on this blog).