Final Exam Review Sheet - Object-Oriented Programming and Design | C SC 335, Exams of Computer Science

Material Type: Exam; Class: Object-Oriented Programming and Design; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Fall 2000;

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-dab
koofers-user-dab 🇺🇸

9 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSc 335 Fall 2004 Final Exam Review Sheet and Sample Questions
Note: Return your lab card (if you are not a major) to 917 Gould Simpson before Friday, 17-Dec 4:00pm
Final Exam: Econ 111 (usually lecture room) Tuesday 14-December-2004, 2:00 p.m. to 4:00 p.m.
oThis final exam will be closed-book and closed-notes
oWrite answers with pencil please (unless you really need a pen)
oThere will be a final exam review session in 701 Gould Simpson, Monday, 13-Dec 5:00-7:00
Final Exam Questions
1. Inheritance: Trace inheritance hierarchies and show output (like the midterm or the tracing of
decorator code that we did with the Animal/Mammal/Insect example).
2. A Little Analysis and Design: Given a problem specification: find the objects, write a sequence
diagram, draw a UML diagram (like the midterm)
3. Answer either one (not both) of the following two questions. If you answer both we will deduct
points from both answers. Please do not answer both in the hopes we will take the higher score.
oSwing and awt API – Layouts, GUIs, Listeners, Events. If you see a new event or a new
graphical component, they will be documented with descriptions and/or API calls
oor a networking question
4. Know some low-level design guidelines and some refactorings: Like 15-Sep section handout.
Sometimes there is no correct answer, so your justification is the important thing: Why.
5. Know synopses of the design patterns we discussed: Adapter, Facade, Composite, Singleton,
Observer, Mediator, Flyweight, Factory Method, State, Strategy, Command, Decorator, Iterator
plus Model-view separation. For example, which pattern defines an interface while retaining
control of which class to instantiate?
6. Write code, interfaces and/or classes for a problem using a Design Pattern that we have not
presented in class or section, from one of these. Bridge Chain of Responsibility, Builder,
Prototype, Visitor.
7. Write code, interfaces and/or classes for a problem using a Design Pattern that we have
presented in class or section: See list above.
8. A question you cannot get wrong unless you leave it blank.
1
pf3
pf4
pf5

Partial preview of the text

Download Final Exam Review Sheet - Object-Oriented Programming and Design | C SC 335 and more Exams Computer Science in PDF only on Docsity!

CSc 335 Fall 2004 Final Exam Review Sheet and Sample Questions

Note: Return your lab card (if you are not a major) to 917 Gould Simpson before Friday, 17-Dec 4:00pm

Final Exam: Econ 111 (usually lecture room) Tuesday 14-December-2004, 2:00 p.m. to 4:00 p.m.

o This final exam will be closed-book and closed-notes

o Write answers with pencil please (unless you really need a pen)

o There will be a final exam review session in 701 Gould Simpson, Monday, 13-Dec 5:00-7:

Final Exam Questions

1. Inheritance: Trace inheritance hierarchies and show output (like the midterm or the tracing of

decorator code that we did with the Animal/Mammal/Insect example).

2. A Little Analysis and Design: Given a problem specification: find the objects, write a sequence

diagram, draw a UML diagram (like the midterm)

3. Answer either one (not both) of the following two questions. If you answer both we will deduct

points from both answers. Please do not answer both in the hopes we will take the higher score.

o Swing and awt API – Layouts, GUIs, Listeners, Events. If you see a new event or a new

graphical component, they will be documented with descriptions and/or API calls

o or a networking question

4. Know some low-level design guidelines and some refactorings: Like 15-Sep section handout.

Sometimes there is no correct answer, so your justification is the important thing: Why.

5. Know synopses of the design patterns we discussed: Adapter, Facade, Composite, Singleton,

Observer, Mediator, Flyweight, Factory Method, State, Strategy, Command, Decorator, Iterator

plus Model-view separation. For example, which pattern defines an interface while retaining

control of which class to instantiate?

6. Write code, interfaces and/or classes for a problem using a Design Pattern that we have not

presented in class or section, from one of these. Bridge Chain of Responsibility, Builder,

Prototype, Visitor.

7. Write code, interfaces and/or classes for a problem using a Design Pattern that we have

presented in class or section: See list above.

8. A question you cannot get wrong unless you leave it blank.

C Sc 335 Practice Final Sample Questions, Fall 2004

1. For each line of code after the long comments, write compile time error or the output the statement

generates

class One { public String toString() { return "one"; } public void methodOne() { System.out.println("aaa"); methodTwo(); } public void methodTwo() { System.out.println("bbb"); } } class Two extends One { public String toString() { return "two/" + super.toString(); } public void methodOne() { System.out.println("ccc"); super.methodOne(); } public void methodTwo() { System.out.println("ddd"); } } class Three extends One { public void methodOne() { System.out.println("eee"); } public void methodThree() { System.out.println("fff"); } } // Initialize some objects One aOne = new One(); One aTwo = new Two(); Two anotherTwo = new Two(); Three aThree = new Three(); //////////////////////////////////////////////////////////// System.out.println(aOne); ///////////////////////////////////////////////////////// /// System.out.println(aTwo); ///////////////////////////////////////////////////////// /// System.out.println(aThree); ///////////////////////////////////////////////////////// /// aOne.methodOne(); ///////////////////////////////////////////////////////// /// aTwo.methodOne(); ///////////////////////////////////////////////////////// /// aThree.methodOne(); ///////////////////////////////////////////////////////// /// aOne.methodTwo(); ///////////////////////////////////////////////////////// /// aTwo.methodTwo(); ///////////////////////////////////////////////////////// /// aThree.methodTwo(); ///////////////////////////////////////////////////////// /// Two obj1 = new One(); ///////////////////////////////////////////////////////// /// aTwo.methodThree(); ///////////////////////////////////////////////////////// /// aOne.methodThree(); ///////////////////////////////////////////////////////// /// One obj2 = (One) aTwo;

2. You are asked to analyze and design an information system for a video rental store. Simplifying

assumptions and details:

You must use the ItemList object as your model (it is already an instance variable in the code below). An

ItemList is a collection of LineItem objects. A LineItem object is the number of items sold and the unit price.

You will need the constructors and methods shown in the following UML diagram. We have a separate handout

with actual code. You do not need to write these ItemList and LineItem classes.

Constraints for this program are as follows (your style will also count):

o The GUI must be laid out to look like the screen shots above

o When the “Enter” button is clicked, a new LineItem object is added to the sale and the subtotal is

updated (do not clear the input areas). Assume there is always valid input for Quantity and Price.

o When the “Show all items” button is clicked a message box appears with the current list if sale

items.

o You will need to the parseInt and parseDouble methods which convert strings to numbers.

Examples:

Double.parseDouble("1.25"); // evaluates to the double value 1.

Integer.parseInt("3"); // evaluates to the integer value 3

// Complete the code on the next page import javax.swing.; import java.awt.; import java.awt.event.*; public class CashRegisterGUI extends JFrame { public static void main(String[] args) { CashRegisterGUI aWindow = new CashRegisterGUI(); aWindow.show(); } private ItemList sale = new ItemList(); // ItemList is the Model private JButton enterButton = new JButton("Enter"); // All three Labels will be right justified when used as initialized here private JLabel quantityLabel = new JLabel("Quantity ", JLabel.RIGHT); private JTextField quantityField = new JTextField(); private JLabel priceLabel = new JLabel("Price ", JLabel.RIGHT); private JTextField priceField = new JTextField(); private JLabel subtotalLabel = new JLabel("Sub total ", JLabel.RIGHT); private JLabel currentTotalLabel = new JLabel("0.00"); private JButton showTotalButton = new JButton("Show all items"); public CashRegisterGUI() { setTitle("Cash Register"); setSize(160, 150); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp = getContentPane();

private class EnterListener implements ActionListener { public void actionPerformed(ActionEvent e) { private class TotalListener implements ActionListener { public void actionPerformed(ActionEvent e) {

4. For each of the following questions, justify you choice: Answer why your choice the better design?

Suggested Readings: The refactoring catalogue http://www.refactoring.com/catalog/index.html Presentation 8 http://www.cs.arizona.edu/classes/cs335/fall04/presentations/08-ObjectRelationships.ppt Section Handout http://www.cs.arizona.edu/classes/cs335/fall04/Misc/SectionRefactorings-Answers.doc

a) Which code is the better design A or B ___ Why?

// A

if (isSpecialDeal())

total = price * 0.95;

send();

else

total = price * 0.98;

send();

// B

if (isSpecialDeal())

total = price * 0.95;

else

total = price * 0.98;

send();

1. Course: Store the course number and units of available courses.

2. RegisteredCourse: Stores a course and a student to represent a list element in the database of

student.

public class Course { private String number; private double units; public Course(String courseNumber, double courseUnits) { number = courseNumber; units = courseUnits; } public double getUnits() { return units; } public String toString() { return number + " " + units; } } ////////////////////////////////////////////////// // A Collection of these are stored in CourseDataBase public class RegisteredCourse { private RegisteringStudent student; private Course course; public RegisteredCourse(RegisteringStudent s, Course c) { student = s; course = c; } public String toString() { return "<" + student.toString() + " " + course.toString() + ">"; } }

You are to completely implement one Observer and one Observable.

RegisteringStudent : The current student who is trying to register. This is the Observable. During an

addCourse message, an instance notifies all observers while passing the course being added. This gives

Observers a reference to the Student object and the Course object.

CourseDataBase : Stores an ArrayList of RegisteredCourse objects. This object gets notified

each time a course is registered. This is an Observer. It must add RegisteredCourse objects to an

ArrayList. whenever it is notified of a change to a RegisteringStudent.

8. A question you cannot get wrong unless you leave it blank.