O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required