Question: Create a Swift class named Cash your playground. The class contains the following elements: A Double stored property that contains the amount of money (dollars
Create a Swift class named Cash your playground. The class contains the following elements: A Double stored property that contains the amount of money (dollars and cents) described by an object of the class. A computed property. o Define a getter that calculates and returns the minimum number of U.S. bills and coins that add up to the amount found in the Double stored property. The return value is an Int array of length 9 that contains (beginning with index 0 of the array) the number of $50 bills, $20 bills, $10 bills, $5 bills, $1 bills, 25 coins, 10 coins, 5 coins, and 1 coins. For example, if the stored property contains 47.23, the return value is: [0, 2, 0, 1, 2, 0, 2, 0, 3] However, if the amount found in the stored property is negative, return an empty array (representing an error). o Define a setter that expects as its input an Int array of length 9 that represents a count of bills/coins of each denomination listed above. It calculates the amount represented by the array and assigns the result to the Double stored property. For example, if the input to the setter is [0, 2, 0, 1, 2, 0, 2, 0, 3], then the amount assigned to the Double stored property: 47.23 However, if the length of the input Int array does not have a length equal to 9, assign a value of -1 (representing an error) to the Double stored property.
An initializer with one Double parameter; it assigns the parametric value to the Double stored property. An initializer with no parameters; it assigns a value of zero to the Double stored property. 3. At the bottom of the playground, test your class: o Define 6 variables of type Cash. Initialize one to a negative number; initialize another to zero by not specifying a parameter to the initializer; initialize the remaining variables to random-ish amounts in the range of 0 < amount <= 100. o Print the values returned by the getter for each of the Cash variables. o Define 6 Int array variables. The first should be of length 6. The other five are of length 9 and contain random-ish non-negative values in the range of 0 <= amount <= 100. o Use the 6 Int array variables to assign values to the 6 Cash variables defined earlier, via the setter. o Print the values returned by the getter for each of the Cash variables.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
