Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c# programming: A) Write a class called Robot with the following three instan

ID: 3761203 • Letter: I

Question

In c# programming:

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

B) Allow the users of the Robot class to set the initial values of the three instance variables when a Robot object is created. To this end declare one constructor with three formal parameters and one default constructor.

C) Include a member variable called robotsCreated that keeps track of the number of Robot objects created. Make the constructors update the robotsCreated variable so it is always up to date. Implement the following logic: If robotsCreated is less than 5 when the constructor is called, set isOn to true; otherwise false

Explanation / Answer

using System;
namespace RobotApplication1
{
    /// <summary>
    /// Summary description for Robot1Class
    /// This class will declare and define the variables and functions needed
    /// </summary>
    public class Robot1
    {
        String name;
        short age;
        bool isOn;
        int robotsCreated = 0;


        void initRobot(String name, short age, bool isOn)
        {

            this.name = "UnKnown";
            this.age = 0;
            this.isOn = FALSE;
        } /// end funtion initRobot
        ///
        /// Accessor method to assign values
        ///
        ///

        void accRob(String name, short age, bool isOn)
        {
            this.name = name;
            this.age = age;
            this.isOn = isOn;

        } /// end accRob method

        ///
        ///
        /// Mutator method to retrieve values
        ///

        void mutateRob(String name, short age, bool isOn)
        {

            name = this.name;
            age = this.age;
            isOn = this.isOn;

        } /// end mutateRob method

        public static void Main(string[] args)
        {
            /// instantiate objects
             Robot1 objRobot1;
             objRobot1 = new Robot1();
             Console.WriteLine(objRobot1.Describe());
            /// void accRob(String name, short age, bool isOn)
             objRobot1.accRob("Asimo Robot", 5, True);
             robotsCreated++;
             Console.WriteLine(objRobot1.Describe());
             objRobot1.accRob("Joy Robot", 4, True);
             robotsCreated++;
             Console.WriteLine(objRobot1.Describe());
             objRobot1.accRob("Toy Robot", 6, True);
             robotsCreated++;
             Console.WriteLine(objRobot1.Describe());
             objRobot1.accRob("Jack Robot The Humanoid", 3, True);
             robotsCreated++;
             Console.WriteLine(objRobot1.Describe());
             Console.WriteLine("So far created " + robotsCreated + " many Robots ");


        } // end main function

    } /// end class Robot1


    ///
    ///class Robot {

    ///
    ///
} /// end of namespace or end of the whole program package

/// The following ASPx code will call the above c sharp ( c# ) code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Robot1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>

class Robot {
    String name,
    short age,
    bool isOn
  
    void initRobot(String name, short age, bool isOn) {
  
        this.name = name;
        this.age = age;
        this.isOn = isOn;
      
      
  
    } // end funtion initRobot


} // end class Robot

<body>
    <form id="form1" runat="server">
    <div>
    /// comments
    ///In c# programming:
    ///A) Write a class called Robot with the following three instance variables:
    /// name (string), age (ushort), isOn (bool). Make the program initialize the instance variables to “unknown”, 0,
    /// and false, respectively (without using constructors).
  
    /// Include accessor and mutator methods to assign and retrieve the values of these instance variables.
    ///B) Allow the users of the Robot class to set the initial values of the three instance variables when a Robot object is created. To this end declare one constructor with three formal parameters and one default constructor.
    ///C) Include a member variable called robotsCreated that keeps track of the number of Robot objects created. Make the constructors update the robotsCreated variable so it is always up to date. Implement the following logic: If robotsCreated is less than 5 when the constructor is called, set isOn to true; otherwise false
    ///
  
  
  
    </div>
    </form>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote