• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Printing Treemap, value and key in pop-up window

 
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Treemap and want to print the Values: and Keys to my window:



When i run the code, the values and keys from the Treemap are shown like this:




I tried with the Iterator (suggested here on forum)




The result looks better, but still have 2 Problems:

1. the text in my pop-up window looks the same, no changes.

QUESTION 1: HOW i get the changes inside my window ?

2. the changes from the iterator are show only on the console, and the squared bracket still there:


10 [Fragen: Ben 10 ]
9 [Fragen: Ben 9 ]
8 [Fragen: Ben 8.1 ]
7 [Fragen: Ben 7.1 ]
6 [Fragen: Ben 6.1 ]
5 [Fragen: Ben 5.1 ]
4 [Fragen: Ben 4.1 ]
3 [Fragen: --> Me Myself <-- ]
2 [Fragen: Ben 2.1 ]
1 [Fragen: Ben 1 ]

QUESTION 2: How i get the squared bracket away


i try to get something like this in my window:

10 Fragen: Ben 10
9 Fragen: Ben 9
8 Fragen: Ben 8.1
7 Fragen: Ben 7.1
6 Fragen: Ben 6.1
5 Fragen: Ben 5.1
4 Fragen: Ben 4.1
3 Fragen: --> Me Myself <--
2 Fragen: Ben 2.1
1 Fragen: Ben 1

Thanks
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using a new List every time? You are adding lots of single-member Lists. Why don't you create a Question class, which can encapsulate the question and answer? Then you can override its toString method to print what you want.
Also the numbers n1 n2 n3 look like awkward coding; that sort of thing can be very error-prone.

To find why you are getting [], you should look at the toString() method used by ArrayList.
 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Long story:
https://coderanch.com/t/522928/java/java/More-than-sorting-dupplicate-elimination

Short version:

have a quiz, where a lot of dummy users inside.

I dont know if i can encapsulate the question / answer because i try them to change randomly:

the n numbers are for the start values of the user, means n1 - user with one right answer .... n7, n71, users with 7 correct answers ...
this numbers are after each ten answers randomly increased, so if you run the quis you get after each 10 questions a list with the scores of the "other users".

thanks for the advice, i will change the names of the n - variables, for better code readability

in my Experiment_RF_Rnk1 class




in my actual class:



i think that a concept change would have as result the rewrite of my whole programm ?
maybe other ideas who dont need a big code change thanks
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you have User objects with a count of how many questions they have answered?
 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have only ONE user, his answers are counted and shown in the list
the ohter users in the list are dummy users, where the answers increase randomly,
The ONE user who run the quiz should think that they are more active users at the same time and that he get each 10 questions the actual standings

Campbell i am not shure if i got that what you meaning right ?

Why don't you have User objects with a count of how many questions they have answered?




 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That can still be implemented with User objects, but I hadn't realised you only have one user.
 
Lucian Botezatul
Greenhorn
Posts: 20
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If someone interested, i solved my problem, put the final code here in Forum:

https://coderanch.com/t/526309/java/java/Problems-printing-Treemap-nd-run
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic