




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
Information about an exam for the masters of business studies in electronic commerce, msc. Information systems management full-time and part-time programs, focusing on the module 'advanced application programming'. The exam includes multiple-choice questions and essay-style questions, covering topics such as polymorphism, inheritance, arrays, constructors, and classes. Candidates are required to answer all questions in section a and any two questions in section b. The document also includes instructions for the exam, such as duration and materials required.
Typology: Exams
1 / 8
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
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 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
Section B (80 Marks) Answer Any TWO Questions
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
Question 3.
ii. 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: € 763.
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