Faculteit der Exacte Wetenschappen Tentamen Inleiding Programmeren Vrije Universiteit 29 januari 1999 tijdsduur : 3 uur ------------------------------------------------------------------------------- U I T W E R K I N G E N ======================= Opgave 1. a) static final double VRIESPUNT_WATER = 0.0; // graden Celcius static final int MAX_GEWICHT_BAGAGE = 20; // kilogram static final char SCHEIDINGSTEKEN = ';' static final String VRAAG = "Zei men: \"OK\"?"; b) double omtrek (double r) { return 2 * Math.PI * r; } c) double benaderPi (int aantaltermen) { double factor = 0.0; int teken = 1, noemer = 1; for (int i = 0; i < aantalTermen; i++) { factor += teken * 1.0/noemer; teken = -teken; noemer += 2; } return 4 * factor; } d) static final int AANTAL_RIJEN = 5; static final int AANTAL_KOLOMMEN = 8; int[][] matrix = new int [AANTAL_RIJEN][AANTAL_KOLOMMEN]; boolean positiefMatrix (int[][] m) { int aantalPositieveGetallen = 0, aantalNegatieveGetallen = 0; for (int i = 0; i < AANTALRIJEN; i++) { for (int j = 0; j < AANTAL_KOLOMMEN; j++) { if (m[i][j] > 0) { aantalPotitieveGetallen += 1; } else if (m[i][j] < 0) { aantalNegatieveGetallen += 1; } } } return aantalPositieveGetallen > aantalNegatieveGetallen; } e) 12 10 2 8 36 24 36 4 Opgave 2. a) Boek() { titel = ""; aantalBladzijden = 0; } b) Boek(String titel, int aantalBladzijden) { this.titel = titel; this.aantalBladzijden = aantalBladzijden; } Iets als het volgende (om het gebruik van this te vermijden) kan ook Boek(String boekTitel, int aantal) { titel = boekTitel; aantalBladzijden = aantal; } c) class Bibliotheek { static final int MAX_AANTAL_BOEKEN = 50000; Boek boekenArray[]; int aantalBoeken; Bibliotheek () { boekenArray = new Boek[MAX_AANTAL_BOEKEN]; aantalBoeken = 0; } void voegToe(Boek boek) { boekenArray[aantalBoeken] = boek; aantalBoeken += 1; } } d) // in de class Boek static final int NOVELLE_GRENS = 40; boolean novelle() { return aantalBladzijden < NOVELLE_GRENS; } // in de class Bibliotheek int aantalNovelles() { int resultaat = 0; for (int i=0; i