Objectives – learn/practice the following new concepts:
Be able to declare a new class.
Be able to write a constructor.
Be able to instantiate an object.
Be able to use calls to instance methods to access and change the state of an Object.
Be able to create an array of objects and fill it from a file or the user input.
Be able to search in or sort an array of objects.
All manufacturers have the same basic elements in the televisions they produce as well as many options. This project works with a few basic elements that are common to all televisions. Think about a television in general. It has a brand name (i.e. it is made by a specific manufacturer). The television screen has a specific size. It has some basic controls. There is a control to turn the power on and off. There is a control to change the channel. There is also a control for the volume. At any point in time, the television’s state can be described by how these controls are set.
INPUT DATA FILE: TVs.csv . The 1st record is a “header record” containing the field-identifiers – skip over this record. The remaining records each contain the following fields in this order:
This program has 2 separate classes (each in its own .java file). These all contain just non static methods.
1. Controller class:
MAIN PROGRAM of controller class contains the overall controller of the whole program. In the main program of this class create an array of objects for Television class called ArrayofTVs with a specific size, Since program does NOT know how many input data records there will be ahead of time, the array sizes should all be “plenty big” (of size MAX_N = 100). HOWEVER, when reading in the data, keep track of counter, and use n (and not array’s length) to do any processing. The program should read all the records from TVs.csv file into ArrayofTVs array of objects. The attributes of each record would be stored into the corresponding fields of an object of ArrayofTVs.
AddNewTelevision method: this method ask the user to input the information about a TV (Manufacturer, ScreenSize, PowerOn, Channel, and Volume) and add it as a new element into ArrayofTVs.
The main method should also call the methods from the television class to change the state of (PowerOn, Channel, or Volume) for some or all objects.
Sort method: this method sorts the ArrayofTVs by the screenSize field using either insertion or selection sort. As you sort the screenSize make the same changes in the other corresponding fields to reflect the sorting.
Search method: Search for a specific television from the ArrayofTVs according to manufacturer attribute, the method return an array of television object for a specific manufacturer and print all the elements of the returned array of television object into the console screen, otherwise return null if there is nothing matches as a manufacturer to be searched for in the ArrayofTVs.
PrintToFile method: this method writes the contents of ArrayofTVs after the changes that you made in the previous steps into a .csv file.
2. Television class. Each object that is created from the television class must be able to hold information about that instance of a television in fields. So a television object will have the following attributes:
manufacturer. The manufacturer attribute will hold the brand name. This cannot change once the television is created, so will be a named constant.
screenSize. The screenSize attribute will hold the size of the television screen. This cannot change once the television has been created so will be a named constant.
powerOn. The powerOn attribute will hold the value true if the power is on, and false if the power is off.
channel. The channel attribute will hold the value of the station that the television is showing.
volume. The volume attribute will hold a number value representing the loudness (0 being no sound).
These attributes become fields in the Television class.
The television object will also be able to control the state of its attributes. These controls become methods in the class.
Constructor methods that will be used to create an instance of a Television. The class should have a default and parametrized constructors.
setChannel. The setChannel method will store the desired station in the channel field.
power. The power method will toggle the power between on and off, changing the value stored in the powerOn field from true to false or from false to true. This can be accomplished by using NOT operator(!). if the Boolean variable powerOn is true, then !powerOn is false and vice versa.
increaseVolume. The increaseVolume method will increase the value stored in the volume field by 1.
decreaseVolume. The decreaseVolume method will decrease the value stored in the volume field by 1.
getChannel. The getChannel method will return the value stored in the channel field.
getVolume. The getVolume method will return the value stored in the volume field.
getManufacturer. The getManufacturer method will return the constant value stored in the MANUFACTURER field.
getScreenSize. The getScreenSize method will return the constant value stored in the SCREEN_SIZE field.
OUTPUT REPORT FILE: OutputReport.csv – looks like the following:
NOTE: it is not necessarily the same contents and ordering sequence, this just shows you the required formatting.