Lucky Cat Tutoring Services


CIT111: Lets Add and Subtract
September 17, 2009, 3:17 pm
Filed under: Uncategorized | Tags: , , , ,

With incrementing and decrementing, things can be in many different orders. You can prefix, or postfix and write it in different ways.

Example: “++number” is the same as “number++” or “number +=1”.

What happens with prefixing:
Say you have a number 4 and ++number. When it runs the program it will starting 5, not 4. If you put it after, then it will start with 4. Here’s a small example program.

/**
This program demonstrates the ++ and — operators.
*/

public class IncrementDecrement
{
public static void main(String[] args)
{
int number = 4; // number starts out with 4

// Display the value in number.
System.out.println(“number is ” + number);
System.out.println(“I will increment number.”);

// Increment number.
number++; //number=number + 1; number += 1 Can put ++ or — infront of variable

// Display the value in number again.
System.out.println(“Now, number is ” + number);
System.out.println(“I will decrement number.”);

// Decrement number.
number–; //number=number-1; number -=1

// Display the value in number once more.
System.out.println(“Now, number is ” + number);
}
}

The result of this program shows up as:
number is 4
I will increment number.
Now, number is 5
I will decrement number.
Now, number is 4

Process completed.

If PREfixed, the program spits out
number is 5
I will increment number.
Now, number is 6
I will decrement number.
Now, number is 5

Process completed.

Advertisements


CIT 111: String Classes and Methods
September 1, 2009, 4:41 pm
Filed under: Uncategorized

String classes and Methods
Each string class has methods to manipulate them. Any input from GUI windows come in as a string datatype and must be changed into the correct classes. String classes are constant and their value can’t be changed after they are created.
A string class is a complex data type, sort of like an ‘array’ but it’s more than just that. For example, in strings, the characters are indexed by number. Index = “length -1”
A list of every string method can be found under strings at Java 6 API Docs. This is handy if you don’t know what the method is or just want to know more.



CIT 111: Booleans & Other Primitive Data Types
September 1, 2009, 3:31 pm
Filed under: Uncategorized | Tags: , ,

Booleans: Can hold true or false, can be assigned any way that we want them, as long as the expression evaluates to “true or false”.

Example:

// A program for demonstrating boolean variables

public class TrueFalse
{
public static void main(String[] args)
{
boolean bool;
int a=18, b=12;
bool = true;
System.out.println(bool);
bool = false;
System.out.println(bool);
bool = a > b;
if (bool)
{System.out.println(“‘a’ is larger than ‘b'”);
}
}
}



Should come out to say:

true
false
‘a’ is larger than ‘b’

Process completed.

CHARS: are letter based only; can only hold a single character.

// This program demonstrates the char data type.

public class Letters
{
public static void main(String[] args)
{
char letter;

letter = ‘A’;
System.out.println(letter);
letter = ‘B’;
System.out.println(letter);
}
}

COMMON MISTAKES WITH CHARS:
-Errors occur when more than one character is used. Char can only use ONE.

-Double quotes “” around the single character makes it the wrong data type. Anything with “” is a STRING not a CHAR!! Single quotes must always be used


Chars and Integer relationships:
Letters can be assigned using numeric value for a letter in Java 6.



CIT 111 Java 101 week 2
August 25, 2009, 4:36 pm
Filed under: Class Notes, Java | Tags: , , ,

Time for more notes from D Smith’s CIT 111 class at CCAC.

A quick review:
–Classs can stack
–You can only have 1 main class
–You can have as many “Methods” in your class as you want
–All you need to get a program to run at all is a basic skeleton:

/*This is where comments go
 *
 *
 *
 */
public class nameOfProgram
{
        public static void main(String[] args)
        {

        }
}

 

Lets make a little program to draw a star pattern using last week’s lesson:

public class StarProgram
 { public static void main(String []args)
  {
   System.out.println(”    *    “);
   System.out.println(“*       *”);
   System.out.println(”    *   “);
   System.out.println(”    *    “);
   System.out.println(”   ***   “);
   System.out.println(”  *****  “);
   System.out.println(” ******* “);
   System.out.println(”  *****  “);
   System.out.println(”   ***   “);
   System.out.println(”    *    “);
  }
 } // ends the class and program

This displays a little star pattern like old school “Hi I’m drawing with emoticons” postings from the dark ages of the internet.  Don’t like how it looks? No need to delete a line of code:

Just turn whatever line that bothers you into a comment by dropping a “//” in front; great for debugging.

————————-

Learning about initializing variables

1)Initizalizing
–if you plan to use a variable you need to declare it

–Variable can just be declared: ex int hours
–Assign set amount: ex int hours = 40;

DATA TYPES
int (INTEGERS) ex 7, 27, whole numbers
—Byte: 1 byte of memory
—Short: 2 bytes
—Long: 8 bytes. All LONGS must have the suffix “L” at the end or it will be output as an integer and not a long
double (FLOATING POINT) ex 7.1, 27.3 decimals
EXAMPLE:
public class IntegerVariables
{
public static void main(String[] args)
{
int checking; // Declare an int variable named checking.
byte miles; // Declare a byte variable named miles.
short minutes; // Declare a short variable named minutes.
long days; // Declare a long variable named days.

//assignments to the data types, not redeclared
checking = -20;
miles = 105;
minutes = 120;
days = 185000L; //make sure it stays long
// int years = days / 365; mixed data types don’t work
int years = (int)days / 365; //years must be long; can’t fit 8 bytes of stuff in 4 byte box. Use explicite casting
Continue reading



Welcome!
August 20, 2009, 7:58 pm
Filed under: Uncategorized

On this blog I will post tutorials that I”ve written and links to ones that I”ve found that I enjoy. Notes from my Software Development courses will be posted here as well as long with other things I find useful for the maths, sciences, arts, and technology. I do private tutoring in everything from Photoshop, or 3d, to biology, Microbio, and anatomy for people in the Pittsburgh area.



CMU and Finch Robot
August 20, 2009, 4:28 pm
Filed under: Class Notes, Finches | Tags: , , ,

Tom Laurs, the lead researcher for CMU’s robotics institute came to visit class this week. He develops learning robots for computer science education at the newbie level and we’re one of the lab rat groups. Frankly a little robot like that is more “Friendly” to learn with than say a mountain of code. Without sounding too girly, it makes programming seem not so hard or scary when you’re telling a robot to move vs being confronted with “Write a program to mimic photoshop” or some nonsense like that.

Finch robot has a beak that can be programmed to be in any color like the Mathmo Aduki. It can see shapes and lights and can thus follow a person if told to. It can sense temperature to a point and it can move around on the floor on its leash. The Finch can tell how it’s held (upside down, on its side, etc) using an accelerometer from the Wiimote. It can also “speak” through computer speakers.

As we work with the finches I’ll post more on this posting. It’s cute for a tiny robot on a USB cable. Here’s the website of one of the guys who’ programmed it and a pic of it.
Erik Pasternak’s Page

It's probably sleeping because the nose light isn't on, and of course not plugged in

It's probably sleeping because the nose light isn't on, and of course not plugged in



Java programming 101 week 1
August 20, 2009, 4:19 pm
Filed under: Class Notes | Tags: , ,

I’m going to post all my notes for CIT 111 up here on the learning blog for those who either can’t take notes, didn’t, or like me in normal class can’t read them. Lets start with week 1 in Java Programming with D. Smith at CCAC

Basic programs for Java: jdk-6u2-windows-i586-p (library of java classes), jcreate400.
Resource Sites:
–Java.sun.com: Site for java Developers
http://java.sun.com/javase/downloads/index.jsp: download resources for Java SE
http://java.sun.com/docs/books/tutorial/: Java Tutorials home

I: Intro to Java
–All classes needed to program can be found in the Java Platform documentation, found in the links to the right.

I2: Starting with J Creator LE
–The program may look familiar as it’s built like the average windows program.
—A: MAKING A NEW PROJECT

  1. Go to NEW>FILE>Empty java file
  2. When naming your file, the FILE NAME should be the same name as the CLASS NAME
  3. FILE NAME must ALWAYS begin with an uppercase letter: EX (LuckyCat.java)
  4. CONFIGURE>JAVA>Show line numbers

–B: STARTING THE PROJECT

  1. Every time you write a program, you need to have comments. Comments keep things organized, remind what parts of code do,
  2. // = comment start (will show up green)
  3. /* =block comment. Lets you write a whole paragraph of coments without having to do // for every line
  4. {} = Determines where a class begins and ends like < > in HTML. Everything that is in the class (EX: public class LuckyCat)

EX so far:

//PROGRAM TITLE

/*  LuckyCat
 *  CIT 111 AC02
 *  08-20-09
 *  This is an in class toy
 *
 */
 
 public class LuckyCat //class declaration
 {
           public static void main(String [] args) //method declaration
               {

            }
 }// ends class

Continue reading