Question:

How to store those informations in Java?

by  |  earlier

0 LIKES UnLike

I need to store those variables for each bot my radar detects [from robocode]:

double bearing = e.getBearing();

double energy = e.getEnergy();

double heading = e.getHeading();

double velocity = e.getVelocity();

double distance = e.getDistance();

double lastUpdated = getTime();

String name = e.getName();

The radar get all those informations and I need a way to store then temporaly. I was thinking about using arrays but I just don't know how to apply they correctly on this situation. The information must be like that:

name, lastUpdated, distance, bearing, velocity, heading, energy

I will need retrieve those informations from all or a specific robot [defined by his own name] later, if I use arrays, how could I do that?

 Tags:

   Report

2 ANSWERS


  1. 1. Create a Radar class that stores all information.

    2. Then you can have Radar[] arrayRadar = new Radar[10];

        Or, instead of array, you can use HashMap for easy retrieval.

    If you use array, then to retrieve a specific radar you need for-loop to check each of them by name.

    If you use HashMap, you can use name as the key and the class as the value.


  2. Hi,

    this is venu . The solution for your query can be fulfilled by using the Vector,ArrayList ,etc.......... these are present in the util package of java

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.