Java Programming Development Exam Questions PDF

Title Java Programming Development Exam Questions
Course Java Program Development
Institution Aston University
Pages 6
File Size 106.9 KB
File Type PDF
Total Downloads 91
Total Views 139

Summary

Java Programming Development past exam paper. This past paper is highly relevant as lecturers for this module recycle past papers every year as opposed to making a new one, hence this would be a great help for preparing for an exam that will most likely look and have the same questions as this one...


Description

CS1410 Java Program Development

The following is not an example of an old exam; these are questions that have appeared in past exams. Take these questions just as a guide to familiarise yourself with the kind of questions you will need to answer in the Final Exam. The fact that these questions appear in this document does not mean they will appear in the Final Exam. Try to answer the questions. Answers will be published later (before the exam). They idea is that you answer the questions and then you can compare with the answers that will be published. 1. Read the following partial problem specification: The task is to implement a record system for students in Higher Education. Undergraduate and taught postgraduate students take a number of modules which are assessed each year. Research students submit a thesis at the end of their programme and work under the guidance of their supervisor, who is a member of academic staff. The supervisor and thesis title are assigned when they enrol. When a student graduates, their record of achievement contains all their assessment grades. Consider also the following partial implementation of a student class: Beginning of code 1 2 3 4 5

public abstract class Student { protected int id; private static int lastID = 0; protected String firstName; protected String familyName;

6

public Student(String firstName, String familyName) { id = Student.nextID(); this.firstName = firstName; this.familyName = familyName; }

7 8 9 10 11 12

private static int nextID() { return ++lastID; }

13 14 15 16

public String toString() { return firstName + " " + familyName; }

17 18 19 20

// Generate string containing graduation information public abstract String graduate();

21 22 23

} End of code

a) Define the term ‘static field’. Explain how the static field lastID, the constructor, and the method nextID interact to ensure that each Student object that is created has a unique ID. (8 marks) (continued. . . ) 1 OF 6

CS1410 Java Program Development

(Question 1 continued. . . ) b) Define the term ‘abstract method’. What is the role of abstract methods in objectoriented design? (6 marks) c) Explain why making Student an abstract class is appropriate in this context. (3 marks) d) An abstract class cannot be instantiated. Why does Student have a constructor? (3 marks) e) Draw a UML class diagram that documents a design for the three classes (undergraduate, taught postgraduate, and research student). You may assume that Module, Thesis, and AcademicStaff classes are given. Your diagram should include all appropriate fields and methods for the student classes. (8 marks) f) Implement a ResearchStudent class that provides methods for enrolment and graduation. In addition, a toString method should be written. This method should return the student’s name; if the student has enrolled, the supervisor name and thesis title should be added, otherwise a message that the student has not enrolled should be added. (12 marks)

2 OF 6

CS1410 Java Program Development

2. Consider the student record system described in question 1. a) Define the term ‘design pattern’. List THREE benefits of using design patterns. (6 marks) b) Give a definition of the ‘Delegation’ pattern and contrast it with inheritance. (8 marks) c) Research students can act as tutors to lab classes. Assuming that classes Tutor and LabGroup are provided and that Tutor contains a method with the signature Beginning of code 1

public void addGroup(LabGroup l) End of code

write two methods that enable a research student to become a tutor and takes a lab group respectively. You only need to write down the changes needed to the ResearchStudent class that you wrote in question 1. (5 marks) d) Give a definition of the ‘Singleton’ pattern.

(5 marks)

e) In the student record system it has been decided that a class StudentDatabase should conform to the singleton pattern. Write down a skeleton implementation of the class showing how the pattern is implemented. (6 marks)

3 OF 6

CS1410 Java Program Development

3. a) Explain why ‘exceptions’ play an important role in Java file handling. b) Describe the differences between ‘text’ and ‘binary’ files in Java.

(6 marks) (6 marks)

c) Suppose that the student record system of question 1 contains a class StudentDatabase that contains a List of Student objects and a List of AcademicStaff objects. Define ‘object serialisation’ in Java, and explain how it could be used to provide persistent storage for the system. What changes to the classes would be needed to support serialisation? (8 marks) d) Read the following partial implementation of a StudentDatabase class. Beginning of code 1 2 3 4 5

public class StudentDatabase { private List students; private List staff; private String university; } End of code

Write a method writeSystem(String fname) for this class that opens a text file with name fname, writes all the information to the file, and then closes it. The method should print a suitable error message if there are any problems writing the file. You may assume that the classes Student and AcademicStaff have appropriate toString methods. (10 marks)

4 OF 6

CS1410 Java Program Development

4. Although it may sometimes be hard to believe, academic staff are people. With this in mind, a Person interface has been added to the student record system of question 1. Beginning of code 1 2 3 4 5

public interface Person { public String getName(); public boolean isSportsClubMember(); // other methods } End of code

All academic staff are automatically members of the Sports Club, but students have to register to qualify. a) Define the term ‘refactoring’. Why is refactoring sometimes necessary during the implementation process? (4 marks) b) Define THRE E differences between Java interfaces and classes.

(3 marks)

c) Explain how interfaces can be used to create flexible and maintainable systems, using an example from the case studies or the coursework to illustrate your answer. (5 marks) d) Write down the CHANGE S and AD DITIONS to the class Student defined in question 1 that are needed for it to implement the Person interface. Also indicate what changes are required to its subclasses. (10 marks) e) When the programmer starts to implement the getName method for AcademicStaff they find that the method body is the same as for Student. Explain how this design flaw can best be removed, with the help of a UML class diagram. (8 marks)

5 OF 6

CS1410 Java Program Development

5. This question is concerned with system design and development. a) What is a ‘scenario’? What is a ‘CRC’ card? Explain how CRC cards are used in scenario analysis. (7 marks) b) A programmer on your team makes the following statement. “I can’t be bothered writing unit tests: I will just put print statements into my code instead.” Give THRE E reasons why this approach is not as effective as writing tests using the JUnit framework. (6 marks) c) Read the following method defined with the JUnit test library. Explain the effect of lines 1 and 4. (6 marks) Beginning of code 1 2 3 4 5

@Test public void testName() { Student s = new UndergraduateStudent("Fred", "Bloggs"); assertEquals(s1.toString(), "Fred Bloggs"); } End of code

d) Define the four key steps in debugging software.

(6 marks)

e) Explain how binary chop is used to find the source of a bug. Why is it preferred to looking through code line-by-line? (5 marks)

END OF EXAMINATION PAPER

6 OF 6...


Similar Free PDFs