SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Plus de Nico Ludwig

(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
 
(1) gui history_of_interactivity
(1) gui history_of_interactivity(1) gui history_of_interactivity
(1) gui history_of_interactivityNico Ludwig
 
New c sharp4_features_part_vi
New c sharp4_features_part_viNew c sharp4_features_part_vi
New c sharp4_features_part_viNico Ludwig
 
New c sharp4_features_part_v
New c sharp4_features_part_vNew c sharp4_features_part_v
New c sharp4_features_part_vNico Ludwig
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_ivNico Ludwig
 
New c sharp4_features_part_iii
New c sharp4_features_part_iiiNew c sharp4_features_part_iii
New c sharp4_features_part_iiiNico Ludwig
 
New c sharp4_features_part_ii
New c sharp4_features_part_iiNew c sharp4_features_part_ii
New c sharp4_features_part_iiNico Ludwig
 
New c sharp4_features_part_i
New c sharp4_features_part_iNew c sharp4_features_part_i
New c sharp4_features_part_iNico Ludwig
 
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_vNico 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_ivNico 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_ivNico Ludwig
 
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_iiiNico Ludwig
 
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_iiNico Ludwig
 
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_iNico Ludwig
 
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_iNico Ludwig
 
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_iiiNico Ludwig
 
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_iiNico Ludwig
 
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_iNico Ludwig
 

Plus 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
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+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...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

(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