Reference no: EM132460628
ISY00245 - Principles of Programming Assignment - Southern Cross University, Australia
Green Foot Assignment - Programming Portfolio
Activity R4-2
Q1) Declare a variable called children of type int. Then write an assignment statement that assigns to this variable the sum of two of variables named daughters and sons.
Q2) Declare a variable named area of type int. Then write an assignment statement that assigns to area the product of two variables called width and length. Remember that the multiplication operator in Java is.
Q3) Declare two variables x and y of type int. Assign the values 23 to x and 17 to y. Then write some code to swap those values (so that afterwards x contains 17 and y contains 23). BE CAREFUL NOT TO LOSE THE VALUES while you are doing this!
Activity R4-3
2) The Greenfoot class has a method to get the noise level from the computer's microphone. Find this method in the API documentation. How many parameters does it have?
3) What is the return type of this method? What does this tell us?
4) What are the possible values returned from this method?
5) Is this method static or not? What does that tell us?
6) How do we call this method? Write down a correct method call to this method
7) In your stickman scenario, make the stickman move to the RIGHT, so that when you run your scenario, he walks over to the right side of the screen. Note: no keyboard input is required.
Activity 6-3
1) Write down the signature for the three methods.
2) Write down an example of a call to the setLocation method.
Activity R7-1
1) Declare and initialize a String array called names with the names of three of your classmates, or if you are an Online student, three of the names from one of the lectures
2) Write the code that will play a sound "ouch.wav" 20 times, using a while loop.
3) Consider the following code:
int x = 3;
int i = 0;
while (i < 3)
{
x = x + 1;
i = i + 1;
}
What is the value of x after this code has executed? Place your answers to this exercise in your portfolio document under the heading.
Activity R7-2
1) Open the scenario called bubbles. You will see that the world is empty. Place some Bubble objects into the world, using the default constructor. Remember you can also do this by shift-clicking into the world. What do you observe?
2) What is the initial size of a new bubble?
What is its initial color?
What its initial direction of movement?
Activity R8-1
1) Declare and initialise a String array called names with the names of three of your classmates, or if you are an Online student, three of the names from one of the lectures.
2) Write the Java/Greenfoot code (not in Greenfoot itself) that will loop through this array, showing each of the names using the showText method, in a different location each time.
3) Write a loop that will add the even numbers from 2 to 2000.
4) Write a FOR loop that will display the numbers from 199 down to 100.
Activity R9-7
Module 9: For-Each Loop
I have implement a simple scenario with class ant. Then I added a few ant objects to the scenario and used a list collection to store them in a single list. Then to set a random direction for each ant to stimulate ant movement I used the For each loop to iterator through the list and thus setting each ant with random direction. For each loop is very useful to iterator though an array or any other collection.
Module 10: Overloading Constructors
These are the constructors defined for the leaf object, using these leaf class object can be instantiated with different property so they can act like different objects in the game.
The first constructor public Leaf() creates a normal leaf object.
The second constructor public Leaf(int val) creates a normal leaf object with given value to the lead.
The third constructor public Leaf(String type) creates a leaf object with different setting based on the type string value.
This is demonstrates constructor overloading, as based on the number and type of parameters passed to the constructor the relevant method is invoked and the object is created by that constructor.