SlideShare uma empresa Scribd logo
1 de 2
The following exercises need to be solved in the given order. 
Exercises: 
1. In the last series of exercises the class DynamicIntArray has been implemented; in 
these tasks you also had to write some tests. Now we're going to systemize testing of 
classes with so called unit tests. 
a) Rewrite the unit tests for the class DynamicIntArray with the facilities integrated into 
Visual Studio, a quick introduction can be found in “Anatomy of a Unit Test”. 
b) You should be able to answer following questions afterwards: 
• What is a unit test? 
• Who creates unit tests? 
• When are unit tests being created? 
• Who executes the unit tests? 
• When are unit tests being executed? 
2. Let's revisit the class DynamicIntArray. 
a) How can we implement a class "DynamicArray" that works with all sorts of types 
(without generics!), e.g.: int, string, double[]? Hint: substitution principle. 
b) Implement the class DynamicArray and test it with elements of type string. - Just 
copy the former project with the DynamicIntArray (incl. unit tests) and modify the 
code. 
c) Redesign the unit tests as well. 
3. Write another class "DynamicCarArray", which is able to store all kinds (types and 
subtypes) of Cars. 
a) Prove that is works with Buses and VintageCars stored in the same array at 
different indexes. 
b) Loop over an instance of that array containing types and subtypes of Car instances 
and write the result of the method ToString() to the console res. 
4. Implement the classes Date and Appointment. - They should be associated to each 
other. - Which association did you choose? Document your idea in a clear manner. 
5. Implement the types Shape, Triangle, Circle, Rectangle and Square in a C# project by 
the usage of inheritance. Not every type needs to be implemented in its own class, if 
helpful more types can be introduced. Respect following guidelines: 
a) Stick to the SOLID principle. 
b) Each type should reside in dedicated file. 
c) All fields needs to be encapsulated. 
d) One of the types needs to be an abstract class. 
e) Following public methods should be implemented reasonably: 
GetPosition()/SetPosition(), GetA()/SetA(), GetB()/SetB(), GetC()/SetC(), 
GetD()/SetD() and GetRadius()/SetRadius(). 
f) The method ToString() should be overridden to generate a string representing the 
data position, a, b, c, d and radius where reasonable. 
g) You should be able to draw the type hierarchy on the whiteboard (e.g. with a UML 
diagram). 
h) Prove the functionality of that types with some unit tests.
6. Learn about the interface IComparable (not IComparable(T)) in the .Net documentation 
a) Implement the class “Car” and the inherited class “VintageCar”, the types can have 
any fields and methods. The class VintageCar should implement the interfaces 
IHistorical and IComparable. Esp. for the implementation of IComparable you need 
to define how VintageCar instances, i.e. their fields, can be compared. 
b) The method CompareTo() should only be able to compare instances of the type 
VintageCar. 
c) In which cases does the .Net framework require types to implement IComparable? 
7. With the results of the last exercise show following aspects with a couple of unit tests 
and belonging to comments: 
a) Usage of IComparable. 
b) Downcasting. 
c) Static and dynamic type. 
8. Read the chapters six and seven of the book "Visual C# 2010". 
Remarks: 
• The usage of the keywords var, dynamic, foreach and goto is not allowed! 
• Avoid magic numbers and use constants where possible. 
• The results of the programming exercises need to be runnable applications! All 
programs have to be implemented as console programs. 
• The programs need to be robust, i.e. they should cope with erroneous input from the 
user. 
• You should be able to describe your programs after implementation. Comments are 
mandatory. 
• In documentations as well as in comments, strings or user interfaces make correct use 
of language (spelling and grammar)! 
• Put your solutions into the TFS repository. 
• Don't panic: In programming multiple solutions are possible. 
• If you have problems use the Visual Studio help (F1), books and the internet primarily. 
• Of course you can also ask colleagues; but it is of course always better, if you find a 
solution yourself. 
<<interface>> 
IHistorical 
+ Era() : Era 
+ EstimatedPrize() : double

Mais conteúdo relacionado

Mais de Nico Ludwig

New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 

Mais de Nico Ludwig (20)

(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(2) gui drawing
(2) gui drawing(2) gui drawing
(2) gui drawing
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivity
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_vi
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_v
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iii
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_ii
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_i
 
New c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_vNew c sharp3_features_(linq)_part_v
New c sharp3_features_(linq)_part_v
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_ivNew c sharp3_features_(linq)_part_iv
New c sharp3_features_(linq)_part_iv
 
New c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iiiNew c sharp3_features_(linq)_part_iii
New c sharp3_features_(linq)_part_iii
 
New c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_iiNew c sharp3_features_(linq)_part_ii
New c sharp3_features_(linq)_part_ii
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
New c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_iNew c sharp3_features_(linq)_part_i
New c sharp3_features_(linq)_part_i
 
Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
 
Review of c_sharp2_features_part_ii
Review of c_sharp2_features_part_iiReview of c_sharp2_features_part_ii
Review of c_sharp2_features_part_ii
 
Review of c_sharp2_features_part_i
Review of c_sharp2_features_part_iReview of c_sharp2_features_part_i
Review of c_sharp2_features_part_i
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

(5) c sharp introduction_object_orientation_part_ii_exercises

  • 1. The following exercises need to be solved in the given order. Exercises: 1. In the last series of exercises the class DynamicIntArray has been implemented; in these tasks you also had to write some tests. Now we're going to systemize testing of classes with so called unit tests. a) Rewrite the unit tests for the class DynamicIntArray with the facilities integrated into Visual Studio, a quick introduction can be found in “Anatomy of a Unit Test”. b) You should be able to answer following questions afterwards: • What is a unit test? • Who creates unit tests? • When are unit tests being created? • Who executes the unit tests? • When are unit tests being executed? 2. Let's revisit the class DynamicIntArray. a) How can we implement a class "DynamicArray" that works with all sorts of types (without generics!), e.g.: int, string, double[]? Hint: substitution principle. b) Implement the class DynamicArray and test it with elements of type string. - Just copy the former project with the DynamicIntArray (incl. unit tests) and modify the code. c) Redesign the unit tests as well. 3. Write another class "DynamicCarArray", which is able to store all kinds (types and subtypes) of Cars. a) Prove that is works with Buses and VintageCars stored in the same array at different indexes. b) Loop over an instance of that array containing types and subtypes of Car instances and write the result of the method ToString() to the console res. 4. Implement the classes Date and Appointment. - They should be associated to each other. - Which association did you choose? Document your idea in a clear manner. 5. Implement the types Shape, Triangle, Circle, Rectangle and Square in a C# project by the usage of inheritance. Not every type needs to be implemented in its own class, if helpful more types can be introduced. Respect following guidelines: a) Stick to the SOLID principle. b) Each type should reside in dedicated file. c) All fields needs to be encapsulated. d) One of the types needs to be an abstract class. e) Following public methods should be implemented reasonably: GetPosition()/SetPosition(), GetA()/SetA(), GetB()/SetB(), GetC()/SetC(), GetD()/SetD() and GetRadius()/SetRadius(). f) The method ToString() should be overridden to generate a string representing the data position, a, b, c, d and radius where reasonable. g) You should be able to draw the type hierarchy on the whiteboard (e.g. with a UML diagram). h) Prove the functionality of that types with some unit tests.
  • 2. 6. Learn about the interface IComparable (not IComparable(T)) in the .Net documentation a) Implement the class “Car” and the inherited class “VintageCar”, the types can have any fields and methods. The class VintageCar should implement the interfaces IHistorical and IComparable. Esp. for the implementation of IComparable you need to define how VintageCar instances, i.e. their fields, can be compared. b) The method CompareTo() should only be able to compare instances of the type VintageCar. c) In which cases does the .Net framework require types to implement IComparable? 7. With the results of the last exercise show following aspects with a couple of unit tests and belonging to comments: a) Usage of IComparable. b) Downcasting. c) Static and dynamic type. 8. Read the chapters six and seven of the book "Visual C# 2010". Remarks: • The usage of the keywords var, dynamic, foreach and goto is not allowed! • Avoid magic numbers and use constants where possible. • The results of the programming exercises need to be runnable applications! All programs have to be implemented as console programs. • The programs need to be robust, i.e. they should cope with erroneous input from the user. • You should be able to describe your programs after implementation. Comments are mandatory. • In documentations as well as in comments, strings or user interfaces make correct use of language (spelling and grammar)! • Put your solutions into the TFS repository. • Don't panic: In programming multiple solutions are possible. • If you have problems use the Visual Studio help (F1), books and the internet primarily. • Of course you can also ask colleagues; but it is of course always better, if you find a solution yourself. <<interface>> IHistorical + Era() : Era + EstimatedPrize() : double