Mobile Apps Development XCODE

Question

  1. Create a “Car” class with the following criteria:

    1. Properties (5)

      1. year – initialized by initializer

      2. make – initialized by initializer

      3. model – initialized by initializer

      4. color – initialized by initializer

      5. currentSpeed – initialized to 0 by initializer

 

    1. Functions (5)

      1. init(year: Int, make: String, model: String, color: String) – Initializer function that sets year make model color based on user input and sets currentSpeed to 0.

           

      1. changeSpeed(to speed: Int) -> String– This function will change the property “currentSpeed” to whatever speed parameter is provided to it.   NOTE: the function will not change the speed directly it must decide if the provided speed is greater or lesser than current speed and then call either “hitTheGas” if the car needs to speed up, or “pumpTheBreaks” if the car needs to slow down. The function should return a string message like: “The car sped up by _ miles”, “The car slowed down by _ miles”, “The car didn’t change its speed” or “The car stopped”.

 

      1. hitTheGas(to speed: Int) -> Int This function accepts an integer and changes the current speed to the speed that was passed to the function ONLY of the provided speed is GREATER than the current speed.  If the speed provided is less than the current speed the function should not change the current speed.

 

 

      1. pumpTheBreaks(to speed: Int ) -> Int - This function accepts an integer and changes the current speed to the speed that was passed to the function ONLY of the provided speed is LESS than the current speed.  If the speed provided is greater than the current speed the function should not change the current speed.  

 

      1. stopTheCar() – This function changes the currientSpeed to 0

  1. (30pts) Create a sub class “Batmobile” that inherits from the Car class

    1. Properties will remain unchanged

    2. Functions

      1. Override the init() function so that it only accepts year as input the rest of the attributes should be automatically initialized as such:

        1. make – Bat Automotive

        2. model – Batmobile

        3. color – Black

        4. currentSpeed – 100

 

      1. shootMachineGun() -> String – This is a function of the Batmobile that returns a string: “Bang Bang Bang”

 

  1. (20pts) Create an array named “carCollection” and add 3 cars to it, 2 regular cars and 1 Batmobile. HINT: you must create Car variables to add to the array.

 

  1. Extra Credit (10pts) Create a loop that iterates over the array and prints the makes and models of each car to the console:

           

            Example console output:       

                        Honda Accord

                        Bat Automotive Batmobile

                        Nissan Altima

Details
Purchase An Answer Below

Have a similar question?