title | type | duration | creator | ||||
---|---|---|---|---|---|---|---|
Creating Classes |
lab |
1:30 |
|
There is no starter code. Create a new project in IntelliJ for this lab
Note: This can be a pair programming activity or done independently.
In this lab you will be using your knowledge of classes, subclassing, interface and abstract class creation and implementation to create a few classes that will be used in the main method.
This looks like a lot. It is, but it is a lot of repetition.
-
Create an abstract class called
Remote
. -
Give the abstract class the property needsBatteries and supportsUsb.
-
Create a constructor that accepts parameters to set the properties you just created.
-
Create getters and setters for the properties.
-
Declare the following abstract methods,
channelUp
,channelDown
,volumeUp
,volumeDown
; they all take no parameters and return nothing. -
Implement
powerButtonPressed
that does not take any parameters and just prints out that the power button was pressed. -
Implement
numberButtonPressed
, that takes in anint
parameter and appends/concatenates theint
parameter to theString
"Changing channel to "
then prints it out to the terminal.
-
Create an interface class named
WaterProof
. -
Inside this class, declare a method
isWaterProof
. What do you think it should return? -
Create an interface class named
Rechargeable
. -
Inside this class, declare a method
isRechargeable
. What do you think it should return? -
Create an interface class named
Universal
. -
Inside this class, declare a method
supportsBrands
. It should return nothing.
-
Create three concrete classes that extends the abstract class
Remote
, name the concrete class one of your favorite brands. (Samsung, LG, Panasonic, Sony, etc.) -
Implement the methods you declared in the
Remote
abstract class which are required to be implemented in each concrete class. -
Make sure the implementations output something different for each concrete class.
-
Implement the
WaterProof
,Rechargeable
, andUniversal
interfaces. -
Implement the methods defined by those interfaces. You can choose what to do, but at the minimum print something out to the terminal.
-
Create a
List
ofRemote
objects. -
Populate the
List
ofRemote
objects with new instances of the concrete classes you created. -
Create a loop that loops as many times as there are items in the
List
ofRemote
objects. (You choose the kind of loop) -
Inside the loop call the
numberButtonPressed
method on each object and pass it the current iteration value of the loop. -
Inside the loop call the
channelUp
,channelDown
,volumeUp
,volumeDown
methods on each object.
Bonus:
-
Create 3 more concrete classes that extend
Remote
and use them in the loop. -
Create another interface,
FingerPrintScanner
, and declare a methodstartScan
that accepts aString
parameter. -
In your classes, implement logic for the
startScan
method that will let you use the remote only when the correct input is given.
Pull request from forked Project on GitHub that contains your implementation of the Remote
abstract class, the WaterProof
, Rechargeable
, and Universal
interface classes, and the main program that uses the classes you created.
- Oracle: Creating abstract classes
- Oracle: Creating an Interface
- Oracle: Defining a class
- Oracle: Instantiating a class