Wednesday, September 03, 2008

ICA-CP: 9/3/08 - Parrot Program

Good morning!

This morning, we are learning something new about Java. We will learn how to use Java libraries. First of all, we have this term, code reuseability. Code reusuabilty means we do not have to invent everything we want to do in Java ourselves. If we can find something already written that does what we want, we borrow and modify it. CASE is an example of code reuseability. In our HellowWorld program, we used already written Java code, and just changed it to meet our needs.

In our Parrot program, we said our algorithm is:
1) Open and run the Java program.
2) The user types something at the keyboard which our Java program captures and saves.
3) The keystrokes which the user typed and which our Java program saved are then printed lt on the screen.
4) Steps two and three just capture and print once. We would like our program to allow a user to type and print multiple times. So, we want to repeat steps two and three until the user types the word, "Done."


So, we will start with modifying our HelloWorld program to perform steps one, two, and three. To do that, we need to learn some new Java concepts:
import
string
new
print

How to declare a variable: datatype variable name
How to identify the location of a library in BlueJ

These are the new lines of code we will use:

import TerminalIO.KeyboardReader --> a package and class
KeyboardReader getTyping = new KeyboardReader();
String userInput;
usesrInput = getTyping.readLine;

0 Comments:

Post a Comment

<< Home