var shieldStrength: Int0 override fune wasHit() ( if shieldstrength> 0 shieldstrength -- 5 } else { super.wasHit() Note that each class above has an error by the class declaration that says "Class has no initializers." Unlike structs, classes do not come with memberwise initializers because the standard memberwise initializers don't always play nicely with inheritance. You can get rid of the error by providing default values for everything, but it is common, and better practice, to simply write your own initializer. Go to the declaration of Spaceship and add an initializer that takes in an argument for each property on Spaceship and sets the properties accordingly. Then create an instance of Spaceship below called falcon. Use the memberwise initializer you just created. The ship's name should be "Falcon." Writing initializers for subclasses can get tricky. Your initializer needs to not only set the properties declared on the subclass, but also set all of the uninitialized properties on classes that it inherits from. Go to the declaration of Fighter and write an initializer that takes an argument for each property on Fighter and for each property on Spaceship. Set the properties accordingly. (Hint: you can call through to a superclass' initializer with super.init after you initialize all of the properties on the subclass). Then create an instance of Fighter below called destroyer. Use the memberwise initializer you just created. The ship's name should be "Destroyer." Now go add an initializer to ShieldedShip that takes argument for each property on ShieldedShip, Fighter, and Spaceship, and sets the properties accordingly. Remember that you can call through to the initializer on Fighter using super.init. Then create an instance of ShieldedShip below called defender. Use the memberwise initializer you just created. The ship's name should be "Defender." Create a new constant named sameShip and set it equal to falcon. Print out the position of sameShip and falcon, then call moveleft() on sameShip and print out the position of sameShip and falcon again. Did both positions change? Why? If both were structs
var shieldStrength: Int0 override fune wasHit() ( if shieldstrength> 0 shieldstrength -- 5 } else { super.wasHit() Note that each class above has an error by the class declaration that says "Class has no initializers." Unlike structs, classes do not come with memberwise initializers because the standard memberwise initializers don't always play nicely with inheritance. You can get rid of the error by providing default values for everything, but it is common, and better practice, to simply write your own initializer. Go to the declaration of Spaceship and add an initializer that takes in an argument for each property on Spaceship and sets the properties accordingly. Then create an instance of Spaceship below called falcon. Use the memberwise initializer you just created. The ship's name should be "Falcon." Writing initializers for subclasses can get tricky. Your initializer needs to not only set the properties declared on the subclass, but also set all of the uninitialized properties on classes that it inherits from. Go to the declaration of Fighter and write an initializer that takes an argument for each property on Fighter and for each property on Spaceship. Set the properties accordingly. (Hint: you can call through to a superclass' initializer with super.init after you initialize all of the properties on the subclass). Then create an instance of Fighter below called destroyer. Use the memberwise initializer you just created. The ship's name should be "Destroyer." Now go add an initializer to ShieldedShip that takes argument for each property on ShieldedShip, Fighter, and Spaceship, and sets the properties accordingly. Remember that you can call through to the initializer on Fighter using super.init. Then create an instance of ShieldedShip below called defender. Use the memberwise initializer you just created. The ship's name should be "Defender." Create a new constant named sameShip and set it equal to falcon. Print out the position of sameShip and falcon, then call moveleft() on sameShip and print out the position of sameShip and falcon again. Did both positions change? Why? If both were structs
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
How do I solve this classes exercises using Swift code? Classes 4/4
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY