Midterm_Sample2.pdf

97 views10 pages
Published on 12 Oct 2012
Course
Professor
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
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in
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) && ( b || (a && !d) ) ) || ((d && a) || !b)
Part 2 (2.5 marks):
boolean a = true, b =false, c = false, d = true;
( ((b || a) && d) && ( b || (a && !d) ) ) || ((d && a) || !b)
TRUE
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in
Surname:_____________ First name:______________ Student #: _______________
Question 1b (5 marks) Designing if statements:
A student needs six major credits to complete her degree. The available major courses
next semester are
HALF4000 3 credits on Tuesday nights
READ4100 3 credits on Wednesday nights
FULL4300 6 credits on Monday and Wednesday nights
In a JAVA program, there are three boolean variables – half, read, and full. The
value of each variable is true if the student takes this course, and false otherwise.
Write an if statement that will set the boolean variable graduate to true if the taken
courses provide at least six credits and do not have any conflicts, and to false if the
taken courses do not have enough credits to allow her to graduate or if there is a
scheduling conflict.
Please write your answer below.
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 10 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Grade+

Unlimited access to all notes and study guides.

YearlyMost Popular
75% OFF
$9.98/m
Monthly
$39.98/m
Single doc
$39.98

or

You will be charged $119.76 upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.