



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Objects and Classes, Programming, Standard Classes, Programmer Defined Classes, Strict Formatting Regulations, Automatically after Compilation, Level of Fuel, Public Void Getsize, Static Void Getsize, Access Modifier are points of Advanced Applications Programming course exam.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




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 the Examination paper. Section B (80 Marks) Answer Any Two Questions
Question 1
a) objects and programming b) objects and orientation c) objects and classes d) objects and inheritance
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.
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.
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.
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);
Section A (20 Marks) Attempt all 10 questions Mark your answers on the MCQ sheet provided
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
Section B (80 Marks) Answer Any TWO Questions
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 {
Question 3.
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. (Marks 10)
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.
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.
(Marks 30)
a) Polymorphism makes possible smooth and easy extension and modification of
a program
Discuss the above statement using examples to illustrate your answer.
(Marks 20)
b) Describe each of the following concepts as they relate to Java, using examples to illustrate your answers.
i. Polymorphic messages
ii. Inheritance and visibility modifiers
iii. Inheritance versus Interface
iv. Inheritance and constructors
(Marks 20)