Objects and Programming - Advanced Applications Programming - Exam, Past Exams for Applications of Computer Sciences
divye
divye

Objects and Programming - Advanced Applications Programming - Exam, Past Exams for Applications of Computer Sciences

9 pages
1Number of download
963Number of visits
Description
Objects and Programming, Strict Formatting Regulations, Built into Java, Automatically, Speedometer, Furniturestore, Public int Getsize, Polymorphism, Inheritance, Encapsulation are points of Advanced Applications Progra...
20 points
Download points needed to download
this document
Download the document
Preview3 pages / 9
This is only a preview
3 shown on 9 pages
Download the document
This is only a preview
3 shown on 9 pages
Download the document
This is only a preview
3 shown on 9 pages
Download the document
This is only a preview
3 shown on 9 pages
Download the document
Microsoft Word - MS815 Autumn 2010.doc

Autumn Examinations 2010

Exam Code(s) 1AE1, 1MIS1, 1MIS2 Exam(s) Masters of Business Studies in Electronic Commerce

MSc. Information Systems Management full-time MSc. Information Systems Management part-time

Module Code(s) MS815 Module(s) Advanced Application Programming Paper No. Repeat Paper External Examiner(s) Dr. Danail Ivanov Internal Examiner(s) Dr. Tom Acton

Mr. Seamus Hill Instructions:

Candidates are required to answer: Section A (20 Marks) Answer all 10 parts of section A, This section consists of 10 multiple-choice questions all of which should ideally be attempted. Answers are to be written on the MCQ sheet provided, NOT on theExamination paper.Section B (80 Marks) Answer Any Two Questions

Duration 2 hrs Department(s) Accountancy & Finance Course Co-ordinator(s)Requirements: MCQ Yes, Type a-d 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Section A (20 Marks)

Attempt all 10 questions Mark your answers on the MCQ sheet provided

1)What are the two most important concepts in object-oriented programming?

a) objects and programming b) objects and orientation c) objects and classes d) objects and inheritance

2) What is the difference between programmer-defined classes and standard classes?

a) Programmer-defined classes are always written after standard classes. b) Programmer-defined classes can be named anything the user chooses, while

standard classes have strict formatting regulations. c) Programmer-defined classes are written by the programmer, while standard

classes are built into Java. d) Programmer-defined classes are written by the programmer, while standard

classes are created automatically after compilation. 3) When an array is passed to a method ________________.

a) only the reference is passed, and a copy of the array is not created in the method.

b) a copy of the array is created within the method. c) the value of the array is passed into the method. d) None of the above.

4) We are writing a program to model the behavior of a car. Which of the following is a valid candidate to be represented with a constant as opposed to a variable?

a) The level of fuel in the gas tank. b) The maximum speed that the speedometer can read. c) The number represented by the car’s odometer. d) The number of miles to the next oil change.

5) Assume a program uses a Class, FurnitureStore, which contains a method called “getSize” that is used as follows:

FurnitureStore fs = new FurnitureStore(30, “LazyBoy”); int size = fs.getSize();

Which of the following is the prototype for the getSize method?

a) public void getSize(int); b) public static void getSize(); c) public int getSize(); d) public int getSize(int);

6) The practice of hiding the details from the user of what goes on inside of an Object is known as ____________.

a) polymorphism b) inheritance c) encapsulation d) access modification

7) What is meant by “returning an object” from a method?

a) It means you are returning a null value to the caller. b) It means returning a primitive type to the caller. c) It means returning the object’s address to the caller. d) It means returning the object’s value to the caller.

8) Suppose we wish to write a program that will continually prompt for a number from the user until the input variable, “number” is greater than 10. What will the while loop look like?

a) while (number > 10) number = Integer.parseInt(JOptionPane.showInputDialog(null, “Enter a number”));

b) while (number > 10){ number = Integer.parseInt(JOptionPane.showInputDialog(null, “Enter a number”)); number ++; }

c) while (number <= 10){ number = Integer.parseInt(JOptionPane.showInputDialog(null, “Enter a number”)); number ++; }

d) while (number <= 10) number = Integer.parseInt(JOptionPane.showInputDialog(null, “Enter a number”));

9) Which of the following is not a Boolean operator?

a) && b) ! c) || d) ++

10) What is the difference between the Error class and the Exception class?

a) There are no differences between the two classes. b) Error classes represent a different set of problems that should be caught than

Exception classes do. c) Error classes represent serious problems that should not be caught, while

Exceptions represent problems that should be caught. d) Error classes represent problems that should be caught, while Exceptions

represent problems that should not be caught.

(20 MARKS)

Section B (80 Marks)

Answer Any TWO Questions Question 2 Review the following application and explain the purpose of the application and how it works. Explain in detail, the purpose of each the classes and the workings of their methods, using the line numbers for reference. 1 import javax.swing.*; 2 3 class HiLo { 4 5 private final int MAX_GUESS_ALLOWED = 6; 6 7 private final int LOWER_BOUND = 1; 8 9 private final int UPPER_BOUND = 100; 10 11 private int secretNumber; 12 13 public HiLo( ) { 14 15 } 16 17 public static void main (String[] args) { 18 HiLo hiLo = new HiLo( ); 19 hiLo.start(); 20 } 21 22 public void start ( ) { 23 int answer; 24 25 answer = prompt("Do you want to play a Hi-Lo game?"); 26 27 while (answer == JOptionPane.YES_OPTION) { 28 29 generateSecretNumber( ); 30 31 playGame(); 32 33 answer = prompt("Do you want to play another Hi-Lo game?"); 34 } 35 } 36

37 private void generateSecretNumber( ) { 38 39 double X = Math.random(); 40 41 secretNumber = (int) Math.floor(X*100) + 1; 42 43 System.out.println("Secret Number: " + secretNumber); //TEMP 44 } 45 46 private int getNextGuess( ) { 47 48 String inputStr; 49 int input; 50 51 while (true) { 52 inputStr = JOptionPane.showInputDialog(null,"Next Guess"); 53 input = Integer.parseInt(inputStr); 54 55 if (LOWER_BOUND <= input && input <= UPPER_BOUND) { 56 return input; 57 } 58 59 JOptionPane.showMessageDialog(null, "Invalid Input: " + 60 "Must be between " + LOWER_BOUND + 61 "and " + UPPER_BOUND); 62 } 63 } 64 65 private void playGame( ) { 66 67 int guessCount = 0; 68 int guess; 69 70 do { 71 guess = getNextGuess(); 72 73 guessCount++; 74 75 if (guess < secretNumber) { 76 77 JOptionPane.showMessageDialog(null, "Your guess is LO"); 78 79 } else if (guess > secretNumber) { 80 81 JOptionPane.showMessageDialog(null, "Your guess is HI"); 82 } 83 84 } while ( guessCount < MAX_GUESS_ALLOWED && 85 guess != secretNumber ); 86 87 if ( guess == secretNumber ) { 88 89 JOptionPane.showMessageDialog(null, "You guessed it in " 90 + guessCount + " tries."); 91 } else {

92 93 JOptionPane.showMessageDialog(null, "You lost. Secret No. was " 94 + secretNumber); 95 } 96 } 97 98 private int prompt(String question) { 99 100 int reply; 101 102 reply = JOptionPane.showConfirmDialog(null, 103 question, 104 "Confirmmation", 105 JOptionPane.YES_NO_OPTION); 106 return reply; 107 } 108 109 } 110

(40 Marks)

Question 3 Part a)

Complete the first four constructors of the following class. Each of the four constructors calls the fifth one by using the reserved word this. class Cat {

private static final String DEFAULT_NAME = "No name"; private static final int DEFAULT_HGT = 6; private static final double DEFAULT_WGT = 10.0; private String name; private int height; private double weight;

public Cat( ) {

//assign defaults to all data members }

public Cat(String name) {

//assign the passed name to the data member //use defaults for height and weight

} public Cat(String name, int height) {

//assign passed values to name and height //use default for weight

} public Cat(String name, double weight) {

//assign passed values to name and weight //use default for height

} public Cat(String name, int height, double weight){

this.name = name; this.height = height; this.weight = weight;

} . . . }

(10 Marks)

Continued ...

Part b)

Write a program that displays the recommended weight, given the user’s age and height. The formula for calculating the recommended weight is; recommendedWeight = (height – 100 + age / 10) * 0.90 Define a service class named Height and include an appropriate method for getting a recommended weight of a designated height.

Your program should include a programmer defined class Height and a main class WeightRecommender Use JOptionPane to get age and height input from the use.

(30 Marks) Question 4 Part a)

In relation to object-oriented programming with JAVA, detail your understanding, using examples/analogies where appropriate, of each of the following:

i. Exception thrower, ii. Exception Catcher

iii. Exception Propagator iv. Checked exception.

(20 Marks) Part b)

In relation to the visibility of data members, discuss the effects of the modifiers protected, public and private, using examples where appropriate.

(8 Marks)

Part c)

Briefly discuss, using examples/analogies where appropriate, the following statement - 


If a class has a superclass that is not the Object class, then include an explicit call to a constructor of the superclass in the constructor of the class. 


(12 Marks) 



no comments were posted
This is only a preview
3 shown on 9 pages
Download the document