Programming Exercises

Exercises 2–5 each build on the code written in the previous exercise, so please keep the code from each exercise handy for the next exercise. As you progress through the questions, you should write a Main method containing code to demonstrate the classes you write.

1 Write a class called Robot with the following three instance variables: name (of type string), age (of type ushort), and isOn (of type bool). Make the program initialize these three instance variables to "unknown", 0, and false, respectively (without using constructors). Include accessor and mutato methods to assign and retrieve the values of these instance variables.

Write a Main method that tests the Robot class.

2 Allow the users of the Robot class to set ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.