Docsity

Java Program - Interactive Programming - Exam, Exams of Management Information Systems

Toggle sidebar
bg1
Semester II Examinations 2008/ 2009
Exam Code(s)
1AE1, 1BD1, 1BD3
Exam(s)
Masters of Business Studies in Electronic Commerce
Higher Diploma in Systems Analysis full-time
Higher Diploma in Systems Analysis part-time
Module Code(s)
MS841
Module(s)
Interactive Programming II
Paper No.
Repeat Paper
External Examiner(s)
Professor H. van der Heijden
Internal Examiner(s)
Professor J. F. Collins
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
Department(s)
Course Co-ordinator(s)
Requirements:
MCQ
Yes, Type a-d
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Java Program - Interactive Programming - Exam and more Exams Management Information Systems in PDF only on Docsity!

Semester II Examinations 2008/ 2009

Exam Code(s) 1AE1, 1 BD1, 1 BD Exam(s) (^) Masters of Business Studies in Electronic Commerce Higher Diploma in Systems Analysis full-time Higher Diploma in Systems Analysis part-time

Module Code(s) (^) MS84 1 Module(s) Interactive Programming II

Paper No. Repeat Paper

External Examiner(s) Professor H. van der Heijden Internal Examiner(s) Professor J. F. Collins 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 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) Polymorphism allows us to _____________.

a) have the same message execute a different method depending on the

receiving object

b) hide the internal workings of a Java program from the client programmer

c) overload methods and allow the same method name to be used multiple

times

d) extend and modify code

2) How would the three classes, Undergraduate, Graduate, and Student interrelate if we

are determined to use inheritance in the class definitions?

a) Student would be a subclass of Undergraduate, which would be a subclass of

Graduate.

b) Graduate would be a subclass of Undergraduate, which would be a subclass

of Student.

c) Graduate would be a subclass of Student, and Undergraduate would be a

subclass of Graduate.

d) Undergraduate and Graduate would both be subclasses of Student.

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) A(n) ______________ has a method prototype but no body.

a) default constructor

b) default method

c) concrete method

d) abstract method

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 class Person { 2 private String name; 3 4 private int age; 5 6 private char gender; 7 8 public Person() { 9 this ("Not Given", 0, 'U'); 10 } 11 12 public Person(String name, int age, char gender) { 13 this .age = age; 14 this .name = name; 15 this .gender = gender; 16 } 17 18 public int getAge( ) { 19 return age; 20 } 21 22 public char getGender( ) { 23 return gender; 24 } 25 26 public String getName( ) { 27 return name; 28 } 29 30 public void setAge( int age ) { 31 this .age = age; 32 } 33 34 public void setGender( char gender ) { 35 this .gender = gender; 36 } 37 38 public void setName( String name ) { 39 this .name = name; 40 } 41 42 } 43 44 45

47 class AddressBook { 48 49 private static final int DEFAULT_SIZE = 25; 50 51 private static final int NOT_FOUND = -1; 52 53 private Person[] entry; 54 55 private int count; 56 57 public AddressBook( ) { 58 this ( DEFAULT_SIZE ); 59 } 60 61 public AddressBook( int size ){ 62 if (size <= 0 ) { 63 throw new IllegalArgumentException("Size must be positive."); 64 } 65 66 entry = new Person[size]; 67 68 } 69 70 public void add( Person newPerson ) { 71 72 assert count >= 0 && count <= entry.length; 73 74 if (count == entry.length) { 75 enlarge( ); 76 } 77 78 entry[count] = newPerson; 79 count++; 80 } 81 82 public boolean delete( String searchName ) 83 { 84 boolean status; 85 int loc; 86 87 loc = findIndex( searchName ); 88 89 if (loc == NOT_FOUND) { 90 status = false ; 91 } else { 92 93 entry[loc] = entry[count-1]; 94 95 status = true ; 96 count--; 97 98 assert count >= 0 && count <= entry.length; 99 } 100 101 return status; 102 } 103

160 class TestAddressBook { 161 162 AddressBook myBook; 163 Person person; 164 165 public static void main ( String[] args ) { 166 TestAddressBook tester = new TestAddressBook(); 167 tester.setupArray( 5 ); 168 tester.testDelete( ); 169 } 170 171 public void setupArray( int N ) { 172 myBook = new AddressBook( N ); 173 174 for ( int i = 0; i < N; i++) { 175 person = new Person( "Ms. X" + i, 10, 'F' ); 176 myBook.add( person ); 177 } 178 } 179 180 public void testDelete( ) { 181 182 person = myBook.search( "Ms. X2" ); 183 184 if ( person == null ) { 185 System.out.println( "Error: Didn’t find the person it should" ); 186 } else { 187 System.out.println( person.getName() + " is found okay." ); 188 189 boolean success = myBook.delete("Ms. X2" ); 190 191 if ( success ) { 192 193 person = myBook.search( "Ms. X2" ); 194 195 if (person == null ) { 196 197 System.out.println( "Okay: Deletion works" ); 198 } else { 199 200 System.out.println( "Error: Person is still there" ); 201 } 202 } else { 203 204 System.out.println( "Error: Deletion has a problem" ); 205 } 206 } 207 } 208 } 209

(40 Marks)

Question 3

Part a)

Given the class Tester, illustrate how the pass-by-value scheme works for the code

segment given. Your answer should include a state of memory diagram to show the flow

of execution and allocation and deallocation of memory.

public class Tester { public void myMethod( int one, double two){ one = 25; two = 35.4; } }

Tester tester; int x,y;

tester = new Tester(); x = 10; y = 20; tester.myMethod(x,y); System.out.println(x + " " + y);

(10 Marks)

Part b)

Write a program that accepts the unit of weight of a bag of coffee in pounds and the

number of bags sold and display the total price of the sale, compute as follows:

totalPrice = bagWeight * numberOfBags * pricePerLb;

totalPriceWithTax = totalPrice + totalPrice * taxRate;

Display the results in the following manner:

Number of bags sold: 25 Weight per bag: 5 Price per pound: €5. Sales tax: 10.0%

Total price: € 7 63.

Define and use a programmer-defined CoffeeBag class. Include class constants for the

price per pound and tax rate with the value of €5.55 per pound and 10% respectively.

(30 Marks)