PackageCom.swift; Public classPhone {PrivateString Pinpai; Private intDianliang; PublicString Getpinpai () {returnPinpai; } Public voidSetpinpai (String pinpai) { This. Pinpai =Pinpai; } Public intGetdianliang () {returnDianliang; } Public voidSetdianliang (intDianliang) { This. Dianliang =Dianliang; } Public voidCheckpower () {if( This. Getdianliang () <20) {System.out.println ("Power is too low, please recharge"); } }}
PackageCom.swift;classtest{ Public Static voidMain (string[] args) {/** Create phone class, the phone class contains the following: * Member properties: *string type of brand *int type of remaining power *set and get method * Non-static no parameter member method with no return value: *checkpower (). In-method implementation: Determine the current object's remaining power, if the remaining power is less than 20, then the console printing "low battery, please charge." * Create test class, complete the following test in the Main method: *a) Create 1 phone objects with the property assigned to: Brand: "IPhone", Power: "15". *B) Call the Checkpower () method with this object after the creation is complete. *ps: Console Print Example*/Phone Phone=NewPhone (); Phone.setpinpai ("IPhone"); Phone.setdianliang (15); Phone.checkpower (); }}
Dark Horse Basic Stage quiz: Create phone class, the phone class contains the following: