Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write code for the InternetThing class to complete: private String manufacturer, serialNumber, ipAddress; private static int nextId =0; private int numThings =0; private int

1. Write code for the InternetThing class to complete:
private String manufacturer, serialNumber, ipAddress;
private static int nextId =0;
private int numThings =0;
private int id;
private int powerUse =0;
protected String password;
public InternetThing(){}
//Complete InternetThing ()
public InternetThing(String manufacturer, String serial){
}
public int getId(){
return id;
}
public String getManufacturer(){
return manufacturer;
}
public String getIPAddress(){
return ipAddress;
}
public int getPowerUse(){
return powerUse;
}
public static int getNumThings(){
return numThings;
}
public String toString(){
return "Thing#"+getId()+":made by "+ manufacturer+"@IP:"+ipAddress;
}
2.
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 127.0.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.
3. 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 phones 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();
4. 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.
5. In class LightBulb, override the 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.
6. In the Refrigerator class, override the method getPowerUse() so that it returns a value that is equal to basePowerUse+contentSize*rating.
7. 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.
image text in transcribed
image text in transcribed
image text in transcribed
Sample Input 6 Sample Output 6 Created Thingtbimade by BesehEteIP 4192,168,0, Created Thinga1: made by BASElitTe1P:192, 168,0., 1 ThingNa saade by BASENETCIP:192,168.0.0 ThingAtiande by BASENETeIPi 192,168,8.1 Created Thingt2t:REFRIGERATOA, made by MAeE: BasePowerne. I Rat ing - .0@P? 192,168.0.2 Created Thingt2::REFRICERSTOR, made by MubE: BasePower =168. ArRating =5.891P7192.16B+0.2. Inserted to Thing72: ReffriceltATd, nade by MABC: BasePower ie1.0:Rating=5. DeIP:192.165.0.2 Inserted to Thingz2i:REFRIGEAATOR, made by MABE: Base Power =190,0R Rat ing=5, 991P 192,168,9,2 fenoved fron Thingt2trREFRIGERATOR, made by MaBe: Base Power 100 , 0: Rat ing 5,09IP:192,165,0,2 Inserted to Thingz2; REFFLIGEHATOA, wade by MABE : BasePower=160.6:Rating=5. GetP:192, 16s.,, 2. 2600nk Thingh2: REFRIGERATOR, nade by ME: BasePower 196.9t Rating 5 . 9etpl 192.168.0.2. Created Thing 3 : LPHoNE made by Sansung Model=nul1e2p:192+168,e+3 Created Thingiat:PhoNE made by SansungtModetnGataxye1p:192.16d.0.3 1mh Thing a3: PHONE nade by Santing:Model=CalaxyeIP:192,16s,0,3 Created Thingr4: PHONE made by Motorolac Model=nulletPr 192.168.0.4 Created Thingr4::PHowe made by Motorola: Modeti=5torne1p:192, 168,0,4 Unlecked Thingt4z: Prove nade by Motorolas ModeL-5torneIP 192.16a.0.4 Successfully changed password for Thingt4zapHove nade by Motorola: Model=5toracip:192,168.0.4 Successfulty changed password for Thinginta PwouE made by Moterola: Model*Storadp:192,168,0,4 Locked Thingz4 1 P PHONE nade by MotorolazModel=5torne1P:192.165:6.4 successfutty changed passmord for Thingris: pPhoNE nade by Motorola: Modetw 5 tormeIP: 192, 168,0.4 Unlocked Thinge4z PHHyE nade by Motorola:Model=5tornetP1192.168.0.4 Successfulty changed password for Thinga4faPHoNE adde by Motorola: ModeloStormeIp:192,168,0,4 Created Thing 5: : PHONE made by Alcatela Model=Lynnytp:192+169+6.5 Unlecked Thinge5: Rhont nade by Alcatel;Medel-Lymxetp:192.168.0.5 1nk Thinga5: PHowe nade by AleatelsModel=LynxeIP:192,168.0.5 Created Thingt 61 made by BULBKAKEReIP 192.168,0,6 Greated Thing 7 : made by BelbMAKERe1P?192. 168.6.6 Tuened on Thinghistnade by BULMakERgIP 192.168.0.6 Created Thing 7imade by ButnikakeReIP:192,168,, 7 Created Thingr7: made by BULBMAKERCIP 192.168.6.7 Turned on Thineatinade by Butexaktnd1P:192.168.0.7 Turned off Thingn7 smade by BULBMAKERe1p:192.165.0.7 Tursed on ThingA7tnade by BuL8mukeReIP 192,168.6.7 Turned off Thine;7anade by bULeMakerelp?192,168. +, Thing a :ade by BASENETQIP :192,164,0,0 Thinga 1 taade by BASENETQIP: 192.168,8.1 Thimgaz: inefRICERATOR, made by Mae: BasePower 100 .0: Rat ing 5 . eeIP: 192.168.0.2 Thing 3 : PHCAE made by Samsung: ModelaCalaxyelpz192,165.0.3 Thinez4: : PHoUE made by Motorota:Modet=\$tormeIPy192.16.5, e.4 ThingA 5 : P4CME made by Alcateli ModelalynweIP : 192.16. 0.5 Thingf6;aade by BuLmkkepoIP:192,164,0,6 Thinga7tande by But bxakteng IP: 192,168.9.7 1. Thingreanade by aASENETPIP:192.168.0.0. 1 Thing 1 znade by BASENETeIP: 192.168.6.1 260e Thing2: AREFRICEICATOH, nade by Muec: BasePower 100. -eRating=5. eeIP:192,16s.0.2 1 Thing 2;: Phawf made by 5 antung : Model-GalaxyeTP:192, 160,0,2 Thingw4; tPHone made by Motorolazkodet=5tornPtP.192.168.6.4 1 Thingw5; :Phant sade by Alcatel:Model=Lynxetp:192.168,0.5 100 Thinga6:nade by BULEMAKEReIP:192,168.0.6 (9) Thing=7 inade by BULEMAKEROIP: 192+163,9.7 TOTAL POWER = 2765 nWW 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 loT 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions