





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






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
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
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);
Number of bags sold: 25 Weight per bag: 5 Price per pound: €5. Sales tax: 10.0%
Total price: € 7 63.