Answer the question
In order to leave comments, you need to log in
How can I make it so that the int method can return an int and string value?
The task itself:
Develop a class library containing a class with a method that will simulate the work of a robot calculator. The input to the robot is a number and a string - a sequence of commands, where "0" means "add 2 to the number",
"1" means "multiply the number by 5".
Each time the command is applied to the already obtained result.
It is necessary to return something like "the wrong command is entered".
My code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RobotLib
{
public class Robot
{
string comand;
int num;
public void setComand(string a)
{
comand = a;
}
public string getComand()
{
return comand;
}
public void setNum(int b)
{
num = b;
}
public int getNum()
{
return num;
}
public int robotAction()
{
if(comand == "0")
{
return num + 2;
}
else if(comand == "1")
{
return num * 5;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
It is necessary to return something like "the wrong command is entered".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question