Programming > QUESTIONS & ANSWERS > School of Information Technology Atkinson Faculty of Liberal and Professional Studies York Universit (All)
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 = s.indexOf("n"); int q = s.substring(++i, j++).indexOf("n"); System.out.println(p + " " + i); System.out.println(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. [Show More]
Last updated: 1 year ago
Preview 1 out of 12 pages
Connected school, study & course
About the document
Uploaded On
Apr 18, 2023
Number of pages
12
Written in
This document has been written for:
Uploaded
Apr 18, 2023
Downloads
0
Views
29
In Browsegrades, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Browsegrades · High quality services·