Question: Using Swift Playgrounds Exercise has three parts: first define class and methods, next use getter and setter methods to set data for the class, and

Using Swift Playgrounds

Exercise has three parts: first define class and methods, next use getter and setter methods to set data for the class, and finally instantiate class and use its methods and properties to get familiar with Classes. As mentioned in class discussion purpose of Object Oriented designs is to encapsulate data or plainly speaking data hiding. You will design a class called Cars. This class will have an array that holds name of the car. In HW 2 we stored car names in an array. Here you will keep array in class. Class have an init method. You can initialize an array here. One of the method you need for Car class is to add car names to the class. You can design method called addCar that accepts string. Method will add name to array. Another method similar to HW 2 will do a query using method called queryCar. You will add third method called reverseIt similar to HW 2, will check if car name is present in the class and reverse it. Add method called print to print name of cars that class holds. From your main function, you need to get class instance and add cars using class method addCar. After adding 5 cars of your choice, use queryCar method to query one car thats present in the class and one that is not. You can Again, you will call this function from your playground main. Provide a name that you would like to query. If car name is present print Query Successful, car name found! And use reverseIt just like HW 2. Finally print whole array using print method of the class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!