In: Computer Science
c#
Create a class named TelpaMotion.
The inMotion field must not be accseible outside of the class. This fields can be initialized 3 different ways.
Default 67 mulltiplied by the value of 9.80665
A value being passed to it
A starting value and an acceleration rate can also be passed, the value should be multiplied by the acceleration rate to set the initial value.
Create a static field called tractionValue with a default value of 0.33.
In the same class create a public method called OverCompensate which allows your team to increase and return a result by multiplying the inMotion value by 1.5 and adding the tractionValue to the result (i.e. (inMotion *1.5)+tractionValue)
In your main method:
Call your class:
TelpaMotion optionA= new TelpaMotion();
TelpaMotion optionB= new TelpaMotion(100.45);
TelpaMotion optionC= new TelpaMotion(27.9, 0.321);
Using the object created for option c, call the OverCompensate method to assign the calculated value to a variable called emergencyStop and display the results. Option created Display to the console the results of each call to the class
C# Program
using System;
class TelpaMotion{ //class definition
private double inMotion; //set inMotion as a private
variable so that it cannot be accessible outside the class
static double tractionValue=0.33; //it is declared as
static and a default value is initialized
public TelpaMotion() //default constructor
{
inMotion=67*9.80665;
}
public TelpaMotion(double val) //constructor if only
one value is passed
{
inMotion=val;
}
public TelpaMotion(double startval,double accrate)
//constructor if start value and acc rate is passed
{
inMotion=startval*accrate;
}
public double OverCompensate() //overcompensate
method
{
return
inMotion*1.5+tractionValue;
}
}
public class Program
{
public static void Main()
{
double emergencyStop;
TelpaMotion optionA= new
TelpaMotion();
TelpaMotion optionB= new TelpaMotion(100.45);
TelpaMotion optionC= new
TelpaMotion(27.9, 0.321);
emergencyStop=optionC.OverCompensate();
Console.WriteLine("Emergency
stop:"+emergencyStop);
Console.WriteLine("optionA
OverCompensate value is "+optionA.OverCompensate());
Console.WriteLine("optionB
OverCompensate value is "+optionB.OverCompensate());
}
}
Screenshot of program


Output

If you find this useful, please rate positive , thankyou