Lucky Cat Tutoring Services


Return Method Example
October 20, 2009, 4:08 pm
Filed under: Uncategorized | Tags: , , , , , ,

Here’s an example of a method that returns the smallest number out of a set of three entered by the user:
Continue reading



October 13, 2009, 4:07 pm
Filed under: Uncategorized | Tags: , , , ,

Methods:Stand alone units, or blocks of code that do a specific task.
–EXAMPLE: public static void main(String []args) <—a main method
–the "public" means it's public, "void" returns nothing, "(String[]args)" returns the string

Step-line Refinement: Creating routines and methods to break the code down into more manageable and efficent parts.

MAKING A METHOD
1) Call the method inside the main method: any method that is called inside the main must also be STATIC!

Example: public static void printStar()
{
}
KEY POINT:METHODS CAN NEVER BE INSIDE ANOTHER METHOD! It’s inside the class, but outside any other method!

2) next put the required method code inside the {} to make the method, making sure that the block of code stands alone.

3)INVOKING THE METHOD: put the method in the code by putting the method name and ()

Continue reading



Free Programming Reference Cards
October 8, 2009, 3:50 pm
Filed under: Java | Tags: , , , ,

Programmer Ref Cards from Dzone. Free Sparknotes style cheat sheet references for programmers and students. Registration to the site is free too!



Making a Finch Count With ‘For’ Loop
October 6, 2009, 3:01 pm
Filed under: Finches, Java | Tags: , , , , ,

Here’s some code to make the CMU Finch count down from 10 and sing.

/**
 * Created by:
 * Date:
 * make baby Finch count and change nose color to a random tint with each number
 */

import finch.*;
import javax.swing.JOptionPane;
import java.util.Random;

public class finchCount
{

   public static void main(final String[] args)
   {
   // Instantiating the Finch object
      Finch baby = new Finch();
      Random spin = new Random();
      int count, redNum, greenNum, blueNum;
   String input; //name for what you’re asking for
  
   
  input = JOptionPane.showInputDialog(null, “What number do you want to count to?”);
  count = Integer.parseInt(input);
  
  for(int i = 1; i <= count; i++)//variable I; while I is lessthan/equal to COUNT, keep adding to I
          //never a ; here
  {
   baby.saySomething(“”+ i);
   baby.sleep(1000);
   //turn nose to random color
   redNum= spin.nextInt(256);//random num between 0 and 255
   greenNum= spin.nextInt(256);//random num between 0 and 255
   blueNum= spin.nextInt(256);//random num between 0 and 255
   baby.setLED(redNum,greenNum,blueNum);
   baby.sleep(1000);
   System.out.println(“number ” +i);
   
   
  }
      // Always end your program with finch.quit()
      baby.quit();
      System.exit(0);
    }
}

How about a fun nose  color change too? Continue reading