Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:38:23+00:00 2026-06-01T17:38:23+00:00

say I have a class A which is as follows public class A {

  • 0

say I have a class A which is as follows

    public class A {
      protected static float[] floatArray = null;
      protected static Map<Integer, float[]>  history = new HashMap<Integer,float[]>();
      protected static Integer historyCount = 0;

      public void runEverySecond(Populator objPopulator) {
         floatArray = objPopulator.getValues();
         history.put(historyCount, floatArray);
         historyCount++;
      }  
    }

and Class B looks as follows

    public class B {
      private A objA;
      protected final static Populator objPopulator = new Populator();

      public void run(Integer numOfTime) {
        for(int i = 0; i < numOfTime; i++)
           objA.runEverySecond(objPopulator);
      }
    }

and Class Populator looks as follows

    public class Populator {
      protected float[] randomValues = new float[2];
      public float[] getValues() {
        randomValues[0] = //some new random float value generated for every call
        randomValues[1] = //some new random float value generated for every call
        return randomValues;
      }
    }

and class containing main looks as follows

    public class MainClass {
      public static void main() {
        final B objB = new B();
        objB.run(10);
      }
    }

Here is the problem I am facing, the Map history contains the same value for every entry in the map. I want the Map history to store all the values generated by objPopulator.getValues() method. How do I do it?

Some help would be really appreciable.
Thanks in Advance 🙂

The Actual code (with irrelevant code removed ) represented by class A

public class MySuperAgent implements Agent {
protected static float[] marioFloatPos = null;
protected static Map<Integer, float[]> levelRecord = new HashMap<Integer, float[]>();
protected static Integer mapCount = 0;
/*  protected static int testCount = 0;
protected static float[] testx = new float[2];
protected static float[] testy = new float[2];*/

@Override
public void integrateObservation(Environment environment) {
    marioFloatPos = environment.getMarioFloatPos();
    levelRecord.put(mapCount, marioFloatPos);
    mapCount++;

   /*if(testCount < 2){
        testx[testCount] = marioFloatPos[0];
        testy[testCount] = marioFloatPos[1];
        testCount++;
    } else {
        testCount = 0;
    }*/
  }
}

class C represent environment object
integrateObservation method is called from class similar to class B
if I use the code within the comment block then I am able to record only 2 past values of x and y of Mario. I need a way to store all the values of x and y of Mario 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:38:25+00:00Added an answer on June 1, 2026 at 5:38 pm

    There’s only one floatArray and you keep reassigning it.

    This code was almost impossible to follow in a reasonable way–what a mess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a class Collection which holds a list of Items. public
Say I have a class which represents a person, a variable within that class
Say I have a class Customer which has a property FirstName . Then I
Let's say we have a class foo which has a private instance variable bar
Let's say I have a Size class which has height and width properties (in
Possible Duplicate: Overload ++ operator Say i have a class in which i overloads
Say I have a class called PermissionManager which should only exist once for my
Let's say I have an class called Star which has an attribute color .
Let's say I have a list in a class which will be used in
Say I have a Date, or a Phone number, or some Class which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.