CIS 636 – Spring 2005
03/03/05 Mid
Term Test Test Form B
Name:
Instructions:
Answer ALL questions on the answer
sheet provided.
Hand in TEST, Attached Code, Answer
Sheet, and Help Sheet, each with your name on it.
This part of the test is “closed book”
except for your help sheet. This part of the test must be handed in before you
receive the programming part of the test. You will not be able to go back and
revise your answers for this section of the test after you have received the
programming part of the test (you can hold onto your help sheet while doing the
programming part)
Remember to put the letter of your test form
on your answer sheet.
Please ask any clarifying questions you have
(come up).
True/ False – If False, Explain Why (4 points each)
- Data that is protected may be accessed only by
methods of the class that it is defined in, and any subclasses of the
class.
- A class can only implement one interface, no more.
- A switch statement can have cases based on a variable of
an enumerated type.
- A new capability of Java (in 1.5) is the capability to
define a method that can be passed a variable number of parameters.
Terminology (3 points each)
- An important OOP principle, ________ means that a higher
level view of something is taken, with some details ignored. From an OOP
perspective, the application of this principle means that data concerning
objects of interest is identified along with operations to be allowed for
that data. Everything else about such objects is ignored.
- ________ methods are not run for specific objects. They
can be invoked using Classname.methodname(parameters). They provide some
functionality that does not require an object.
- One of the principles of OOP, ________ means that the same
method name can be used for multiple forms of the method (multiple
versions of code). Strict definitions require that in order to count as
this, the determination of what code to run must be able to be made at
run-time.
- A kind of statement used for testing and debugging,
________ tests some condition and if the condition is not true, creates a
run-time error.
- A new capability in Java, ________ allows a direct
assignment of a primitive value (such as an int or double) into an wrapper
object (such as an Integer or Double) without any explicit conversion or
cast.
Short Answer (points as shown)
(6 points)
- The keyword “final” has several uses. Explain briefly its
meaning when used with data, methods, and classes.
(6 points)
11.
Why are instance variables usually
defined as private?
Doing and Understanding: (points as shown)
(6 points)
- Given the attached EzPassLocation, EzPassBridge,
EzPassInterchangeArrays, EzPassCustomer, and exception classes, what is
displayed by the following code fragment?
EzPassCustomer customer1 = new
EzPassCustomer("Alice", 10.00, false, 5.00, 111);
EzPassCustomer dup = new EzPassCustomer("Alice", 10.00, false, 5.00, 111);
if (dup = = customers[1]) {
System.out.println("The
same");
}
else {
System.out.println("Different");
}
(10 points)
- Given the attached
EzPassLocation, EzPassBridge, EzPassInterchangeArrays, EzPassCustomer, and
exception classes, and assumiong that the code in Question 13 has already
run, what is displayed by the following code fragment?
EzPassBridge
bridge1 = new EzPassBridge("Betsy", "Pennsk",
"NJ", "NJ 90", 3, 'W',2.70);
bridge1.debit(customer1);
System.out.println("Cust
1: " + customer1);
bridge1.debit(customer1);
System.out.println("Cust
1: " + customer1);
(6 points)
- Given the attached
EzPassLocation, EzPassBridge, EzPassInterchangeArrays, EzPassCustomer, and
exception classes, and assumiong that the code in Question 14 has already
run, what is displayed by the following code fragment?
EzPassLocation tollPlaces []
= new EzPassLocation[3];
tollPlaces[0] = bridge1;
System.out.println("Bridge: " +
tollPlaces[0]);
CIS 636 – Spring 2005
03/03/05 Mid
Term Test Part 2
Name:
Instructions:
Answer ALL questions by writing
code and turning in a complete setup of folders and files so it can be easily
tested (and printouts).
Hand in TEST, and Help Sheet,
printouts, and disk, and the CD-R I gave you, each with your name on it.
This part of the
test is “open-anything” – any resources you have, or can find on the Net are
permissible.
You cannot go
back to Part 1 of the test after receiving this part.
Please ask any clarifying questions
you have (come up).
Writing Code (points as shown)
MAKE SURE THAT ANYTIME YOU ARE ADDING TO OR ADAPTING A
FILE THAT YOU CLEARLY MARK WHERE YOUR CHANGES ARE!!!!!
Given the Card, Hand, Deck, Player, Person (and ID) classes
and the Suit and Rank enumerated types and the IO package included on the
included CD, carry out the following questions. (the CD is CD-R, so you
cannot update on there)
(15 points)
- Add a method to the Hand class, playChoiceInSuit, which
(passed a Suit), gives the user a choice of the cards in the hand, and
returns the one chosen, adjusting the hand (essentially playing it). If
there is no card in the given suit, throw an Exception with appropriate
message
(20 points)
- Write a (portion of a) main class, setting up for a game
in which there are 4 players and all cards in the deck are dealt to the
players (after being shuffled of course). You can kludge together players
names etc, but I recommend strongly that you deal in some kind of loop.
Show the players’ hands. Have the first player choose a club to play. Show
the card to play, and show the revised hand.