Вы находитесь на странице: 1из 7

UG 20.

01: Introduction to Computers and Programming Asian Institute of Technology Final Examination

November 2009 Information and Communication Technology Instructor: Matthew Dailey

Final Examination
Instructions
1. This examination is open book, open notes, open laptop, open Internet. 2. You may not consult with any living human being during the exam. 3. Write your name on every page. 4. Read each question carefully before answering. Ask the instructor if anything seems ambiguous. 5. Note that there are 2 types of questions on this exam: Hacking and Short Answer. You must write your answers to the short answer questions directly on the exam sheet and turn the sheet in at the end of the exam. You must develop your solutions to the hacking questions on your computer and then demonstrate your solutions to the instructor at the end of the exam. 6. You have 3 hours to complete the examination. Use your time wisely. 7. You must STOP WORKING and step away from your computer when I call time. Please wait patiently for your your turn to demonstrate your solutions to the Hacking questions. 8. Be sure to set up your demonstration before the end of the exam time. You will only have 3 minutes to demonstrate your code to me.

Name:
Question 1 2 3 4 5 6 Total Point Value 10 10 10 30 30 10 100

ID #:
Points

Name:
Question 1 [SHORT ANSWER, 10 points, 15 minutes]
We know that the code BankAccount account1 = new BankAccount(...); ... BankAccount account2 = account1; will result in two references, account1 and account2, to the same BankAccount object. Suppose I want account2 to refer to a copy of the BankAccount object referred to by account1 (instead of just referring to the same object). Explain precisely what I have to do (Hint: your answer involves Object.clone).

Name:
Question 2 [SHORT ANSWER, 10 points, 15 minutes]
Consider the code: String hello = "Hello World!"; hello.toUpperCase(); System.out.println("Upper case result: " + hello); I expected the result Upper case result: HELLO WORLD! but instead I got the result Upper case result: Hello World! In the space below, explain why I did not get the result I expect and how I can x the problem.

Name:
Question 3 [SHORT ANSWER, 10 points, 15 minutes]
Suppose I would like my BankAccount class to keep track of all the objects of type BankAccount that have been created. I would like to have the BankAccount constructor add each new BankAccount object to a static ArrayList of BankAccount objects then to provide a static method numberOfAccounts that returns the length of the list. Write the denition of the static array list I should add to my BankAccount class:

Write the numberOfAccounts method below:

Write the snippet of code I should use in the BankAccount constructor to add the newly constructed BankAccount object to the array list:

Name:
Question 4 [HACKING, 30 points, 60 minutes]
Suppose we want to know who is the best teacher at AIT. We arrange student evaluations of all the professors and create a text le like this containing the evaluation scores and professor names: 3.0 2.4 2.9 2.0 4.0 4.9 1.1 2.5 Peter Haddawy Vilas Wuwongse Sumanta Guha Paul Janecek Phan Minh Dung Vatcharaporn Esichaikul Matthew Dailey Kanchana Kanchanasut

We would like to write a program to read les like this and create a list of professors sorted by their evaluation scores, with the highest score coming rst in the list. Design a set of classes to solve this problem. Your design should include a JUnit test class whose responsibility is to run your list sorting code on a known le and check the correctness of the ordering of the professors. Draw a UML diagram of the particpating classes here:

Provide the method signatures and instance eld denitions for each of the classes here:

Implement your design and demonstrate the result of the JUnit test to the instructor.

Name:
Question 5 [HACKING, 30 points, 30 minutes]
Add a GUI to the program you developed in the previous question. The GUI should include a customized subclass of JFrame and should create a window similar to this:

The program should let the user type a le name into the text box, and when the user clicks Read File, the program should invoke the professor sorter class you created for the previous question and display the results in the text area, as shown. Provide a UML diagram of the participating classes here:

Implement your design and demonstrate to the instructor.

Name:
Question 6 [SHORT ANSWER, 10 points, 15 minutes]
Consider the CheckingAccount class from Chapter 10, which extends the BankAccount class developed in previous chapters. Suppose I write code that does the following: 1. Create an instance of CheckingAccount with an initial balance of 200 baht. 2. Deposit 1000 baht into the account. 3. Withdraw 500 baht from the account. 4. Deduct fees at the end of the month. Describe below the sequence of constructors and methods that get called and object state changes that occur for each of these steps. Be clear about the sequence of method calls for both the child (CheckingAccount) and parent (BankAccount) classes.

Вам также может понравиться