Coder Social home page Coder Social logo

build-a-driod's Introduction

Defining a Droid 1. The Droid.java file is empty.

Start by defining the class Droid.

Don’t forget to include a main() method! You can leave it empty for now.

We want a Droid object that has the following state:

name battery level and the following behavior:

performing a task stating its battery level

Stuck? Get a hint 2. Declare an instance field called batteryLevel. We want to store whole number values in this field.

Stuck? Get a hint 3. Declare another instance field called name which will store our droid’s name.

What type should this be?

Stuck? Get a hint 4. Create a constructor method for the Droid class.

The method should have one parameter of String droidName.

Stuck? Get a hint 5. Inside the constructor, assign the parameter value of droidName to the appropriate instance field.

Set the value of batteryLevel to 100. Every new instance of Droid will have a batteryLevel of 100.

Stuck? Get a hint Declaring Instances of Drone 6. Inside main(), create a new instance of Droid named "Codey".

Stuck? Get a hint 7. Print out the variable using System.out.println().

Stuck? Get a hint 8. That output isn’t very informative!

Define a toString() method within Droid.

The return type is String.

Inside toString(), return a string that introduces the Droid using their name.

Something like “Hello, I’m the droid: droidNameHere”

Stuck? Get a hint Doing Droid Things 9. Define a new method: performTask(). This method should have a single parameter: String task.

This method does not return any value.

Stuck? Get a hint 10. Inside performTask(), print a statement like “name is performing task: task“.

For example, codey.performTask("dancing"); will print:

Codey is performing task: dancing 11. 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 value minus 10.

Stuck? Get a hint 12. Have your Droid instance perform some tasks inside of main().

Stuck? Get a hint Next steps 13. Create new instances and play around with methods. Here are some ideas to get you started:

Create a energyReport() method that prints the instance’s batteryLevel.

Create another instance.

Create a method energyTransfer() that exchanges batteryLevel between instances.

build-a-driod's People

Contributors

fouzih avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.