5 Pages

sollab5

Course: CSI ITI1520, Spring 2010
School: University of Ottawa
Rating:
 
 
 
 
 

Word Count: 1232

Document Preview

1521. ITI Introduction linformatique II Laboratoire 5 Hiver 2010 Objectifs Bien comprendre tous les aspects des interfaces Introduction limplmentation et lutilisation des piles Revu des concepts dhritage Premire partie Interfaces 1 Combination Revisitons la classe Combination cre lors du premier laboratoire. Eectuez tous les changements ncessaires an que la classe Combination (voir ci-bas) ralise linterface...

Register Now

Unformatted Document Excerpt

Coursehero >> Canada >> University of Ottawa >> CSI ITI1520

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
1521. ITI Introduction linformatique II Laboratoire 5 Hiver 2010 Objectifs Bien comprendre tous les aspects des interfaces Introduction limplmentation et lutilisation des piles Revu des concepts dhritage Premire partie Interfaces 1 Combination Revisitons la classe Combination cre lors du premier laboratoire. Eectuez tous les changements ncessaires an que la classe Combination (voir ci-bas) ralise linterface java.lang.Comparable. public interface Comparable<E> { // // // // // Compare cet objet et celui pass en paramtre afin den dterminer lordre. Retourne une valeur ngative, zro ou positive selon que cet objet est plus petit, gal ou plus grand que lobjet spcifi. public int compareTo( E obj ); } La comparaison de deux objets Combinaison se fait comme suit. On vrie dabord la premire paire de nombres, si la valeur pour cet objet est plus petite que celle de lautre on retourne -1, si elle est plus grande on retourne 1, sinon, il faut regarder la seconde paire de nombres, on retournera -1 ou 1, selon que le deuxime nombre de cet objet es plus petit ou plus grand que celui de lautre objet, si les deux nombres sont gaux, il faut alors considrer la troisime paire de nombres. Vous devez aussi concevoir un programme an de valider la mthode compareTo, tchez dtre aussi exhaustif que possible. Fichier : Combination.java 1 Deuxime partie Piles Introduction Ce devoir porte sur lune des trois implmentations de linterface Stack, ainsi quune application des piles. 2 Modier linterface Stack : ajout dune mthode clear() Modiez linterface Stack ci-bas an dy ajouter la mthode abstraite public void clear(). public interface Stack<E> { public abstract boolean isEmpty(); public abstract E peek(); public abstract E pop(); public abstract void push( E element ); } Fichier : Stack.java 3 Implmenter la mthode clear() de la classe ArrayStack La classe ArrayStack utilise un tableau de taille xe et ralise linterface Stack. Puisque linterface Stack a t modie an dy ajouter la mthode clear(), limplmentation de la classe ArrayStack est dfectueuse (essayez dabord de la compiler sans y apporter de changement, quel message derreur est ach lcran ?). Puisque la classe ArrayStack ralise linterface Stack, elle doit fournir une implmentation pour toutes les mthodes de linterface. Ainsi, vous devez crire une mthode void clear(). Cette dernire retire tous les lments de cette pile (ArrayStack). La pile sera vide suite cet appel. Fichiers : ArrayStack.java L4Q2.java 4 Algo1 Pour cette partie du laboratoire, il y a deux algorithmes pour la validation dexpressions contenant des parenthses (rondes, frises et carres). La classe Balanced ci-bas prsente un algorithme simple pour valider des expressions. On remarque quune expression bien forme est telle que pour chaque type de parenthses (les rondes, les frises et les carres), le nombre de parenthses ouvrantes est gal au nombre de parenthses fermantes. Do lalgorithme suivant : public static boolean algo1( String s ) { int curly = 0; int square = 0; int round = 0; 2 for ( int i=0; i<s.length(); i++ ) { char c = s.charAt( i ); switch ( c ) { case {: curly++; break; case }: curly--; break; case [: square++; break; case ]: square--; break; case (: round++; break; case ): round--; } } return curly == 0 && square == 0 && round == 0; } Compilez ce programme et exprimentez. assurez-vous Dabord, quil fonctionne pour des expressions valides, telles que ()[](), ([][()]). Vous remarquerez que lalgorithme fonctionne aussi pour des expressions qui contiennent des oprandes et des oprateurs : (4 * (7 - 2)). Ensuite, vous devez trouvez des expressions pour lesquelles lalgorithme retourne true bien que ces expressions ne sont pas bien formes. Fichier Balanced.java 5 Algo2 Vous avez trouv des expressions qui font chec cet algorithme. Trs bien ! En eet, une expression bien forme est une expression telle que le nombre de parenthses ouvrantes et fermantes est le mme, et ce, pour chaque type de parenthses. Mais aussi, lorsquon lit une telle expression de gauche droite et que lon rencontre une parenthse fermante alors son type doit tre le mme que celui de la dernire parenthse ouvrante rencontre qui na pas encore t traite. Vous devez implmenter un algorithme base de pile an de valider des expressions : retourne true si lexpression est bien forme et false sinon. De plus, lanalyse ne devrait parcourir la chane quune seule fois. Vous devez crer votre implmentation dans la class Balanced, nommez cette mthode algo2. (Ma solution a 15 lignes) Faites plusieurs tests laide dexpressions valides et non valides. Assurez-vous que votre algorithme traite ce cas-ci : ((()) ? Comment traitez-vous ce cas-ci ? 3 Troisime partie Revue : hritage Le diagramme UML ci-bas prsente une hirarchie de classes an de reprsenter des codes postaux de divers pays. Sachant que, Tous les codes postaux ont une mthode getCode retournant le code (de type String) reprsent par cette instance ; Tous les codes postaux ont une mthode isValid retournant true si le code de cette instance est valide, et false sinon ; Un code postal canadien est valide si les positions 0, 2 et 5 sont occupes par des lettres, les positions 1, 4 et 6 sont des chires, et la position 3 est un caractre blanc ; Un code postal amricain (Zip code) valide est consistitu de deux lettres, suivies dun espace blanc, suivi de 5 chires. 1. Concevoir une implmentation pour les classes PostalCode, CanadianPostalCode et USZipCode. Assurezvous dy include les variables dinstance, ainsi que les constructeurs. Lappendice A prsente un rsum des mthodes des classes String et Character. 2. Crez une classe test pour classes ci-haut. Dclarez un tableau, nomm codes, pouvant contenir 100 codes postaux ; Crez n = 10 codes postaux dont certains sont des codes amricains alors que dautres seront des codes canadiens. De mme, certains codes sont valides et dautres pas. Finalement, sauvegardez ces codes dans les n premires cellules de gauche du tableau ; Sachant quexactement n codes postaux se trouvent dans la partie gauche du tableau, crivez une boucle for an de compter le nombre de codes valides. 4 A Appendix La classe String contient les mthodes suivantes. char charAt(int pos) : retourne le caractre se trouvant la position spcie par lindex pos ; int length() : retourne la longueur de cette chane. La classe Character contient les mthodes suivantes. static boolean isDigit(char ch) : dtermine si le caractre pass en paramtre est un nombre ; static boolean isLetter(char ch) : dtermine si le caractre pass en paramtre est une lettre ; static boolean isWhitespace(char ch) : dtermine si le caractre pass en paramtre est un espace blanc. Modi le : 6 fvrier 2010 5
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Ottawa - CSI - ITI1520
ITI 1521. Introduction linformatique IILaboratoire 6 Hiver 2010Plan Introduction aux interfaces graphiques usager (GUIs) Exercices lis aux interfaces graphiques Les solutions sont incluses dans ce document, faites de srieux eorts avant de consulter les
Delaware - MATH - 201
COMP/MATH 3804 Design and Analysis of Algorithms I Assignment 2Due June 3 at the beginning of classWrite down your name and student number on every page. The questions must be answered in order and your assignment sheets must be stapled. Late assignment
Delaware - MATH - 201
Spring 2010 MATH 4320: Final Exam Instructor: Yuri Berest The exam is due 6 pm, Thursday, May 20. Please turn in your exam in 439 Mallot Hall. Problem 1. (35 points) Let A be a commutative ring with 1. a. An element a A is called nilpotent if an = 0 for s
Delaware - MATH - 201
Spring 2010 MATH 4320: Solutions to Prelim 2 Instructor: Yuri Berest Problem 1. (a) This is straightforward: for example, we have 1 [(x1 , x2 ) (y1 , y2 )] = 1 [(x1 y1 , x2 y2 )] = x1 y1 = 1 [(x1 , x2 )] 1 [(y1 , y2 )] , and similarly for 2 . Both 1 and 2
Delaware - MATH - 201
Spring 2010 MATH 4320: Prelim 2 Instructor: Yuri Berest The exam is due Wednesday, April 14. Please write clearly and concisely. Problem 1. (15 points) If H1 and H2 are two groups, dene their direct product H1 H2 to be the set of ordered pairs cfw_(x1 , x
Delaware - MATH - 201
Spring 2010 MATH 4320: Prelim 1 Instructor: Yuri BerestProblem 1. (15 points) a. Find all integer solutions to the congruence 72x 36 (mod 376) . b. Find the smallest positive integer which leaves remainders 1, 3, 4 after dividing by 9, 7, 5 respectively.
Delaware - MATH - 201
Delaware - MATH - 201
Spring 2010 MATH 4320: Solutions to Prelim 1 Instructor: Yuri Berest Problem 1. a. Solving the congruence 72x 36 (mod 376) is equivalent to solving the equation 72x + 376y = 36 . Now, using Euclids algorithm, we compute (72, 376) = 8 . Since 8 does not di
Delaware - MATH - 201
Math 480HOMEWORK solutions #3W1. Find all integer solutions of the equation 2x + 3y = 11 Answer. (1 + 3t, 3 2t), t Z. W2. (a) For which n is it possible to simplify the fraction39n+8 ? 65n+1339n+8 Solution. The fraction 65n+13 is reducible if and only
Delaware - MATH - 201
Rensselaer Polytechnic Institute - PHIL - 77777
julia kristevapsychoanalysis and modernitysara beardsworthJulia KristevaSUNY series in Gender Theory Tina Chanter, editorJ U L I A K R I S T E VAPsychoanalysis and ModernitySara BeardsworthSTATE UNIVERSITY OF NEW YORK PRESSPublished by State Univ
Rensselaer Polytechnic Institute - PHIL - 7777
1Copyright Jonathan Bennett [Brackets] enclose editorial explanations. Small dots enclose material that has been added, but can be read as though it were part of the original text. Occasional bullets, and also indenting of passages that are not quotation
University of Phoenix - MATH - math115
Name: Crystal Reilly Date: 4-22-2010MAT115Test 1 Chapters 1 and 2 25 problems 4 points each 100 points possible Solve all problems and attach your solutions document in your Individual Forum (IF). Remember to show all steps and check your work carefully
University of Phoenix - MATH - math 115
MAT115Test 2 Chapters 3 and 4 25 problems 4 points each 100 points possible Name: Crystal Reilly Date:_5-8-10 Solve all problems and attach your solutions document in your Individual Forum (IF). Remember to show all steps and check your work carefully. P
University of Phoenix - MATH - math 115
Name: Crystal Reilly _ Date:_5-22-10MAT115Test 3 Chapters 5, 6 and 7 25 problems 4 points each 100 points possible Solve all problems and attach your solutions document in your Individual Forum (IF). Remember to show all steps and check your work carefu
Alexandria University - PHYS - MP107
PUZZLERHave you ever wondered why a tennis ball is fuzzy and why a golf ball has dimples? A spitball is an illegal baseball pitch because it makes the ball act too much like the fuzzy tennis ball or the dimpled golf ball. What principles of physics gover
Nova Southeastern University - ACT - 5753
COUNTY OF LOS ANGELES COMPREHENSIVE ANNUAL FINANCIAL REPORTFiscal Year Ended June 30, 2009 Wendy L. Watanabe, Auditor-ControllerCOUNTY OF LOS ANGELES COMPREHENSIVE ANNUAL FINANCIAL REPORT FOR THE FISCAL YEAR ENDED JUNE 30, 2009 TABLE OF CONTENTSI.INTR
Harvard - PSYCH - 1000
The presents new theories about how men fall in love and for how long.
The Petroleum Institute - PHYS - 344
11. (a) The vertical components of the individual fields (due to the two charges) cancel, by symmetry. Using d = 3.00 m and y = 4.00 m, the horizontal components (both pointing to the x direction) add to give a magnitude ofEx ,net = 2|q|d 2(8.99 109 N m
The Petroleum Institute - PHYS - 344
14. The field of each charge has magnitude E= kq e 1.60 1019 C =k = (8.99 109 N m 2 C2 ) = 3.6 106 N C. 2 2 2 r (0.020 m) ( 0.020 m )The directions are indicated in standard format below. We use the magnitude-angle notation (convenient if one is using a
The Petroleum Institute - PHYS - 344
15. (a) The electron ec is a distance r = z = 0.020 m away. Thus, (8.99 109 N m 2 C2 )(1.60 1019 C) = = 3.60 106 N/C . EC = 2 2 4 0 r (0.020 m)e(b) The horizontal components of the individual fields (due to the two es charges) cancel, and the vertical c
The Petroleum Institute - PHYS - 344
16. The net field components along the x and y axes areEnet, x =4 0 Rq12q2 cos , 4 0 R 2Enet, y = q2 sin . 4 0 R 2The magnitude is the square root of the sum of the components-squared. Setting the magnitude equal to E = 2.00 105 N/C, squaring and
The Petroleum Institute - PHYS - 344
17. We make the assumption that bead 2 is in the lower half of the circle, partly because it would be awkward for bead 1 to slide through bead 2 if it were in the path of bead 1 (which is the upper half of the circle) and partly to eliminate a second solu
The Petroleum Institute - PHYS - 344
18. According to the problem statement, Eact is Eq. 22-5 (with z = 5d)Eact = q q 160 q = 2 2 4 0 (4.5d ) 4 0 (5.5d ) 9801 4 0 d 2and Eapprox isEapprox =2qd 2 q = . 3 4 0 (5d ) 125 4 0 d 2The ratio isEapprox Eact = 0.9801 0.98.
The Petroleum Institute - PHYS - 344
19. (a) Consider the figure below. The magnitude of the net electric field at point P is 1 q Enet = 2 E1 sin = 2 2 2 4 0 ( d / 2 ) + r d /2( d / 2)2+ r2=1qd4 0 ( d / 2 )2 + r 2 3/ 2 &gt; For r &gt; d , we write [(d/2)2 + r2]3/2 r3 so the expression abo
The Petroleum Institute - PHYS - 344
20. Referring to Eq. 22-6, we use the binomial expansion (see Appendix E) but keeping higher order terms than are shown in Eq. 22-7:E=q d 3 d2 1 d3 d 3 d2 1 d3 + 4 z2 + 2 z3 + 1 z + 4 z2 2 z3 + 2 1 + z 4o z q d3 qd + + = 2o z3 4o z5Therefore, in the t
The Petroleum Institute - PHYS - 344
21. Think of the quadrupole as composed of two dipoles, each with dipole moment of magnitude p = qd. The moments point in opposite directions and produce fields in opposite directions at points on the quadrupole axis. Consider the point P on the axis, a d
The Petroleum Institute - PHYS - 344
23. We use Eq. 22-3, assuming both charges are positive. At P, we haveEleft ring = Eright ring 4 0 ( R + R2q1 R2 3/ 2)=q2 (2 R) 4 0 [(2 R ) 2 + R 2 ]3/ 2Simplifying, we obtainq1 2 = 2 q2 53/ 2 0.506.
The Petroleum Institute - PHYS - 344
25. From symmetry, we see that the net field at P is twice the field caused by the upper semicircular charge + q = R (and that it points downward). Adapting the steps leading to Eq. 22-21, we findj Enet = 2 () sin 4 0 R9090 q j. = 2 2 0 R (a) With
The Petroleum Institute - PHYS - 344
26. We find the maximum by differentiating Eq. 22-16 and setting the result equal to zero.d qz dz 4 z 2 + R 2 0F GG HcI q R 2z J= h JK 4 cz + R h2 3/ 2 0 222 5/ 2=0which leads to z = R / 2 . With R = 2.40 cm, we have z = 1.70 cm.
The Petroleum Institute - PHYS - 344
27. (a) The linear charge density is the charge per unit length of rod. Since the charge is uniformly distributed on the rod,=q 4.231015 C = = 5.19 1014 C/m. L 0.0815 m(b) We position the x axis along the rod with the origin at the left end of the rod,
The Petroleum Institute - PHYS - 344
28. We use Eq. 22-16, with q denoting the charge on the larger ring:qz qz 13 + = 0 q = Q 2 2 3/ 2 2 2 3/ 2 4 0 ( z + R ) 4 0 [ z + (3R) ] 53/ 2= 4.19Q .Note: we set z = 2R in the above calculation.
The Petroleum Institute - PHYS - 344
29. The smallest arc is of length L1 = r1 /2 = R/2; the middle-sized arc has length L2 = r2 / 2 = (2 R) / 2 = R ; and, the largest arc has L3 = (3R)/2. The charge per unit length for each arc is = q/L where each charge q is specified in the figure. Follow
The Petroleum Institute - PHYS - 344
30. (a) It is clear from symmetry (also from Eq. 22-16) that the field vanishes at the center. (b) The result (E = 0) for points infinitely far away can be reasoned directly from Eq. 2216 (it goes as 1/z as z ) or by recalling the starting point of its de
The Petroleum Institute - PHYS - 344
31. First, we need a formula for the field due to the arc. We use the notation for the charge density, = Q/L. Sample Problem 22-3 illustrates the simplest approach to circular arc field problems. Following the steps leading to Eq. 22-21, we see that the g
The Petroleum Institute - PHYS - 344
33. Consider an infinitesimal section of the rod of length dx, a distance x from the left end, as shown in the following diagram. It contains charge dq = dx and is a distance r from P. The magnitude of the field it produces at P is given by dE = 1 dx . 4
The Petroleum Institute - PHYS - 344
34. From Eq. 22-26, we obtain z E= 1 2 2 0 z + R2 2 5.3 106 C m 1 = 2 ( 8.85 1012 C2 /N m 2 ) 12cm(12cm ) + ( 2.5cm )22 = 6.3103 N C.
The Petroleum Institute - PHYS - 344
35. At a point on the axis of a uniformly charged disk a distance z above the center of the disk, the magnitude of the electric field isE= z 1 2 2 0 z + R2LM NOP Qwhere R is the radius of the disk and is the surface charge density on the disk. See Eq
The Petroleum Institute - PHYS - 344
36. We write Eq. 22-26 as E z = 1 2 Emax ( z + R 2 )1/ 2 and note that this ratio is 2 (according to the graph shown in the figure) when z = 4.0 cm. Solving this for R we obtain R = z 3 = 6.9 cm.1
Dallas - HIST - 1302
Angelica Casas Larry Pool History 1302 July 21, 2009 The Jungle Throughout the history of society, economic competition has been a constant struggle. The Jungle by Upton Sinclair demonstrates an example of this struggle. It is, questionably, one of the mo
UC Irvine - MGMT - 38004
Management5Final19:22 Chapter 6: Individual and Group Decision Making Decision Making Process of specifying the nature of particular problem or opportunity and selecting among the available alternatives to solve the problem or capitalize on the opportuni
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070
Cornell - CHEM - 2070