Docsity

Java Programming: Advanced Application Programming Module, Exams of Applications of Computer Sciences

Toggle sidebar
bg1
Semester 2 Examinations 2010/ 2011
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. Thomas 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 the Examination paper.
Section B (80 Marks) Answer Any Two Questions
Duration
3 Hours
No. of Pages
Discipline(s)
Business Information Systems
Course Co-
ordinator(s)
Mr. Seamus Hill
Requirements:
MCQ
Release to Library: Yes No
Handout
Statistical/ Log
Tables
Cambridge Tables
Graph Paper
Log Graph Paper
Other Materials
PTO
X
pf3
pf4
pf5
pf8

Partial preview of the text

Download Java Programming: Advanced Application Programming Module and more Exams Applications of Computer Sciences in PDF only on Docsity!

Semester 2 Examinations 2010/ 2011

Exam Code(s) 1AE1, 1MIS1, 1MIS

Exam(s) Masters of Business Studies in Electronic Commerce

MSc. Information Systems Management full-time

MSc. Information Systems Management part-time

Module Code(s) MS

Module(s) Advanced Application Programming

Paper No.

Repeat Paper

External

Examiner(s)

Dr. Danail Ivanov

Internal

Examiner(s)

Dr. Thomas 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 the Examination paper. Section B (80 Marks) Answer Any Two Questions

Duration 3 Hours

No. of Pages

Discipline(s) Business Information Systems

Course Co-

ordinator(s)

Mr. Seamus Hill

Requirements :

MCQ Release to Library: Yes No

Handout

Statistical/ Log

Tables

Cambridge Tables

Graph Paper

Log Graph Paper

Other Materials

PTO

X

Question 1

1. Which of the following terms is defined as “user-defined set of instructions that are defined

for a class that Java uses to carry out basic tasks”?

a) instance method

b) user-defined method

c) natural method

d) class method

2. How does object declaration differ from object creation?

a) In object declaration space is allocated in memory for the object, while in object

creation, the identifier of the object is set to refer to a space in memory.

b) In object declaration, an identifier is created, while in object creation, the actual

object is created.

c) In object declaration, an identifier of an object is set to refer to a space in memory,

and in object creation, the space in memory is actually created for the object.

d) Other than the fact that the syntax of the two operations differs, they perform the

same function of creating the object.

3. Which of the following variable declarations would generate a compile-time error?

a) int i, j, k;

b) float m = 22.33;

c) long f = 2300, g = 12395;

d) int float x, y;

4. What happens at compile-time if the programmer forgets to include a constructor in the

class definition?

a) The constructor is not necessary, so the compilation carries through regularly.

b) A constructor with a body is automatically generated.

c) An error occurs, complaining about the lack of a constructor method for the class.

d) A default constructor with no arguments and no body is created.

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 public class SummerSale 2 { 3 private String name; 4 private double price; 5 6 public SummerSale( ) 7 { 8 name = "No name yet"; 9 price = 0; 10 } 11 12 public SummerSale(String theName, double thePrice) 13 { 14 setName(theName); 15 setPrice(thePrice); 16 } 17 18 public SummerSale(SummerSale originalObject) 19 { 20 if (originalObject == null) 21 { 22 System.out.println("Error: null Sale object."); 23 System.exit(0); 24 } 25 else 26 name = originalObject.name; 27 price = originalObject.price; 28 } 29 30 public static void announcement( ) 31 { 32 System.out.println("This is the Sale class."); 33 } 34 35 public double getPrice( ) 36 { 37 return price; 38 } 39 40 public void setPrice(double newPrice) 41 { 42 if (newPrice >= 0) 43 price = newPrice; 44 else 45 { 46 System.out.println("Error: Negative price."); 47 System.exit(0); 48 } 49 } 50

Section B (80 Marks) Answer Any TWO Questions

51 public String getName( ) 52 { 53 return name; 54 } 55 56 public void setName(String newName) 57 { 58 if (newName != null && newName != "") 59 name = newName; 60 else 61 { 62 System.out.println("Error: Improper name value."); 63 System.exit(0); 64 } 65 } 66 67 public String toString( ) 68 { 69 return (name + " Price and total cost = €" + price); 70 } 71 72 public double bill( ) 73 { 74 return price; 75 } 76 77 public boolean equalDeals(SummerSale otherSale) 78 { 79 if (otherSale == null) 80 return false; 81 else 82 return (name.equals(otherSale.name) 83 && bill( ) == otherSale.bill( )); 84 } 85 86 public boolean lessThan (SummerSale otherSale) 87 { 88 if (otherSale == null) 89 { 90 System.out.println("Error: null Sale object."); 91 System.exit(0); 92 } 93 else 94 return (bill( ) < otherSale.bill( )); 95 } 96 97 public boolean equals(Object otherObject) 98 { 99 if (otherObject == null) 100 return false; 101 else if (getClass( ) != otherObject.getClass( )) 102 return false; 103 else 104 { 105 SummerSale otherSale = (SummerSale)otherObject; 106 return (name.equals(otherSale.name) 107 && (price == otherSale.price)); 108 } 109 } 110

168 public String toString( ) 169 { 170 return (getName( ) + " Price = €" + getPrice( ) 171 + " Discount = " + discount + "%\n" 172 + " Total cost = €" + bill( )); 173 } 174 175 public boolean equals(Object otherObject) 176 { 177 if (otherObject == null) 178 return false; 179 else if (getClass( ) != otherObject.getClass( )) 180 return false; 181 else 182 { 183 SummerDiscountSale otherDiscountSale = 184 (SummerDiscountSale)otherObject; 185 return (super.equals(otherDiscountSale) 186 && discount == otherDiscountSale.discount); 187 } 188 } 189 190 public SummerDiscountSale clone( ) 191 { 192 return new SummerDiscountSale(this ); 193 } 194 } 195 196 public class SummerDemo 197 { 198 public static void main(String[] args) 199 { 200 SummerSale simple = new SummerSale("floor mat", 10.00); 201 SummerDiscountSale discount = new SummerDiscountSale("floor mat", 11.00, 10); 202 System.out.println(simple); 203 System.out.println(discount); 204 205 if (discount.lessThan(simple)) 206 System.out.println("Discounted item is cheaper."); 207 else 208 System.out.println("Discounted item is not cheaper."); 209 210 SummerSale regularPrice = new SummerSale("cup holder", 9.90); 211 SummerDiscountSale specialPrice = new SummerDiscountSale("cup holder", 11.00, 10); 212 System.out.println(regularPrice); 213 System.out.println(specialPrice); 214 215 if (specialPrice.equalDeals(regularPrice)) 216 System.out.println("Deals are equal."); 217 else 218 System.out.println("Deals are not equal."); 219 } 220 } 221

Question 3.

i. Describe using examples the concept of Polymorophism.

(Marks 10)

ii. Write an java application that keeps track of a student’s food purchases at the

campus cafeteria. Your application should contain a used defined package which

will contain two classes, MealCard and Student. The MealCard class will keep track

of the students points, which should initially be set to 100 points. Points assigned to

each food item are a whole number. A student can purchase additional points at

anytime during the semester. Every time food is purchased, points are deducted

from the balance. If the balance becomes negative the purchase of food items is not

allowed. The Student class should record a student’s name, their age and their

address, both the name and address can be recorded as a single string for simplicity.

You are also required to write a program to test the MealCard class.

(Marks 30)

Question 4.

i. Java interface and inheritance are language features used to support object-oriented

modelling –

Discuss the above statement and compare and contrast the Java Interface with

inheritance as it relates to Java, using examples where appropriate.

(Marks 20)

ii. Describe each of the following concepts as they relate to Java, using examples to

illustrate your answers.

a) Abstract superclass

b) Abstract method

c) implemented method

d) Inherited Visibility modifiers

(Marks 20)