Question: Input Format The first line of input represent t , the number of InternetThings to be added. Each InternetThing is a member of the set
Input Format
The first line of input represent t, the number of InternetThings to be added. Each InternetThing is a member of the set {REFRIGERATOR,SMARTPHONE, LIGHTBULB}. For each InternetThing the parameters sufficient to describe it are placed on the same line, and the following line specifies an integer a, the number of actions to be carried out on the InternetThing. Each action specifies it's required parameters.
After all InternetThings have been defined, the testcase closes with a symbol SMARTHOME, and a set of subsequent actions. The line following SMARTHOME contains an integer s, which describes the number of actions that will be applied to the SmartHome.
Constraints
t
part 1. THE BASE CLASS FOR InternetThing
Note that the superclass to InternetThing is Object. Write code for the InternetThing class to include:
a. A default constructor, as well as
b. A constructor that accepts string values manufacturer and serial number as parameters. This constructor performs the following actions:
i Store the serial number and the manufacture
ii Set a unique id number as an integer, where each successive InternetThing created has a consecutively increasing id number. The id number of the first InternetThing created is 0.
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 Prints the value Created + the result of the toString() method after assigning all instance data.
vi. Set the password to "admin".
c. Create the following accessors:
String getSerialNo()- *returns a serial number stored on the InternetThing* String getManufacturer()-*returns a manufacturer stored on the InternetThing* String getPassword()- *returns a password stored on the InternetThing* int getPowerUse()- *returns the power use stored on the InternetThing* int getId()- *returns the id stored on the InternetThing* d. A method setPassword that accepts a string argument and sets the instance password to the argument.
e. A toString() method that returns the string Thing #+getId()+:made by + manufacturer+@IP:+IPAddress,
f. A public static method named getNumThings(), which displays the total number of things that have been created.
g. All instance variables, except the password, should be private. The password should be protected.
Uncomment all the currently commented lines in SmartHome class
Note the SmartHome class contains a method called addThing which accepts an array of strings as an argument, and then creates an instance of a derived class of InternetThing and adds it to an array. To allow test case 2 to pass, uncomment the lines in the addThing method of SmartHome that allow an instance of a Refrigerator to be created.
part 2:SmartPhone - A DERIVED CLASS
Write code for SmartPhone class which is an InternetThing that includes:
a. A constructor which accepts as arguments 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 phones status to locked(You need to decide how the phone will represent it's locked status). 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 "+getManufacturer()+ ":Model=" +getModel()+ @IP: +getIPAddress();
Uncomment the lines in the addItem method of the SmartHome class that allows an instance of a SmartPhone to be added.
part 3:LightBulb - ANOTHER DERIVED CLASS
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 turn off the light. After assigning all instance data, the constructor should print the value Created + the result of the toString method.
b. A method named getPowerUse() that evaluates current power used by the lightbulb as the product of its lumenCount and the power use of its base class if the light is on. If the light is off, getPowerUse() returns 0.
c. A method named turnOn() that turns on the light. The method should then print Turned on + the result of the toString method.
d. A method named turnOff() that turns off the light. The method should then print Turned off + the result of the toString method.
Uncomment the lines in the addItem method of the LightBulb class that allows an instance of a LightBulb to be added.
part 4:ADDITIONAL OVERRIDING
In the Refrigerator class, override the method getPowerUse() so that it returns a value that is equal to sum of the basePowerUse and the product of the capacity and the rating.
part 5:AGGREGATE POWER
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 its result in the format "TOTAL POWER = "+sumPower+"mW",where sumPower represents the aggregated power use.
The internet of things, or IoT, is a system of interrelated computing devices, mechanical and digital machines, objects, animals or people that are provided with unique identifiers (UIDs) and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction. IoT concepts have enabled actualization of SmartHome, which allow common devices within a home to incorporate processing and communication capability, and together these devices are should be able to increase the satisfaction of the user. Examples of IoT devices that could be in a home could include a refrigerators, a light bulbs and smart phones. For this lab you will create a set of classes that can model a smart home, using the concepts of inheritance and aggregation
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
