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

  • Home
  • SEARCH
  • 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 6894473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:47:14+00:00 2026-05-27T06:47:14+00:00

I am trying to build a program for a school assignment that generates transitive

  • 0

I am trying to build a program for a school assignment that generates transitive closures given a set o Functional Dependencies. I am using JAVA . To make it recognize string subsets i have had to build a Class called Attribute consisting of a char and a boolean field (to help further recognition of strings containing character sequences

Then i have a class called FunctionalDependency which simply has two maps of
<Integer, Attribute>.
the first map represents the left hand and the second the right hand of an attribute.

Finally my main program that does the actual calculationhas a map of Integer,FunctionalDependency, which represents the set of dependencies that the user wants to input. My problem is located in the method insertFD() and more specifically in the first for{} block. Whilst in the for block the map seems to have the values i want , outside it (meaning after the last call of the loop) it copies to all the positions of the map the last character of the input destroying the further calculations.

   /*The method for inserting a new FD*/
   public void insertFD() throws IOException{
       Map<Integer, Attribute > tempMapLeft= new HashMap<Integer,Attribute>();
       Map<Integer, Attribute > tempMapRight= new HashMap<Integer,Attribute>();
       Attribute tempAttrLeft = new Attribute();
       Attribute tempAttrRight = new Attribute();
       FunctionalDependency tempDependency=new FunctionalDependency();


       String tempString;
       BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
       System.out.println("Please give the string for the left hand:");
       System.out.flush();
       tempString=stdin.readLine();
       tempString.toUpperCase();
       System.out.println("Your input is "+tempString);


       for(int j=0;j<tempString.length();j++)
       {
           System.out.println("for j="+j+"letter is "+(tempString.toCharArray()[j]));
           tempAttrLeft.setTheCharacter(tempString.toCharArray()[j]);
           tempAttrLeft.setCheck(true);
           tempMapLeft.put(j, tempAttrLeft);
           System.out.println("I just inserted "+ tempAttrLeft.getTheCharacter());
           System.out.println("Here is the proof: "+tempMapLeft.get(j).getTheCharacter());
       }
       System.out.println(tempMapLeft.get(0).getTheCharacter());
       System.out.println(tempMapLeft.get(1).getTheCharacter());
       tempDependency.setLeftHand(tempMapLeft);
       //fSet.put(number, tempDependency);
       //fSet.get(number).setLeftHand(tempMapLeft);

       System.out.flush();
       System.out.println("Your left hand is at 0 "+  tempDependency.getLeftHand().get(0).getTheCharacter());
       System.out.println("Your left hand is at 1 "+ tempDependency.getLeftHand().get(1).getTheCharacter());

I am not any java expert but i cannot see the mistake in my code, i would be glad if you could help me, thanks in advance.

  • 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-05-27T06:47:14+00:00Added an answer on May 27, 2026 at 6:47 am

    Your problem is that you keep re-using the same tempAttrLeft and tempAttrRight in each pass of the loop. Every key in the map is pointing to the same object! You need to create a new tempAttrLeft and tempAttrRight on each pass of the loop. The map keeps a reference to the object you put in it, it doesn’t “copy” it. So when you change the values on the next pass of the loop, that map key is pointed to the same one with the new values.

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

Sidebar

Related Questions

I am trying to build a server program that receives file from client using
I am trying to build a program using the command scons compiler = msvc.
I'm trying to build a small program that hosts vst effects and I would
I'm trying to build a Chinese flashcards program in Java to help myself learn
I am trying to build a simple java program which creates a db file,
I'm trying to build a program I've written in C using GNU autotools, but
I am trying to build a program that uses libusb and I get a
I am trying to build a program that, once the button was click, every
Helllo! I'm trying to build a program that calculates the best score from a
I'm trying to build a video chat program using Adobe Flex but there is

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.