CS001 Lab-2

SCRATCH

Exercise-1

Write Scratch scripts to do the following:

1.  Make an applause sound happen for 3 second when you click the green flag.

2.  Play the applause sound continuously when you click the space bar.

3.  Get a sprite to move forward 100 steps and then turn right and move in a downward direction for 100 steps.

4.  Get a sprite to move to wherever you move your pointer to.

Exercise-2

Create a program as follows:

1.  Get one sprite (Sprite1) to move around the screen in random way when the green flag is clicked.

2.  Use the keyboard to control the movement of the other sprite (Sprite2)

3.  If Sprite1 touches Sprite2, create an action by adding a sound and saying something

4.  Count how many times Sprite1 touches Sprite2 by adding a variable.

JAVA

1.  Open the notepad and type the following. Be careful with the uppercase and lowercase letters. Java is CASE-SENSITIVE.

public class Average

{

public static void main(String[] args)

{

int number1 = 5;

int number2 = 4;

int number3 = 7;

int sum = number1+number2+number3;

int average = sum/3;

System.out.println(sum);

System.out.println(average);

}

}

2.  Save the program as Average.java in your X: drive

3.  Click on Start -> Run

4.  Type cmd

5.  Type X:

6.  Type javac Average.java

7.  Press enter key

8.  Type java Average

9.  Press enter key

YOU WILL NOW SEE THE OUTPUT ON THE SCREEN AS

18

6

WHICH ARE YOUR CORRECT OUTPUTS

Program to find if the first number is greater than or less than or equal to the second number.

public class Maximum

{

public static void main(String[] args)

{

int x = 10;

int y = 20;

if (x<y)

{

System.out.println(“ x is less than y ”);

}

else

if (x>y)

{

System.out.println(“ x is greater than y ”);

}

else

{

System.out.println(“ x is equal to y ”);

}

}

}

Save the file now as Maximum.java in your X: drive

Repeat the steps 3-9