Thursday, October 22, 2009

ICA-CP: 10/22/09 - Test Re-take and continue with Parrot

Good morning!

Here's the link to our test re-take: http://www.quia.com/quiz/2002389.html

Today is our last class of the quarter. So, I need the Parrot program and Karel assignment #4 completed today. Also, any blogs which you might want to make-up are due by midnight tonight. If you need more time for blogs, you can arrange it with me.

Tuesday, October 20, 2009

ICA-CP: 10/20/2009

Good morning!

Today's agenda is: Q &A for the test, take our test, work on the Parrot Program and Karel assignments #'s 4 & 5. Be sure to work on making up Questions of the Week in your blogs. You have until Thursday at the end of class to make up Questions of the Week.

Our test is here: http://www.quia.com/quiz/1996958.html

Monday, October 19, 2009

ICA-CP: 10/19/2009

Good morning!

This morning, we are reviewing for tomorrow's 75 point test. Be sure to bring you "Parrot program" handout to class. This is a reminder that you can use the Parrot program handout when you take your test tomorrow.

Friday, October 16, 2009

Good morning!

Today, we are reviewing for the test on Tuesday, 10/20/09. The we are going to install the TerminalIO library to make the Parrot program work. Finally, we will work on more of Karel the Robot. There is no Question of the Week due. Instead, there will be a double Question of the Week due a week from Monday, on 10/26/2009. Please check your Powerschool grades. The end of the quarter is next week.

So, here's the to-do list you all have:
1) Print out the source code and display screen for the Parrot program.
2) Do Karel the Robot assignment #4. Turn in a print out of the source code and display screen.
3) Do Karel the Robot assignment #5. Turn in a print out of the source code and display screen.
4) Do the Question of the Week due 10/26/2009.

Thursday, October 08, 2009

Adding the TerminalIO Library to BlueJ

Good morning!

To make your Parrot program compile and run, a library is needed. The library is on the R Drive under my name in the folder, TerminalIO Library. To use the library, please follow these steps:

1) Go to MyComputer and find the folder: C:\BlueJ\lib\userlib. You will be copying a file into this folder.

2) Go to the R Drive and find the folder: R:\Clingingsmith,Debbie\TerminalIO Library There should be a file named TerminalIO.jar in the folder.

3) Copy (do not drag it, but right click and copy!) the file to the C:\BlueJ\lib\userlib folder you found in Step 1.

4) Now, start BlueJ. In BlueJ, you have to add the TerminalIO.jar file to the list of libraries in BlueJ.

5) To add the TerminalIO.jar file to the library list, click Tools --> Preferences. A window should open. Click on the Libraries tab. In the Libraries tab, click the Add button. Another window should open. Go to the C:\BlueJ\lib\userlib folder and click on the TerminalIO.jar file. Then click on all buttons necessary in BlueJ to finish adding the file to the libraries.

6) Now, BlueJ will indicate that you have to exit and restart BlueJ to use the TerminalIO library file. Once you do, your Parrot and Eliza programs should compile.

ICA-CP: Sample TerminalIO program

import TerminalIO.KeyboardReader;
class MyEliza
{ // begin class
public static void main (String[] args)
{ // end class

// declare variables here
KeyboardReader userAnswer = new KeyboardReader();
boolean Done;
final String DoneString = "Done";

while (Done == false)
{ // begin while
System.out.println ("Tell the parrot all!");
userAnser = ReadLine();
if (userAnswer.equals(DoneString))
{ // begin if
Done = true;
} // end if
if (Done == false)
{ // begin if
System.out.println ("You said: " + userAnswer);
} // end if
} // end while
} // end main
} // end class

ICA-CP: SEXI for Java datatypes

Java Datatypes

State:
There are two broad categories of datatypes in Java, primitive data types which are "built-in" and abstract datatypes, like String and KeyboardReader, which require a library to be imported in order to use them. There are seven basic primitive data types. They are bit, nybble, byte, char, boolean, int, and double.

Size matters with primitive datatypes. It matters because hardware memory is reserved for use by a variable when it is declared based on the datatype. The following are the sizes of the primitive datatypes:
1) bit - may be a 1 or a 0 (zero)
2) nybble - 4 bits
3) byte - 8 bits
4) char- 2 bytes or 16 bits; may be character values
5) int - 4 bytes or 32 bits; may be integer values
6) double - twice the size of an int at 8 bytes or 64 bits
7) boolean - 1 which is True or 0 (zero) which is False

Of the other datatypes that we have used, the datatype String is multiple "char" types or multiple characters in size.

The size of a variable's datatype determines what kind of value a variable can represent. A variable of datatype bit can only be a 1 or zero. If I declared this variable:

bit myBit;

I could never assign it the value of 3 or 6 or 999. The largest number that myBit can represent is just one. It is similar for an int declaration of:

int numberOfStarsInTheGalaxy;

Could I represent a googol with numberOfStarsInTheGalaxy? Well . . . since a googol is a 1 followed by 100 zeroes or this number:

10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

and since the largest number an int can represent is 2147483647, I think the answer is a definitely "negatory!" Could a googol fit in a double datatype (hint: a double is 64 bits big)?

Elaborate:
The size of the datatype determines how high one may count or how many characters one may have. For example, since a bit is 1 or zero, the highest one may count is 1. With an int datatype, 1 bit is used for the positive or negative integer sign leaving 31 bits for representing the integer number. If every one of the 31 bits for counting is a one, we would have 31 ones: 1111111111111111111111111111111 (I think that's 31). If we put those 31 ones into a scientific calculator in the binary counting system, then change the counting system in the calculator to decimal, we find that 31 ones in binary equal 2,147,483,647. So, that's the largest positive number we can represent with an int datatype. The largest negative number for an int is -2,147,483,648. For the double datatype, one bit is used for the sign and the remain 63 (out of 64 bits) is used to represent the number value. For the char datatype, the largest amount of data that can be represented is one character. For String, multiple characters may be represented.

Casting is changing the datatype of a variable from a larger datatype to a smaller one. (One cannot cast from a smaller datatype to a larger.) So, if I declare an variable of datatype int, for example:

int myVar = 2147483647

I can cast myVar into a smaller datatype like bit:

(bit) myVar;

Please notice that when casting, I place parentheses around the datatype in the cast statement.

So, myVar which was 31 bits of data as an int becomes one bit of data as a datatype of bit. But, when I do that, the difference in bits is lost or cut off. That is, 30 bits are truncated or cut off. So, after I cast from an int to a bit, the value of myVar (which was 2,147,483,647 when it was datatype int) becomes one since I now only have one bit. To trunctate means to cut off and throw away the rest of the bits that are larger than the new datatype can handle.

Exemplify:
Here's another example of casting. I have this variable declaration:

String myVar = "Hello World";

I cast it into char:

(char) myVar;

Since myVar after it is cast is only one character long, the rest ("ello World!") is truncated or cut off. After I cast myVar down from a String to a char, the value of myVar becomes just the letter, "H".

Why is it that we can cast only from larger to smaller datatypes? Remember that when a variable is declared in Java, memory space in the hardware is set aside for it. For example, if I declare:

int myAge;

the computer sets aside 32 bits in memory for the use of the variable, myAge. I can cast myAge to any datatype smaller than 32 bits because the space is already set aside in the computer. I cannot cast myAge into a datatype larger than 32 bits because there is simply not enough space in the computer's hardware memory set aside for it.

Illustrate:
So, using datatypes in Java and casting is much like buying milk in different sizes of containers. I can have a cup, pint, quart, half-gallon, or gallon container of milk. The milk container size is like the size of the datatype. When I cast from one datatype to another, I could put a cup of milk into a quart sized container. But, I could never fit a gallon of milk into a pint-sized container.

Tuesday, October 06, 2009

Good morning!

Today, we take the next step with our Eliza program. We will review the if and if/else statements, and then learn about Java libraries. We will be using a specific library, TerminalIO.KeyboardReader, so that we can capture the emotion word a user types at the keyboard. We will also work on Karel the Robot assignment #4. Once again, here is the link to the Karel tutorials and Karel worlds: http://lesson.taskstream.com/lessonbuilder/v.asp?LID=pohnhrh2cozef1ck

Also, if you have not turned-in your assignment from last class, printing all 15 or 30 of your Eliza replies on the screen, please do so today. Thank you.

Friday, October 02, 2009

ICA-CP: 10/2/2009

Good morning!

Today, finish your emotive words and replies for your Eliza programs. Then, create a Java program that prints all of your replies on the screen. Turn in your source code and the ourput screen to me today.

Question of the Week #5 - Due 10/12/2009

[Your answer should be at least 250 words in length. It is due by 11:59 PM on Momday, 10/12/2009.]


Background: The San Francisco Chronicle laid off 30 reporters and staffers in May. The Rocky Mountain Newspaper closed its doors on February 27, 2009. More and more newspaper are downsizing and many more are closing. Why? Well, when I asked in class how many read a newspaper, no one raised her hand. Fewer and fewer are reading newspapers. Here are some links for more background info: http://www.examiner.com/x-2913-Boston-Republican-Examiner~y2009m2d27-More-Big-City-newspapers-close-their-doors
and http://www.mediapost.com/publications/?fa=Articles.showArticle&art_aid=114137


Question: Where do you get your news? Where and how do you think you may get your news in the future? Do you think newspapers will survive?