# Build A Droid ## Project Overview: We've set up a robot workshop to build some droids. All that's missing are the instructions on how to create the robots and what they'll do. Can we write a Java class to help? We'll nee to define the state and behavior of the droids using instance fields and methods. Let's get to work! We want each Droid to have the following state: * name * battery level and the following behavior: * perform a task * state its battery level --- ## Project Instructions: ### Defining a Droid 1. The Droid.java file is empty. Start by defining the class ``Droid``. 2. Add a ``main()`` method! You can leave it empty for now. 3. Declare an instance field called ``batteryLevel``. We want to store whole number values in this field. 4. Declare another instance field called ``name`` which will store our droid's name. What type should this be? 5. Create a constructor method for the ``Droid`` class. The method should have one parameter of ``String droidName``. 6. Inside the constructor, assign the parameter value of ``droidName`` to the appropriate instance field. 7. Set the value of ``batteryLevel`` to ``100``. Every new instance of ``Droid`` will have a batteryLevel of ``100``. ### Declaring Instances of Drone 8. Inside ``main()``, create a ``new`` instance of ``Droid`` named ``"Codey"`` 9. Print out the variable using ``System.out.println()``. 10. That output isn't very informative! Define a toString() method within Droid. The return type is ``String``. 11. Inside ``toString()``, ``return`` a string that introduces the ``Droid`` using their name. Something like *"Hello, I'm the droid: droidNameHere".* ### Doing Droid Things 12. Define a new method: ``performTask()``. This method should have a single parameter: ``String task``. This method does not return any value. 13. Inside ``performTask()``, print a statement like: "``name`` is performing task: ``task``". For example, ``codey.performTask("dancing");`` will print: ![](https://i.imgur.com/YglaFRP.png) 14. Performing tasks is hard work. After the print statement, set ``batteryLevel`` to be ``10`` less than it was before. We'll need to reassign the instance field to be the current valus minus 15. Now have Codey complete each of the following tasks. Inside ``main`` call the ``performTask()`` method to have Codey: 1. cook dinner 2. solve a math problem 3. learn to code in Java 16. That was a lot of work! As Codey performs tasks, we'll want to know how much battery is left. Define a new method called ``energyReport()``. This method should have no parameters and return a ``String``. 17. Inside ``energyReport()``, return a ``String`` that reports the Droid's battery level. Something like: *"``name``'s battery level is: batteryLevelHere".* 18. Now, in main, call the ``energyReport()`` method and print the result to report Codey's battery level. ---