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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question
100%
  1. 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.
  2. 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 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();

  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 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.
  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 it’s result in the format "TOTAL POWER = "+sumPower+"mW",where sumPower represents the aggregated power use.
 
 
49
50
51
52 //QUESTION 3. Create class SmartPhone
53 //Pass case2 by completing SmartPhone
54 class SmartPhone extends InternetThing{
55
56
NAASTGOI88688RFNAFR8=:::::>:=:====D1
57 boolean locked;
58
59 public SmartPhone (String manufacturer, String serialNumber, String model, int megaPixels) {
62
60 }
63
65
66
64- public void unlock(String pw) {
}
67
69
70
71
72 }
73
76
74 //QUESTION 4. Create class Light Bulb
78
75 //Pass case3 by completing Light Bulb
79
77 -class LightBulb extends InternetThing{
80 -
82
83
84
85
87
89
90
91
92
93
94
95
96
97
98
}
99
100
101
102
String model;
int megaPixels;
103
104
105
106
107
108
109
110
public void lock() {
}
111
112
113
114
115
116
117
118
119
public void setPassword (String oldPassword, String newPassword) {
}
}
int lumenCount;
boolean lighton;
public void turnon () {
}
public void turnOff() {
}
public Light Bulb (String manufacturer, String serialNumber, int lumenCount) {
}
///* UNCOMMENT AFTER IMPLEMENTING InternetThing
class Refrigerator extends InternetThing {
double basePower;
double powerRating;
int capacity;
int contents = 0;
public Refrigerator (String manufacturer, String serialNumber,
double basePower, double power Rating, int capacity)
{
}
super (manufacturer, serialNumber);
this.basePower basePower;
this.powerRating powerRating;
this.capacity= capacity;
this.contents = 0;
System.out.println("Created "+this.toString());
public void insertItem(int size)
{
if (contents+size<capacity)
{
contents+ size;
System.out.println("Inserted to "+ this.toString());
Transcribed Image Text:49 50 51 52 //QUESTION 3. Create class SmartPhone 53 //Pass case2 by completing SmartPhone 54 class SmartPhone extends InternetThing{ 55 56 NAASTGOI88688RFNAFR8=:::::>:=:====D1 57 boolean locked; 58 59 public SmartPhone (String manufacturer, String serialNumber, String model, int megaPixels) { 62 60 } 63 65 66 64- public void unlock(String pw) { } 67 69 70 71 72 } 73 76 74 //QUESTION 4. Create class Light Bulb 78 75 //Pass case3 by completing Light Bulb 79 77 -class LightBulb extends InternetThing{ 80 - 82 83 84 85 87 89 90 91 92 93 94 95 96 97 98 } 99 100 101 102 String model; int megaPixels; 103 104 105 106 107 108 109 110 public void lock() { } 111 112 113 114 115 116 117 118 119 public void setPassword (String oldPassword, String newPassword) { } } int lumenCount; boolean lighton; public void turnon () { } public void turnOff() { } public Light Bulb (String manufacturer, String serialNumber, int lumenCount) { } ///* UNCOMMENT AFTER IMPLEMENTING InternetThing class Refrigerator extends InternetThing { double basePower; double powerRating; int capacity; int contents = 0; public Refrigerator (String manufacturer, String serialNumber, double basePower, double power Rating, int capacity) { } super (manufacturer, serialNumber); this.basePower basePower; this.powerRating powerRating; this.capacity= capacity; this.contents = 0; System.out.println("Created "+this.toString()); public void insertItem(int size) { if (contents+size<capacity) { contents+ size; System.out.println("Inserted to "+ this.toString());
123
124
125
126
127-
128
138
139
140
141
142
143
129
130
131
132
133
134
135 public String toString()
136
{
137
154
155
156
157
158
159
160
161
162
163
164
public void removeItem(int size)
{
144
145 }
146
147 //*/
165
166
167-
168
169
170
171
172
173
174
175
176
177 -
178
179
180
181
182
183
184
185
186
187
}
188
189
if (contents-size>0)
{
contents--size;
148 class SmartHome {
149
150
151
152
153
System.out.println("Removed from "+ this.toString());
}
"+getManufacturer
}
return "Thing#"+getId() +":: REFRIGERATOR, made by
//QUESTION 5. Overload getPowerUse() in Refrigerator
//Pass case4 by completing getPower Use here
}
()+":BasePower="+basePower+":Rating="+powerRating+"@IP:"+getIPAddress();
InternetThing baseAddress, router;
private final int MAX THINGS = 252;
int numThings =0;
public InternetThing[] things = new InternetThing [MAX_THINGS];
//NB Making "things" public violates the principle of self-governing classes, but without additional knowledge that
will be gained in coming weeks, this is the available strategy to aggregate a group of related sub-classes
public SmartHome ()
{
InternetThing baseAddress = new InternetThing("BASENET","Nee");
InternetThing router = new Internet Thing ("BASENET","N01");
things [0]=baseAddress;
things [1]=router;
//numThings=2;
System.out.println (baseAddress.toString());
System.out.println(router.toString());
public int addThing (String[] args)
{
int returnval=-1;
//TO HELP YOUR DEBUGGING IF NECESSARY
//String argList="";
//for (int i=0; i< args.length; i++)
System.out.println(i+":"+args[i]);
if (args[0].equals("REFRIGERATOR"))
{
String manufacturer = args[1];
String serialNo= args[2];
int basePower = Integer.parseInt(args[3]);
int powerRating Integer.parseInt(args[4]);
int capacity= Integer.parseInt(args [5]);
//Pass case 1 by instantiating Refrigerator as rf
//1. Create a refrigerator object by calling the relevant constructor with the following arguments
(in order... manufacturer, serialNo, basePower, powerRating, capacity)
//2. Set the value in array things, at the position that matches the ID of the refrigerator ie
(rf.getId()), to the refrigerator object.
//Uncomment below after instantiating a Refrigerator
//returnval= rf.getId();
}
if (args[0].equals("SMARTPHONE"))
Transcribed Image Text:123 124 125 126 127- 128 138 139 140 141 142 143 129 130 131 132 133 134 135 public String toString() 136 { 137 154 155 156 157 158 159 160 161 162 163 164 public void removeItem(int size) { 144 145 } 146 147 //*/ 165 166 167- 168 169 170 171 172 173 174 175 176 177 - 178 179 180 181 182 183 184 185 186 187 } 188 189 if (contents-size>0) { contents--size; 148 class SmartHome { 149 150 151 152 153 System.out.println("Removed from "+ this.toString()); } "+getManufacturer } return "Thing#"+getId() +":: REFRIGERATOR, made by //QUESTION 5. Overload getPowerUse() in Refrigerator //Pass case4 by completing getPower Use here } ()+":BasePower="+basePower+":Rating="+powerRating+"@IP:"+getIPAddress(); InternetThing baseAddress, router; private final int MAX THINGS = 252; int numThings =0; public InternetThing[] things = new InternetThing [MAX_THINGS]; //NB Making "things" public violates the principle of self-governing classes, but without additional knowledge that will be gained in coming weeks, this is the available strategy to aggregate a group of related sub-classes public SmartHome () { InternetThing baseAddress = new InternetThing("BASENET","Nee"); InternetThing router = new Internet Thing ("BASENET","N01"); things [0]=baseAddress; things [1]=router; //numThings=2; System.out.println (baseAddress.toString()); System.out.println(router.toString()); public int addThing (String[] args) { int returnval=-1; //TO HELP YOUR DEBUGGING IF NECESSARY //String argList=""; //for (int i=0; i< args.length; i++) System.out.println(i+":"+args[i]); if (args[0].equals("REFRIGERATOR")) { String manufacturer = args[1]; String serialNo= args[2]; int basePower = Integer.parseInt(args[3]); int powerRating Integer.parseInt(args[4]); int capacity= Integer.parseInt(args [5]); //Pass case 1 by instantiating Refrigerator as rf //1. Create a refrigerator object by calling the relevant constructor with the following arguments (in order... manufacturer, serialNo, basePower, powerRating, capacity) //2. Set the value in array things, at the position that matches the ID of the refrigerator ie (rf.getId()), to the refrigerator object. //Uncomment below after instantiating a Refrigerator //returnval= rf.getId(); } if (args[0].equals("SMARTPHONE"))
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,