1 / 11

Final Exam Review

Final Exam Review. CSE113. 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. While loop.

bree
Télécharger la présentation

Final Exam Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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,…. intans = 0; int count = 1; intnum; 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? intsumSq = 0; intsq; for (inti = 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* 14 -16/3

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

More Related