Programming 2019/20 Java Coursework: “Smart Home App” Deadline 11 pm, Thursday 14th May 2020 Background A fictional UK-Finnish company, Alikoti, develops eco-friendly smart home technologies. Since...

Smart home application


Programming 2019/20 Java Coursework: “Smart Home App” Deadline 11 pm, Thursday 14th May 2020 Background A fictional UK-Finnish company, Alikoti, develops eco-friendly smart home technologies. Since 1999 they have developed fully integrated Smart Home Solutions. Since 2011 they have begun selling standalone smart home devices, including smart devices, smart lights and smart fridges to be supportedby third-party software. Last year the company made the decision to build their own Smart Home App. The Smart Home App can register devices in a home and control devices. Overview This coursework focuses on the classes required to support the app. It is not concerned with building a front end (i.e. a graphical user interface is not required). All interaction and testing will be carried out in a Java console. The coursework is broken down into several steps, each with accompanying testing. The testing will be used by the assessors to evaluate functionality. The coursework must be developed as a single Netbeans project. The core class for the App is a SmartDevice class. It represents a generic smart device and should have three member variables: a name, a location and a switchedOn value. The switchedOn value refers to whether the device is switched on or off. The location uses the following system: 12.4 12 corresponds to room in house 4 corresponds to wall socket in that room The location, represented by a double, is made of two parts: the integer part (12 in the example above) and a fractional part (4 in the example above). The integer part corresponds to the room in a particular house. The fractional part refers to the actual wall socket in that room that the device is plugged into. Each location is assumed to be unique. The SmartDevice will be managed within a SmartHome class. The SmartHome class provides a number of methods to populate, display, analyse and update values of an array of SmartDevice objects. The SmartHome class will also allow new smart devices to be registered, and control the switchedOn value for all smart devices, both at the home level and at a room level. The SmartDevice class will be extended to add a SmartFridge class and SmartLamp class, both of which have additional properties and behaviours. Core Tasks Step 1 SmartDevice class (SmartDevice.java) 5 marks Tests (Step1.java) 20 marks This step focuses on the design, creation and testing of the SmartDevice class. Assessment of code quality will be based on the SmartDevice class design and code. Assessment of functionality will be based on execution of a separate test class (Step1.java). Design and write the SmartDevice class (SmartDevice.java). This class should have three private member variables: name (String), location (double) and switchedOn (boolean). Name and location member variables should only be accessed and updated through standard get/set methods which you should also write. The switchedOn member variable should only be accessed through switchOn/switchOff/isSwitchedOn methods which you should also write. Design and write a constructor which must allow all three member variables to be populated. Design and write a toString() method. This method should return a well-formatted String containing the variable name-value pairs stored inside the object. For example: Name: device Location:12.1 Switched On: false Create a test script file (Step1.java) to test the SmartDevice class. All test sequences should be placed inside the main() method of this class and use the console for input and output. This class will be executed when we assess the functionality of your work. Your testing must include all of the following tests, one after the other. 1. Create object - a. Create a SmartDevice object with suitable parameter values. b. Use the toString() method to display the object’s data. 2. Create an array of SmartDevices in the main() method - a. Using console input, allow the user to specify the number of Smart Devices to store in an array. Create an array with the given size in main(). Populate each element of the array using a loop and user input for each value. Test that the array is populated correctly by using a loop combined with the toString() method to display the details of all the SmartDevices. (Example output) ---------- -DEVICE 1- ---------- Name: device 1 Location:12.1 Switched On: false ---------- ---------- -DEVICE 2- ---------- Name: device 2 Location:6.2 Switched On: true ---------- ---------- -DEVICE 3- ---------- Name: device 3 Location:1.1 Switched On: false ---------- 3. Update the switchedOn value for one of the devices in the array - a. Allow the user to select an item (SmartDevice) from the array by entering an index value. b. Execute a switchOn() or switchOff() operation on the selected SmartDevice to change the switchedOn value (from true to false, or from false to true). c. Verify that the update procedure worked correctly by using a loop combined with the SmartDevice toString() method to display details of all the SmartDevices. Step 2 SmartHome class (SmartHome.java) 5 marks Tests (Step2.java) 20 marks This step focuses on the design, creation and testing of the SmartHome class. Assessment of the code quality will be based on the SmartHome class design and code. Assessment of functionality will be based on execution of a separate test class (Step2.java). The test script in Step 1 will help you code this step. Design and write the SmartHome class (SmartHome.java). This class should have only one private member variable: an array of SmartDevice objects. Design and write two constructors. The first constructor should take one parameter: a size value. The constructor should create a new instance of the array using the size parameter. The initial array should be unpopulated - it should contain null values at every index. The second constructor should take one parameter: an array of pre-populated SmartDevices. This parameter should be assigned to the member variable. Design and write two insertDevice() methods. The first insertDevice() method should take one parameter: a SmartDevice object. It should insert the SmartDevice at the first empty (null) array position and fail if there is no empty position in the array. The second insertDevice() method takes 3 parameters: name, location and switchedOn, parameters corresponding to the three member variables of the SmartDevice class. It creates a SmartDevice from the parameter values. It should then insert the SmartDevice at the first empty (null) position in the array and fail if there is no empty position. Design and write two getDevice() methods. The first getDevice() method should take one parameter: an index value. It should return the SmartDevice object at the index of the array. If the index is too big or small for the array, or if there is no SmartDevice at the given index, then it should return null. The second getDevice() method should also have one parameter: a location value. The method returns the SmartDevice object at the given location. If no device is at the given location, then it should return null. Design and write a toggle() method. This method takes one parameter: the location (a search parameter). The method attempts to locate the SmartDevice using the location parameter. If it finds a SmartDevice at the location then it should flip the switchedOn value of the SmartDevice (from false to true, or from true to false) Design and write a toString() method. This method should return a well-formatted String containing the name-value pairs of the SmartDevices stored inside the array. If there are empty positions, these should be skipped (not appear in the returned String). For example: ---------- -DEVICE 1- ---------- Name: device 1 Location:12.1 Switched On: false ---------- ---------- -DEVICE 2- ---------- Name: device 2 Location:6.2 Switched On: true ---------- ---------- -DEVICE 3- ---------- Name: device 3 Location:1.1 Switched On: false ---------- Create a test script file (Step2.java) to test the SmartHome class. All test sequences should be placed inside the main() method and use the console for input and output. This class will be executed when we assess the functionality of your work. Your testing must include all of the following tests, one after the other. 1. Create SmartHome object - the first constructor. a. Using console input, ask the user to specify the number of smart devices (size) to be held in the SmartHome object. b. Create a SmartHome object using the size value given by the user. c. Populate the SmartHome object with Smart devices using a loop, user inputs for each new SmartDevice, and the insertDevice() method. d. Verify that the SmartHome is correctly populated using the SmartHome object toString() method. 2. Create SmartHome object - using the second constructor. a. Using console input, ask the user to specify the number of items to be held in an array of SmartDevices. Create the array in main(). Populate each item in the array using a loop and user input for each new SmartDevice object. b. Create a SmartHome object using the populated array. c. Verify that the SmartHome object is correctly populated using the SmartHome object toString() method. 3. Get a device from the SmartHome object using an index and update switchedOn value. a. Ask the user for an index, and using the getDevice() method, return the specific SmartDevice at that index to the main(). b. Execute a switchOn() or switchOff() operation on this SmartDevice to change the switchedOn value (from true to false, or from false to true). c. Verify the values are updated using the SmartHome object’s toString() method. 4. Get a device from SmartHome object using a location and update switchedOn value a. Ask the user for a location and using the getDevice() method, return the specific SmartDevice at that location to the main(). b. Execute a switchOn() or switchOff() operation on this SmartDevice to change the switchedOn value. c. Verify this using the SmartHome object’s toString() method. 5. Locate a device from SmartHome object using a location and toggle the switchedOn value a. Ask the user for a location and using the toggle() method, update the specific SmartDevice at that location to the main(). b. Verify this using the SmartHome object’s toString() method. Step 3 Add functionality to SmartHome Class (SmartHome.java) 5 marks Tests (Step3.java) 15 marks This step focuses on the design, creation and testing of additional functionality to the SmartHome class. Assessment of the code quality will be based on the SmartHome class design and code. Assessment of functionality will be based on execution of a separate test class (Step 3.java). The code should be inserted into the SmartHome class designed, built and tested in step 2. Design and write an addDevice() method. The addDevice takes one parameter: a SmartDevice object
May 09, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here