School of Information Technology Atkinson Faculty of Liberal and Professional Studies York University AK/ ITEC 1620 Introduction to Object Oriented Programming– Object-Based Programming_ FINAL EXAMINATION _WithAnswers
School of Information Technology Atkinson Faculty of Liberal and Professional Studies York University AK/ ITEC 1620 Introduction to Object Oriented Programming– Object-Based Programming_ FINAL EXAM INATION _WithAnswers PART A: FIND OUTPUT OF JAVA CODE FRAGMENTS [40 marks] 1. What is the output of the following Java code fragment? [5 marks] String s = "York University"; int i = 3; int j = 9; int p = Of("n"); int q = ring(++i, j++).indexOf("n"); Sln(p + " " + i); Sln(q + " " + j); PART B: PROGRAMMING QUESTION [60 marks] 1) [15 marks] 7AK/ITEC 1620 3.0A&B: Object-Based Programming Fall 2007 Using the Coin class with the API shown below design and implement the driver class FlipRace which creates two Coin objects , then continually flips them both to see which coin comes up Heads three flips in a row. Continue flipping the coins until one coin wins the race and also consider the possibility that both coins achieve the objective in the same time (that will be a tie). Print the results of each turn and at the end print the winner and the total number of flips that were required. Possible output: flip 1 Tails Tails flip 2 Tails Tails flip 3 Tails Tails flip 4 Tails Heads flip 5 Tails Heads flip 6 Heads Tails flip 7 Tails Heads flip 8 Heads Tails flip 9 Heads Heads flip 10 Tails Tails flip 11 Heads Heads flip 12 Heads Tails flip 13 Heads Tails First coin is the winner after 13 flips The API for Coin class is: public Coin() // default constructor public void flip() //Flips the coin by randomly choosing a face value. public boolean isHeads() //Returns true if the current face of the coin is heads public String toString() // Returns the current face of the coin as a string.
Written for
- Institution
- School of Information Technology Atkinson Faculty
- Course
- School of Information Technology Atkinson Faculty
Document information
- Uploaded on
- April 18, 2023
- Number of pages
- 12
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
school of information technology atkinson faculty of liberal and professional studies york university ak itec 1620 introduction to object oriented programming– object based programming final examina