Study Guides (248,302)
Canada (121,471)
York University (10,193)
ITEC 1620 (18)
Final

Final_Sample2.pdf

16 Pages
347 Views
Unlock Document

Department
Information Technology
Course
ITEC 1620
Professor
Stephen Chen
Semester
Fall

Description
York University AK/ITEC 1620 3.0 OBJECT-BASED PROGRAMMING Final Exam Sample Examiner: S. Chen Duration: Three Hours This exam is closed textbook(s) and cl osed notes. Use of any electronic device (e.g. for computing and/or communicating) is NOTrmitted. Do not unstaple this test book – ay detached sheets will be discarded . Answer all questions in the space provided. No additional sheets are permitted. Work independently. The value of each part of each question is indicated. The total value of all questions is 100. Write your name and student number in the space below, and on the top of each sheet of this exam where indicated. NOTE: YOU MAY USE PEN OR PENCIL. Surname: __________________ _________________ Given Names: ___________________________________ Student Number: ___________________________________ 1 2 Total 3 4 5 6 Question 1 (15 marks) Object Diagrams: Answer both parts below. The file First.java contains the following implementation of the First class: public class First { public int value; public First (int value) { } } The file Second.java contains the following implementation of the Second class: public class Second { public First first; public int second; public Second (First first, int second) { } } The main method in the file MainClass.java uses the above classes: public class MainClass { public static void main(String[] args) { First x = new First(8); First y = new First(1); Second a = new Second(y, 2); // Part 1 – draw the object diagrams at this time x;= y a.secondrst.value; x = new First(7); a.fi=st // Part 2 – draw the object diagrams at this time } } Surname:_____________ First name:______________ Student #: _______________ When java MainClass is executed, Part 1 ( 5 marks): draw the object diagrams for all identiFirst and Second when the comment line “ // Part 1 – draw the object diagrams at this time” is reached. Part 2 (10 marks): draw the object diagrams for all identiFirst and Second when the comment line “ // Part 2 – draw the object diagrams at this time” is reached. Question 2 (15 marks) Structured Programming: Write a program in JAVA that will determine if the input int value represents a valid Wizard Ball score. In Wizard Ball, there are two ways to score – “lightning bolts” which are worth 7 points and “fire balls” which are worth 11 points. To be a valid score, it must be possible to achieve the given score with an integer number of lightning bolts and fire balls. For example, the following inputs would lead to the underlined output: Example 1: 28 validrng bolts, zero fire balls Example 2: 36 lithtni//lid ng bolts, two fire balls Example 3: 19 not validibl/i/nations Example 4: 0 validn/i/ng bolts, zero fire balls Example 5: 12 ponot validnations Example 6: 22 valid // zero lightning bolts, two fire balls Please write your program on the following page. You may use this page for rough work, but anything on this page will not be graded. Surname:_____________ First name:______________ Student #: _______________ import java.until.*; public class Question2 { public static void main (String[] args) { } } Question 3 (15 marks) Arrays: Write a code fragement in JAVA that will determine if a fully populated array of ints has more odd values than even values. Only consider positive values – all values less than or equal to zero will not be counted as being either even or odd. Example outputs (underlined) are given below: Example 1: int[] array1 = new int[] {1, 2, 3}; // two odd values, one even value Array has more odd Example 2: int[] array1 = new int[] {1, 2, 3, 2}; // two odd values, two even values (no output) Example 3: int[] array1 = new int[] {-1, 2, 3}; // one odd value, one even value, one non-positive value (no output) Please write your code on the following page. You may use this page for rough work, but anything on this page will not be graded . Surname:_____________ First name:______________ Student #: _______________ // int[] array1; Question 4 (15 marks) Arrays of Objects: The API for the DigitCode class is given below. Each instance of this class represents a two-digit code. Each digit is an integer fr om 0-9 (inclusive), and a code must contain two distinctigits to be valid – e.g. the codes 0,0 and 8,8 are invalid because the first and second digits in both codes are the same. The default code is 1,2 – 1 is the first digit of the code, and 2 is the second digit of the code. Field Summary static int DEFAULT_FIRST The first digit of the default code. static int DEFAULT_SECOND The second digit of the default code. Constructor Summary DigitCode () Constructs a new two-digit code set to the default – 1,2. Method Summary boolean changeCode (int old1, int old2, int new1, int new2) Attempts to change the code to new1,new2. To do so, old1,old2 must match the current code, and new1,new2 must represent a valid code. Returns true if the code is changed, and false otherwise. Example: if the current code is 1,2, then changeCode(1,2,3,4) will change the code to 3,4 and return true. If the current code is 3,4, then changeCode(3,4,5,5) will leave the code unchanged and return false. boolean isCode (int first, int second) Returns true if the code is first,second, and false otherwise. Example: if the current code is 1,2, then isCode(3,4) will return false. Given a partially-populated array of DigitCodes where each DigitCode has the default code, write a code fragment in JAVA that will set each DigitCode to a random code that is not the default code. Please write your code on the following page. You may use this page for rough work, but anything on this page will not be graded Surname:_____________ First name:______________ Student #: _______________ // DigitCode[] codes; // int count; Question 5 (25 marks) Object-Based Programm
More Less

Related notes for ITEC 1620

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit