0% found this document useful (0 votes)
70 views15 pages

Exam Object Oriented Software Development CME 1, WS 2010/11 09.02.2011

This document contains instructions and exercises for an object oriented software development exam. It provides instructions that students' names and student IDs must be written on exam sheets. It also lists the point values and time limit for the exam. The exam contains 4 exercises on topics like short code examples, class diagrams, redesigning class models, and designing class diagrams. Students are allowed to use an English dictionary and a 4 page handout during the exam.

Uploaded by

Shubham Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views15 pages

Exam Object Oriented Software Development CME 1, WS 2010/11 09.02.2011

This document contains instructions and exercises for an object oriented software development exam. It provides instructions that students' names and student IDs must be written on exam sheets. It also lists the point values and time limit for the exam. The exam contains 4 exercises on topics like short code examples, class diagrams, redesigning class models, and designing class diagrams. Students are allowed to use an English dictionary and a 4 page handout during the exam.

Uploaded by

Shubham Kapoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Name: _____________________________________ MatrikelNr.

: ____________________

Exam Object Oriented Software Development CME 1, WS 2010/11 09.02.2011

Time: 60 Minutes Liudmila Goryaynova


___________________________________________________________________________

1. Please write your name and Matrikelnummer on each sheet of paper. Sheets without
name and Matrikelnummer will not be graded.
2. Please use the provided sheets for writing down your solutions. Other sheets will not
be graded.
3. Please check that the exam sheets are complete.
4. Please write clean and clearly readable. Unreadable answers will not be graded. Please
do not use a pencil or red ink.
5. Students are allowed to use an English dictionary and the Handout of 4 DIN A4 Pages

Exercise 1 2 3 4 Sum
Points 19 36 12 12 79

Reached Points

Final Result

Good Luck!

Please wait to turn over page until exam starts!

__________________________________________________________________________________________
Page 1 von 1
Name: _____________________________________ MatrikelNr.: ____________________

Exercise 1: Short exercises (19 Points)

Please provide short answers below/behind the questions in this sheet.

a) Have a look at the following source code:

public class ExamDemo {

public static void main(String[] args) {


ExamDemo demo = new ExamDemo();

demo.doSomething();
}

public void doSomething() throws Exception {


System.out.println("Print out the message");
}

Please mark the line of code where the compiler error is. What should be done to correct the
code? (4 Points)

c) Following source code is given:


private static final String myField = "My Field";

public static void main(String[] args) {


myField = myField + "5";
}
Mark the line in which compiler error is. Why compiler marks this line as error? (2 Points)

__________________________________________________________________________________________
Page 2 von 2
Name: _____________________________________ MatrikelNr.: ____________________

d) The following interface and class definition are given:

public interface IWashable {

void wash();
}

public class Car implements IWashable {

private int power;

public void start() {


// do something
}
}

Please describe what is wrong in this code.


Provide 2 possibilities to correct this code. (4 Points)

e) Is it possible for the class in Java to have multiple superclasses?


Which concept allows somehow the multiple inheritance? (2 Points)

f) Following code is given:

int i, j, k;
double d = 5.52;

i = (int)d;
j = i;
k = i + j;

System.out.println("i: " + i);


System.out.println("j: " + j);
System.out.println("k: " + k);

Provide the values of i, j and k. (3 Points)

__________________________________________________________________________________________
Page 3 von 3
Name: _____________________________________ MatrikelNr.: ____________________

g) Which advantage gives the Generics Framework of Java? (1 Point)

h) Please provide the definition of Enumeration class, which represents the day of week
property of the Date. Possible values of Enum are: Monday, Tuesday, Wednesday, Thursday,
Friday, Saturday and Sunday. (3 Points)

__________________________________________________________________________________________
Page 4 von 4
Name: _____________________________________ MatrikelNr.: ____________________

Exercise 2: Class diagram (36 Points)

Following class diagram is given:

a) Translate the given UML Diagram to the Java code. Data types and access modifiers are
provided. Methods should only contain the implementation that is necessary for compilation
(no business logic). Please notice, that the relationship between class Store and Product
has also an access modifier. Constructor of the class Product should initialize the attributes
productID, description and price with the values of the parameters. Take attention
that the getProductInfo() - method is overwritten in each subclass of Product.
(16 Points)

b) Please implement the printAllProducts()- method. The method should give out the
list of all products, represented by the relationship between the classes Store and Product,
to the console in the following format: “The %product% %description% with
ID: %productID% costs %price% Euro.”
%product% - takes the value “IronTool” or “Toy” dependent on which type of product is it
%description% - the value of the attribute description
%productID% - the value of the attribute productId
%price% - the value of the attribute price
(8 Points)

__________________________________________________________________________________________
Page 5 von 5
Name: _____________________________________ MatrikelNr.: ____________________

c) Additional to the stuff, defined in UML diagram, following constant is given in the
Product class:
public static final double SALES_TAX = 19.0;
Please implement setPrice(double basePrice)- method as follows: the price of the
product can be calculated as a sum of the base price, which is given by a parameter of the
method setPrice(), and 19% of the base price for the sales tax. This value should be set
as a value of the attribute price in the Product class. Take care, that the base price cannot be
negative.
(4 Points)

d) Please provide the TestClass for the method setPrice(double basePrice) –


SetPriceTest. Implement the setUp()- method in order to prepare your test data
(creation of the Product-object etc.). Provide at least 2 test methods in order to test
setPrice(double basePrice)- method in positive (standard case) and negative (not
valid parameter as a base price) way.
(8 Points)

__________________________________________________________________________________________
Page 6 von 6
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 7 von 7
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 8 von 8
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 9 von 9
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 10 von 10
Name: _____________________________________ MatrikelNr.: ____________________

Exercise 3: Redesign (12 Points)


Following class diagram is given:

a) Redesign this model (provide the new UML class diagram) in order to avoid the code
redundancy.
(4 Points)

b) Following class more is given:

Please integrate this class in your class hierarchy above and avoid code redundancy. Make
sure that Bird and Aircraft classes have the fly()- method in any case.
(6 Points)

c) What are the differences (write down at least 2 of them) between abstract classes and
interfaces?
(2 Points)

__________________________________________________________________________________________
Page 11 von 11
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 12 von 12
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 13 von 13
Name: _____________________________________ MatrikelNr.: ____________________

Exercise 4: Design (12 Points)

a) Provide the UML class diagram for the following description:


A Locomotive has many wagons. The Wagon has attributes maximum weight and
length. Locomotive should provide the method
isTotalLengthExceeded(double maxLength) with return true or false,
weather the given length is exceeded by current list of wagons or not.
(6 Points)

b) Implement the isTotalLengthExceeded(double maxLength) method as it


described above
(6 Points)

__________________________________________________________________________________________
Page 14 von 14
Name: _____________________________________ MatrikelNr.: ____________________

__________________________________________________________________________________________
Page 15 von 15

You might also like