Study Guides (256,158)
CA (124,557)
York (10,242)
ITEC (115)
ITEC 1620 (18)
Midterm

Midterm_Sample1_Solution.pdf

10 Pages
176 Views

Department
Information Technology
Course Code
ITEC 1620
Professor
Stephen Chen

This preview shows pages 1-3. Sign up to view the full 10 pages of the document.
York University
AK/ITEC 1620 3.0
OBJECT-BASED PROGRAMMING
Midterm Test – Sample
Examiner: S.Y. Chen
Duration: One Hour and Fifteen Minutes
This exam is closed textbook(s) and closed notes. Use of any electronic
device (e.g. for computing and/or communicating) is NOT permitted.
Do not unstaple this test book – any 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 60.
Write your name and student number in the space below. Do the same on
the top of each sheet of this exam where indicated.
NOTE: YOU MAY USE PEN OR PENCIL, BUT ANSWERS IN PENCIL WILL
NOT BE CONSIDERED FOR REGRADING.
Surname: ___________________________________
Given Names: ___________________________________
Student Number: ___________________________________
Q1. __________
Q4. __________
Q2. __________
Q5. __________
Q3. __________
Total
Surname:_____________ First name:______________ Student #: _______________
Question 1a (5 marks) Evaluating Conditions:
When a condition is evaluated in JAVA, it is useful to know both its result (TRUE or
FALSE) and which terms were evaluated. For the conditions listed below, please circle
all terms that were evaluated and give the final result of the condition. Note: terms in a
condition are only evaluated if the (sub) result is still unknown.
Example :
boolean a = true, b = true, c = false, d = false;
(!a && ((b || c) && !d)) || ((a && !c) || d)
After evaluating !a, the left sub-result is known to be FALSE. Skipping to the next
term in the OR expression, a is TRUE so the next term in the AND expression is
evaluated. Upon evaluating !c, (a && !c) is TRUE and the right sub-result is
known to be TRUE. The overall result is now known to be TRUE, so no further
terms need to be evaluated.
Please answer both parts below.
Part 1 (2.5 marks):
boolean a = false, b = true, c = true, d = false;
((!b && a) || d) || ( (!d || (a && c) ) && ((!a && d) || c) )
Part 2 (2.5 marks):
boolean a = true, b = false, c = false, d = true;
((!b && a) || d) || ( (!d || (a && c) ) && ((!a && d) || c) )
TRUE
TRUE
TRUE
Surname:_____________ First name:______________ Student #: _______________
Question 1b (5 marks) Designing if statements:
You are trying to organize an on-line, video game tournament. The tournament requires
an even number of players. Thus, after including yourself and your roommate, you need
to invite an even amount of friends. Since it would be impolite to invite some but not all
of a set of friends, you note that you have an even number of neighbours, an odd number
of co-workers, and an odd number of regulars.
neighbours even
co-workers odd
regulars odd
In a JAVA program, there are three boolean variables – neighbours, coworkers,
and regulars. The value of each variable is true if you choose to invite that set of
friends, and false otherwise.
Write an if statement that will set the boolean variable even to true if the invited
set(s) of friends creates an even number of total players (including yourself and your
roommate), and to false if the invited set(s) of friends results in an odd number of total
players.
Please write your answer below.
if ((coworkers && regulars) || (!coworkers && !regulars))
even = true;
else
even = false;

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.

Leah — University of Toronto

OneClass has been such a huge help in my studies at UofT especially since I am a transfer student. OneClass is the study buddy I never had before and definitely gives me the extra push to get from a B to an A!

Leah — University of Toronto
Saarim — University of Michigan

Balancing social life With academics can be difficult, that is why I'm so glad that OneClass is out there where I can find the top notes for all of my classes. Now I can be the all-star student I want to be.

Saarim — University of Michigan
Jenna — University of Wisconsin

As a college student living on a college budget, I love how easy it is to earn gift cards just by submitting my notes.

Jenna — University of Wisconsin
Anne — University of California

OneClass has allowed me to catch up with my most difficult course! #lifesaver

Anne — University of California
Description
York University AK/ITEC 1620 3.0 OBJECT-BASED PROGRAMMING Midterm Test – Sample Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes This exam is closed textbook(s) and cl osed notes. Use of any electronic device (e.g. for computing and/or communicating) is NOT permitted. Do not unstaple this test book – an y 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 60. Write your name and student number in the space below. Do the same on the top of each sheet of this exam where indicated. NOTE: YOU MAY USE PEN OR PENCI L, BUT ANSWERS IN PENCIL WILL NOT BE CONSIDERED FOR REGRADING. Surname: __________________ _________________ Given Names: ___________________________________ Student Number: ___________________________________ Q1. __________ Q4. __________ Total Q2. __________ Q5. __________ Q3. __________ Surname:_____________ First name:______________ Student #: _______________ Question 1a (5 marks) Evaluating Conditions: When a condition is evaluated in JAVA, it isuseful to know both its result (TRUE or FALSE) and which terms were evaluated. For the conditions listed below, please circle all terms that were evaluated and give the final result of the condition. Note: terms in a condition are only evaluated if the (sub) result is still unknown. Example : boolean a = true, b = true, c = false, d = false; (!a && ((b || c) && !d)) || ((a && !c) || d) TRUE After evaluating !a, the left sub-result is known to be FALSE. Skipping to the next term in the OR expression, a is TRUE so the next term in the AND expression is evaluated. Upon evaluating !c, (a && !c) is TRUE and the right sub-result is known to be TRUE. The overall result is now known to be TRUE, so no further terms need to be evaluated. Please answer both parts below. Part 1 (2.5 marks): boolean a = false, b = true, c = true, d = false; ((!b && a) || d) ||((!d || (a && c) ) && ((!a && d) || c) TRUE Part 2 (2.5 marks): boolean a = true, b = false, c = false, d = true; ((!b && a) || d) ||((!d || (a && c) ) && ((!a && d) || c) TRUE Surname:_____________ First name:______________ Student #: _______________ Question 1b (5 marks) Designing if statements: You are trying to organize an on-line, video game tournament. The tournament requires an even number of players. Thus, after including yourself and your roommate, you need to invite an even amount of friends. Since it would be impolite to invite some but not all of a set of friends, you note that you have an even number of neighbours, an odd number of co-workers, and an odd number of regulars. neighboursven co-workers odd regulars odd In a JAVA program, there are three boolean variables –neighbours, coworkers, and regulars. The value of each variable is true if you choose to invite that set of friends, and false otherwise. Write an if statement that will set the boolean variabeven to true if the invited set(s) of friends creates an even number of totplayers (including yourself and your roommate), and to false if the invited set(s) of friends results in an odd number of total players. Please write your answer below. if ((coworkers && regulars) || (!coworkers && !regulars)) even = true; else even = false; Surname:_____________ First name:______________ Student #: _______________ Question 2 (10 marks) Evaluating JAVA Code: Please answer both parts below. Note: you must show your wo rk to receive any credit. Part 1 (5 marks): i x int x = 0; 0 50/60 for (int i = 0; i < 10; i++) 1 60 { 2 60 if (i % 3 == 0) 3 110 x += 50; 4 110 else if (i % 5 == 0) 5 130/140 x += 20; 6 190 if (i % 5 == 0) 7 190 x += 10; 8 190 } 9 240 What is the final value of x? 240 Part 2 (5 marks): x y int
More Less
Unlock Document


Only pages 1-3 are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Don't have an account?

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