CSC 335 Fall 2006 Practice Test 1 Answers and Explanations, Exams of Computer Science

The answers and explanations for practice test 1 of csc 335 fall 2006. It covers topics such as objects, classes, and relationships between them, as well as creating candidate objects for a system and drawing uml diagrams. It also includes examples and exercises.

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-cfj
koofers-user-cfj 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C Sc 335 Fall 2006 Answers to Practice Test 1
The answer could have been any of these first three bullets
1. Object:
A module that makes up part of a system
A software model of a real world entity (account), concept (strategy), or part of a utility (network data
base, GUI, event)
A bunch of bits in the memory of the computer
Extra explanation fo 1 follows
Every object has
1) an identity a reference variable to find the object
2) methods a.k.a. functions
3) variables: the values that the object remembers
2. Class:
A blueprint for objects of that type
An OO way to implement a type as a set of operations and data
Code that descrobe the method and variables
Relationship between a class diagram and two instance diagrams (on the right) after these two
constructions
BankAccount anAcct = new BankAccount("Stoers", 333.33);
BankAccount acct2= new BankAccount("Daly", 75.00);
3. Keeps related data and methods together
4. The method or variable can be accessed anywhere an object of that type can be declared (unloess
shadowed)
5. Polymorphism in action
toString
addActionListener
1
-String my_ID
-double my_balance
+withdraw(double amount)
+deposit(double amount)
+double getBalance( )
+String getID( )
+String toString()
BankAccount
BankAccount: anAcct
my_ID = "Stoers"
my_balance = 333.33
my_ID = "Daly"
my_balance = 75.00
BankAccount: acct2
class name
instance
variables
methods
instance
(object)
instance
(object)
state
state
pf3
pf4

Partial preview of the text

Download CSC 335 Fall 2006 Practice Test 1 Answers and Explanations and more Exams Computer Science in PDF only on Docsity!

C Sc 335 Fall 2006 Answers to Practice Test 1

The answer could have been any of these first three bullets

  1. Object:
  • A module that makes up part of a system
  • A software model of a real world entity (account), concept (strategy), or part of a utility (network data base, GUI, event)
  • A bunch of bits in the memory of the computer

Extra explanation fo 1 follows

Every object has

  1. an identity a reference variable to find the object
  2. methods a.k.a. functions
  3. variables: the values that the object remembers
  1. Class:

• A blueprint for objects of that type

• An OO way to implement a type as a set of operations and data

• Code that descrobe the method and variables

Relationship between a class diagram and two instance diagrams (on the right) after these two constructions BankAccount anAcct = new BankAccount("Stoers", 333.33); BankAccount acct2= new BankAccount("Daly", 75.00);

  1. Keeps related data and methods together
  2. The method or variable can be accessed anywhere an object of that type can be declared (unloess shadowed)
  3. Polymorphism in action

• toString

• addActionListener

  • String my_ID
  • double my_balance +withdraw(double amount) +deposit(double amount) +double getBalance( ) +String getID( ) +String toString()

BankAccount

BankAccount: anAcct my_ID = "Stoers" my_balance = 333. my_ID = "Daly" my_balance = 75. BankAccount: acct

class name

instance

variables

methods

instance

(object)

instance

(object)

state

state

6. Create an initial list of candidate objects for your system (NEW) with its main (major) responsibility

BookStore: Coordinates Activities (Check out student, collect payment, update inventory)

Student: Keeps track of CatCard number, address, sales confirmation order

ShoppingBasket: Keeps track of desired purchases

Item: one the books that can be purchased

Shelf: Shows books for purchase, with browse/search

Inventory: Keeps inventory levels of all items

7. Draw a UML class diagram showing all of your candidate objects and any relationships between them. Show

inheritance relationships, interface implementation, or general association such as dependency by drawing a line.

Write any multiplicity adornment you can think of. You will likely have 1, and or * in a few places at least. The

classes only need the class name and its major responsibility, one or more method names (no attributes needed for

a perfect score).

  1. Note: if the JTextField was constructed with "1.23", the output would be Good and Ugly Bad Ugly

14. Iterator itr = set.iterator();

assertEquals ( -1 , itr.next());

assertEquals ( 0 , itr.next());

assertEquals ( 2 , itr.next());

assertEquals ( 5 , itr.next());

assert False (itr.hasNext());

15. for(Integer i : set)

System.out.println(i);

16. No: Need an int 5 or new Integer(5)

  1. rule-spam rule-AOL rule-Bad Text

//... NumberListener listener = new NumberListener(); myField.addActionListener(listener); //... cp.add(prompt, BorderLayout. NORTH ); cp.add(myLabel, BorderLayout. CENTER ); cp.add(myField, BorderLayout. SOUTH ); } private class NumberListener implements ActionListener { public void actionPerformed(ActionEvent ae) { try { double num = Double. parseDouble (myField.getText()); myLabel.setText("You entered: " + num); } catch (NumberFormatException nfe) { myLabel.setText("!!ERROR"); } } } }