1. getter and setter of the attribute
// Set the computing property: it is not a real storage value, but the VaR Subtotal: Double calculated every time using other values {// getter: get the total value through the total and taxpct calculation get {return total/(taxpct + 1)} // setter: updated related values (for example, the value of total and taxpct is set based on newsubtotal) Set (newsubtotal ){//...}}
Ii. tuples | tuples
// Create an unamed tupleslet tipandtotal = (4.00, 25.19) // create a named tupleslet tipandtotalnamed = (tipamt: 4.00, total: 25.19) tipandtotalnamed. tipamttipandtotalnamed. total // create tupleslet tipandtotalnamed :( tipamt: Double, total: Double) = (4.00, 25.19)
Returned tuples
Let Total = 21.19let taxpct = 0.06let subtotal = total/(taxpct + 1) // here, the returned type is func calctipwithtippct (tippct: Double)-> (tipamt: Double, total: double) {Let tipamt = subtotal * tippct let finaltotal = total + tipamt return (tipamt, finaltotal)} calctipwithtippct (0.20)
III,