My task is to have the LiftingPower () method be abstract. How can I correctly implement the LiftingPower () method in the Motorcycle class? The method should set the load capacity, but before that ask about the presence of a motorcycle stroller. If it is not there, then assign the load value to 0. I don’t like my version of the method implementation much. abstract class Carrier {private string model; private string number; private double speed; protected double liftPower;

private bool SpeedIsNotCorrect(double tempSpeed) { return tempSpeed > 0.0; } private bool ModelIsNotCorrect(string tempModel) { return String.IsNullOrEmpty(tempModel); } private bool NumberIsNotCorrect(string tempNumber) { return String.IsNullOrEmpty(tempNumber); } public string Model { get { return model; } set { do { model = value; }while(ModelIsNotCorrect(model)); } } public double Speed { get { return speed; } set { do { speed = value; }while(!SpeedIsNotCorrect(speed)); } } public string Number { get { return number; } set { do { number = value; } while (NumberIsNotCorrect(number)); } } abstract public void DecsribeCarrier(); abstract public double LiftingPower(); } class Car : Carrier { public Car(string mod, string num, double lPower) { Model = mod; Number = num; liftPower = lPower; } public override double LiftingPower() { return liftPower; } public override void DecsribeCarrier() { Console.WriteLine("Π­Ρ‚ΠΎ лСгковая машина ΠΌΠ°Ρ€ΠΊΠΈ {0} с Π½ΠΎΠΌΠ΅Ρ€ΠΎΠΌ {1} ΠΈΠΌΠ΅Π΅Ρ‚ ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ {2} ΠΊΠΌ/час. ", Model, Number, Speed); } } class Motorcycle : Carrier { public Motorcycle(string mod, string num) { Model = mod; Number = num; } public override void LiftingPower() { Console.WriteLine("К ΠΌΠΎΡ‚ΠΎΡ†ΠΈΠΊΠ»Ρƒ ΠΏΡ€ΠΈΡ†Π΅ΠΏΠ»Π΅Π½Π° каляска? - y/n"); string avaibalitySideCar = Console.ReadLine(); if (avaibalitySideCar == "y") { liftPower = 0; } else { liftPower = 2; } Console.WriteLine("БрСдняя Π³Ρ€ΡƒΠ·ΠΎΠ΄ΡŠΠ΅ΠΌΠ½ΠΎΡΡ‚ΡŒ ΠΌΠΎΡ‚ΠΎΡ†ΠΈΠΊΠ»Π° {0} Ρ‚ΠΎΠ½", liftPower); return liftPower; } public override void DecsribeCarrier() { Console.WriteLine("Π­Ρ‚ΠΎ ΠΌΠΎΡ‚ΠΎΡ†ΠΈΠΊΠ» ΠΌΠ°Ρ€ΠΊΠΈ {0} с Π½ΠΎΠΌΠ΅Ρ€ΠΎΠΌ {1} ΠΈΠΌΠ΅Π΅Ρ‚ ΡΠΊΠΎΡ€ΠΎΡΡ‚ΡŒ {2}", Model, Number, Speed); } 
  • one
    IMHO, the method is normally implemented (within the framework of the task), only the string "return liftPower" is superfluous, the method is void. If you want a clearer answer, then either specify the requirements for the task, or tell me what exactly you do not like. PS I would hide appeals to the console in a separate class so that the class of the bike would not depend on the console, but, I repeat, everything depends on the task. - ganouver
  • 2
    Reduce the amount of code and specify what exactly you do not like. - Jakeroid
  • Return is not superfluous, since the method in the base class is declared as returning a double value. Therefore, the code will not compile with the view - I suspect this is a typo. By using the console +1 - wind

0