Presentation is loading. Please wait.

Presentation is loading. Please wait.

Final Exam Review CSE113.

Similar presentations


Presentation on theme: "Final Exam Review CSE113."— Presentation transcript:

1 Final Exam Review CSE113

2 Arithmetic Expression
Assume A = 2, B =4, C =10, D=5, evaluate the following expressions. Ans1 = A + B - C + D Ans2 = B * C / A Ans3 = C + B – D/A Ans4 = B * (C/A) Ans5 = C % B * D Ans6 = (C+B – D)/A

3 While loop What is the output when the “while” loop given below is executed? Assume number generated are : 0, 4, 3, 2 ,5, 3, 5, 3, 4, 2,…. int ans = 0; int count = 1; int num; while (count < 5) { num = Greenfoot.getRandomNumber(6); if (num % 2 == 0) { ans = ans + num; } count = count + 1; }

4 While loop Write a while that adds 4 crabs in a vertical line to the world at locations {(10, 100), (20, 100), (30, 100) etc. } How will you modify this to add 10 crabs?

5 Array Definition You want to create a scenario with a (i) pink worm (pworm.jpg), (ii) blue worm (bworm.jpg), (iii) brown carb (bcrab.jpg), (iv) green crab (gcrab.jpg), (v) red lobster (rlob.jpg). Write an array definition for this and initialize it with the image files given above.

6 For statement Use a “for” statement to add the above objects to the world.

7 Evaluate the “for” statement
What does the following “for” evaluate? int sumSq = 0; int sq; for (int i = 0; i < 4; i++) { sq = i* I; sumSq = sumSq + sq; }

8 Evaluate the Switch statement
switch (color) { case ‘v’ : {bg.SetColor(Color.VIOLET); break;} case ‘i’ : {bg.SetColor(Color.INDIGO); break;} case ‘b’ : {bg.SetColor(Color.BLUE); break;} case ‘g’ : {bg.SetColor(Color.GREEN); break;} case ‘y’ : {bg.SetColor(Color.YELLOW); break;} case ‘o’ : {bg.SetColor(Color.ORANGE); break;} case ‘r’ : {bg.SetColor(Color.RED); break;} default: { bg.setColor(Color.BLACK);} } If color is assigned ‘i’ what is the color for writing?

9 Write a switch statement
Write a switch statement that converts a number representing day of the week into a word for the day.

10 Evaluate the method calls
Using the calculator class and its methods write a set of call that will evaluate: 5 + 6* /3

11 Write a method Write a method that computes the distance between two location and outputs the distance on the screen.


Download ppt "Final Exam Review CSE113."

Similar presentations


Ads by Google