Write code for the InternetThing class to complete: a. A constructor that accepts a manufacturer and a serial number as its parameter. This constructor performs the following actions: i Store the serial number as a string ii Set a unique id number as an integer(hint- use the nextId). iii Set the IP address to the value “192.168.0.”+idnumber iv Set a local representation of a the power used in mW to the integer 1. v Set the password to “admin”. vi Prints the value “Created ”+ the result of the toString() method after assigning all instance data. vii Increment the number of things on record. b. Accessors for all private variables – Ensure the accessors for id, password and powerUse are named getId(), getPassword() and getPowerUse() c. A method setPassword that accepts a string argument and sets the instance password to the argument. All instance variables, except the password, should be private. The password should be protected. In class SmartHome, method addThing, • Create a refrigerator object by calling the relevant constructor with the following arguments (in order... manufacturer, serialNo, basePower, powerRating, capacity) • Set the value in array things, at the position that matches the ID of the refrigerator ie (rf.getId()), to the refrigerator object. Write code for SmartPhone class which is an InternetThing that includes: a. A constructor which accepts a manufacturer(string), ), a serial number(String) , a model(String) and the number of associated megapixels(int) as its parameters. This constructor shall store the each argument appropriately and will set the phone’s status to locked. After assigning all instance data, the constructor should print the value “Created “+ the result of the toString method. b. A method named setPassword that accepts two strings (old password and new password) as its parameters. The method shall change the password to the new password value only if the old password given as a parameter matches the password stored on the phone, and if the phone is unlocked. If the password is successfully changed, the method will print the value “Successfully changed password for “+ the result of the toString method c. A method named lock that will lock the phone(), and print the value “Locked “+ the result of the toString method. d. A method named isLocked that returns the value true is the phone is locked. e. A method named unlock that accepts a string (the password) as its parameter and unlocks the phone only if the password is correct. If the phone becomes unlocked the method should print “Unlocked “+ the result of the toString method. f. A toString method that returns data in the format "Thing#"+getId()+"::PHONE made by "++":Model="++”@IP:”+getIPAddress(); Write code for a LightBulb class that is an InternetThing which includes: a. A constructor that accepts a manufacturer(String), a serial number(String), and a lumenCount(int) then sets values in the arguments parameter appropriately, and sets a property that reflects whether the light is on to false. After assigning all instance data, the constructor should print the value “Created “+ the result of the toString method. b. A method named turnOn() that turns on the light. The method should then print “Turned on “+ the result of the toString method. c. A method named turnOff() that turns off the light. . The method should then print “Turned off “+ the result of the toString method. d. In class SmartHome, method addThing, at the secton where the argument is checked for “LIGHTBULB”, instantiate a LightBulb with a reference called lb, and then uncomment the lines in the below that add lb to things, then return the id. In class LightBulb, override the method named getPowerUse() that evaluates current power used by the lightbulb as the product of it’s lumenCount and the power use of it’s base class if the light is on. If the light is off, getPowerUse() returns 0. In the Refrigerator class, override the method getPowerUse() so that it returns a value that is equal to basePowerUse+contentSize*rating. In the SmartHome class, Observe the operation of the method showAllItems and then complete the method sumAllPower(). For each item that is assessed while evaluating the total power, the method should print the power used by the item, a tab, and then the result of the toString method. At the end of the calculation, the method should output it’s result in the format "TOTAL POWER = "+sumPower+"mW",where sumPower represents the aggregated power use.
- Write code for the InternetThing class to complete: a. A constructor that accepts a manufacturer and a serial number as its parameter. This constructor performs the following actions: i Store the serial number as a string ii Set a unique id number as an integer(hint- use the nextId). iii Set the IP address to the value “192.168.0.”+idnumber iv Set a local representation of a the power used in mW to the integer 1. v Set the password to “admin”. vi Prints the value “Created ”+ the result of the toString() method after assigning all instance data. vii Increment the number of things on record. b. Accessors for all private variables – Ensure the accessors for id, password and powerUse are named getId(), getPassword() and getPowerUse() c. A method setPassword that accepts a string argument and sets the instance password to the argument. All instance variables, except the password, should be private. The password should be protected.
- In class SmartHome, method addThing, • Create a refrigerator object by calling the relevant constructor with the following arguments (in order... manufacturer, serialNo, basePower, powerRating, capacity) • Set the value in array things, at the position that matches the ID of the refrigerator ie (rf.getId()), to the refrigerator object.
-
Write code for SmartPhone class which is an InternetThing that includes: a. A constructor which accepts a manufacturer(string), ), a serial number(String) , a model(String) and the number of associated megapixels(int) as its parameters. This constructor shall store the each argument appropriately and will set the phone’s status to locked. After assigning all instance data, the constructor should print the value “Created “+ the result of the toString method. b. A method named setPassword that accepts two strings (old password and new password) as its parameters. The method shall change the password to the new password value only if the old password given as a parameter matches the password stored on the phone, and if the phone is unlocked. If the password is successfully changed, the method will print the value “Successfully changed password for “+ the result of the toString method c. A method named lock that will lock the phone(), and print the value “Locked “+ the result of the toString method. d. A method named isLocked that returns the value true is the phone is locked. e. A method named unlock that accepts a string (the password) as its parameter and unlocks the phone only if the password is correct. If the phone becomes unlocked the method should print “Unlocked “+ the result of the toString method. f. A toString method that returns data in the format "Thing#"+getId()+"::PHONE made by "++":Model="++”@IP:”+getIPAddress();
-
Write code for a LightBulb class that is an InternetThing which includes: a. A constructor that accepts a manufacturer(String), a serial number(String), and a lumenCount(int) then sets values in the arguments parameter appropriately, and sets a property that reflects whether the light is on to false. After assigning all instance data, the constructor should print the value “Created “+ the result of the toString method. b. A method named turnOn() that turns on the light. The method should then print “Turned on “+ the result of the toString method. c. A method named turnOff() that turns off the light. . The method should then print “Turned off “+ the result of the toString method. d. In class SmartHome, method addThing, at the secton where the argument is checked for “LIGHTBULB”, instantiate a LightBulb with a reference called lb, and then uncomment the lines in the below that add lb to things, then return the id.
- In class LightBulb, override the method named getPowerUse() that evaluates current power used by the lightbulb as the product of it’s lumenCount and the power use of it’s base class if the light is on. If the light is off, getPowerUse() returns 0.
- In the Refrigerator class, override the method getPowerUse() so that it returns a value that is equal to basePowerUse+contentSize*rating.
- In the SmartHome class, Observe the operation of the method showAllItems and then complete the method sumAllPower(). For each item that is assessed while evaluating the total power, the method should print the power used by the item, a tab, and then the result of the toString method. At the end of the calculation, the method should output it’s result in the format "TOTAL POWER = "+sumPower+"mW",where sumPower represents the aggregated power use.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps