• Aucun résultat trouvé

LP24 Object Oriented Programing Final Exam - Spring 2017

N/A
N/A
Protected

Academic year: 2022

Partager "LP24 Object Oriented Programing Final Exam - Spring 2017"

Copied!
2
0
0

Texte intégral

(1)

LP24 Object Oriented Programing Final Exam - Spring 2017 Documents, Computer, Calculator unauthorized

1. Theoretical questions (3 pts)

A. What are the pillars of OOP?

B. What is inheritance? Explain the differences between inheritance and composition. When should we prefer one or the other?

C. Explain the difference between a class and an object.

2. Exercise #1: Computations (8 pts)

The goal of this exercice is to develop a program aimed at evaluating arithmetical equations such as the one presented in the figure. For this purpose, we will use binary trees for representing an expression. Thus, the tree presented in the figure corresponds to the following expression: 3+5*(4+2)

A tree representing an expression is composed of nodes from two types: (1) constant value (2) binary operator.

The code which evaluates the value of the example can be written as follows:

class TestExprExample{


public static void main(String [] arg){

Constant c1 = new Constant (3) , c2 = new Constant (5) , c3 = new Constant (4) , c4 = new Constant (2);

Operator o1 = new Addition(), o2 = new Multiplication(), o3 = new Addition();

o1.setRL ( c1 ) ; o1.setLL ( o2 ) ; o2.setRL ( c2 ) ; o2.setLL ( o3 ) ; o3.setRL ( c3 ) ; o3.setLL ( c4 ) ;

System.out.println (o1.eval ( ) ) ; }

}

System . out . p r i n t l n ( ” V e h i c u l e s : ”+v1+v2+v3 ) ; System . out . p r i n t l n ( ) ;

v2 . a p p r o v i s i o n n e r ( 3 5 . 0 ) ; // l i t r e s d ’ e s s e n c e v3 . a p p r o v i s i o n n e r ( 7 0 . 0 ) ;

System . out . p r i n t l n ( ) ;

v1 . t r a n s p o r t e r ( ” Di jon ” , ” Valence ” ) ; v2 . t r a n s p o r t e r ( 5 , 3 0 0 ) ;

v3 . t r a n s p o r t e r ( ” t u i l e s ” , 1 0 0 0 ) ; }

Ce programme est-il correct ? Le corriger si n´ecessaire. Qu’affiche-t-il ? Question 10

On voudrait maintenant d´efinir des v´ehicules ´ecologiques. Les v´ehicules sans moteur et la voiture ´electrique sont

´ecologiques.

1. Que faut-il rajouter `a la hi´erarchie des classes pour mod´eliser les v´ehicules ´ecologiques ?

2. Comment doit-on modifier les classes d´ecrites initialement pour rendre les v´ehicules sans moteur ´ecologiques ? 3. Comment ´ecrire la classe VoitureElectrique?

Exercice 2

On souhaite ´evaluer des expressions arithm´etiques repr´esent´ees sous forme d’arbre.

Par exemple l’expression 3 + 5 * (4 + 2) peut ˆetre repr´esent´ee par l’arbre de la figure.

Un arbre est constitu´e de noeuds valu´es. On distingue deux sortes de noeud :

• les op´erateurs dont la valeur est celle de l’expression arithm´etique associ´ee

• et les constantes.

La classe suivante permet d’´evaluer l’expression pr´ec´edente : c l a s s TestExprArith{

public s t a t i c void main ( S t r i n g [ ] a r g ){

Constante c1 = new Constante ( 3 ) , c2 = new Constante ( 5 ) , c3 = new Constante ( 4 ) , c4 = new Constante ( 2 ) ;

Operateur o1 = new A d d i t i o n ( ) , o2 = new M u l t i p l i c a t i o n ( ) , o3 = new A d d i t i o n ( ) ; o1 . setFD ( c1 ) ;

o1 . setFG ( o2 ) ; o2 . setFD ( c2 ) ; o2 . setFG ( o3 ) ; o3 . setFD ( c3 ) ; o3 . setFG ( c4 ) ;

System . out . p r i n t l n ( o1 . e v a l ( ) ) ; }

}

Question 1

Ecrire la classe Noeud permettant de repr´esenter un noeud de l’arbre avec ces deux fils. Pourquoi est-elle abstraite ? Question 2

Ecrire la classe Constante.

Question 3

Les op´erateurs sont des noeuds ayant la propri´et´e d’ˆetre ´evalu´e. Comment d´eclarer la classe Operateur en Java ? Ecrire l’ensemble des classes n´ecessaires pour repr´esenter les 4 op´erations.

Polytech’Paris-UPMC Electronique Informatique Syst`emes Embarqu´es - 3e ann´ee´ 2

(2)

Question 1: Write the class Node which describes what a node is. Can the Node class be considered as a regular class? Why?

Question 2: Write the class that describes the constants

Question 3: Operators are nodes that can be evaluated depending on their type. However, they are sharing some common features. How to manage this in Java?

Question 4: Write the classes necessary for defining the 4 classical operators?

3. Exercise #2: The droid classification (9 pts)

We consider the Droid class which is aimed at representing the characteristics of a droid. A droid is defined by a name, a release date, a version, a manufacturer and a set of type numbers.

A droid can be from one or several types, each of them being associated to a set of possible actions such as firing for droid from type #4 or repairing ships for droid from type #2.

The types of droids are the following:

• The first type was made up of droids skilled in mathematical, physical, and medical sciences.

• Droids of the second type were skilled in engineering and technical sciences.

• Third type droids were skilled in social sciences and service functions.

• Droids of the fourth type were skilled in military and security functions

• Fifth type droids were programmed for menial labor and intensive jobs that did not require a high level of intelligence

Question 1: Write the enum Type which will represent the available types of droids. Why do we need an enum instead of using an integer for representing the number of the droid types.

Question 2: Write the Droid class. Is this class a regular class?

Question 3: How can we manage the 5 possible types of droids. Can we define a Java class for each droid type? What Java feature can we use then? Give all necessary the code which will allow to define droids from the proposed types.

Question 4: Looking for R2D2. Using your classes, you can now define the Astromech droid type which is from droid type #2. Write this class.

Question 5: All the droids have a location device. Considering that all the droids from the empire

are store into an ArrayList named myDroids, write the lines of codes of a main program that will

make a call to the locate function of all the imperial droids. What features of OOP is used for

making this easily possible?

Références

Documents relatifs

The goal of the exercise is to write the required classes which embedded the methods aimed at writing the following patterns on the screen!. Try to do so with as

The goal of the exercise is to write the required classes which embedded the methods aimed at writing the following patterns on the screen.. Try to do so with as

The conversion of cellulose or lignocellulosic biomass to isosorbide was studied by combining a homogeneous acid cata- lyst to promote the hydrolysis of cellulose to glucose and

To have an uniform and transparent mechanism to store values of a field, our different structures that keep states of this field for linear, backtracking and branching

An example for this transformation is thus composed of a UML model (the input model), a Relational model (the output model) and transformation links making explicit from which

[r]

Our method fol- lows two phases: (1) objects are detected and tracked from every single frame using YOLO, providing simple events such as appearance of the object, disap- pearance

• Using addr2line , address from ndk-stack and binary with symbols , we resolve the crash to a line and method in the sourcode.. HOW TO : DROID-FF :