Do the following using Swift Xcode project (using macOS and choosing option/tab: Command line Tool): Create a class CarLoan (store it in a separate file – CarLoan.swift) which is having the following: Loan number, customer name, yearly interest rate, loan amount and duration (time period) as stored properties Define private setter for loan number and customer name Loan amount should not be negative or zero Interest rate should be positive and between 1.0% and 4.0 %. Default – 1.0% Time duration cannot be negative and cannot be more than 7 years. Min – 3 years You need to define property observers – didSet for interest rate, loan amount and time duration. Down payment should be at least 10% of loan amount or more but it cannot be equal to loan amount. Define it as computed property. Define two initializers, one which initializes all the properties to their default values and one which initializes to appropriate values. Define a Print as computed property which display all the instance data member’s values of loan object. This should be defined in the class extension file – CarLoanExtensions.swift. And a convenience initializer which only initializes loan number and customer name and loan amount. It should be defined in the class extension file – CarLoanExtensions.swift Define one function- CalculateMonthlyInstallment() --> Double which is used for calculating the monthly installment on the loan amount based on the rate and time. Use formula: Interest = (loan amount – down payment) * rate * time / 100. Monthly Installments = ((loan amount – down payment) + Interest)/ (time * 12) Test the above class in main.swift file by creating at least two objects of CarLoan and test its capabilities.
Do the following using Swift Xcode project (using macOS and choosing option/tab: Command line Tool): Create a class CarLoan (store it in a separate file – CarLoan.swift) which is having the following:
Loan number, customer name, yearly interest rate, loan amount and duration (time period) as stored properties
Define private setter for loan number and customer name
Loan amount should not be negative or zero
Interest rate should be positive and between 1.0% and 4.0 %. Default – 1.0%
Time duration cannot be negative and cannot be more than 7 years. Min – 3 years
You need to define property observers – didSet for interest rate, loan amount and time duration.
Down payment should be at least 10% of loan amount or more but it cannot be equal to loan amount. Define it as computed property.
Define two initializers, one which initializes all the properties to their default values and one which initializes to appropriate values.
Define a Print as computed property which display all the instance data member’s values of loan object. This should be defined in the class extension file – CarLoanExtensions.swift.
And a convenience initializer which only initializes loan number and customer name and loan amount. It should be defined in the class extension file – CarLoanExtensions.swift
Define one function- CalculateMonthlyInstallment() --> Double which is used for calculating the monthly installment on the loan amount based on the rate and time. Use formula: Interest = (loan amount – down payment) * rate * time / 100. Monthly Installments = ((loan amount – down payment) + Interest)/ (time * 12)
Test the above class in main.swift file by creating at least two objects of CarLoan and test its capabilities.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images