This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

My arraylist is doesn't display the info  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I'm making a program about selling video games. I'm having a problem linking two classes (Games & Admin).I'm sure the problem is too silly, but I can't figure it out. When I want to display the data in games' arraylist nothing shows up
Here's the code for the games class.







Here's the code for Admin class





 
Saloon Keeper
Posts: 5753
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A) I don't see a main() method.
B) Both classes have a gList.
C) Case 3: is not implemented.
 
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
d) you're creating two scanners in your gameClass, as if two isn't worse enough, you never use any of them.
e) you're doing the same in your adminClass, at least there you use them, but instead of 4 you should only have one
f) your displayGameList method(which is basicly a toString) is really porely formated, don't use System.out all the time, build a string, return it and use System.out on the returnValue
g)...
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:A) I don't see a main() method.
B) Both classes have a gList.
C) Case 3: is not implemented.



A) I didn't think the main method would matter to post since I think the problem is from one of these two classes.

Here is the main class





B) As for the gList, I actually have have some difficulties  when it comes to connecting things in different classes. What would you recommend to share the arraylist in other classes that needs it?

C) Still not all methods are implemented since I can't continue my work without solving the problem with the game's arraylist
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't keep the list in you're gameClass, whenever you create a new game you also create a new list.
Make a class Store for example, a getter is sufficient to get the list
I would also seperate my code a bit
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also don't understand why admin is extending games, the two have nothing to do with eachother
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I also don't understand why admin is extending games, the two have nothing to do with eachother



I thought about it. They have nothing n common,but I wanted to use the setters so I can create my games from the class Admin. Clearly not a good way to do it like that,but I don't know how else to do it
 
Marshal
Posts: 63781
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joel Drake wrote:. . . I wanted to use the setters so I can create my games from the class Admin. . . .

Like that. I shall let you work out what the method names mean
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This how I would structure it
- Create a class Game with it's variables, getter and setters and a toString
- Create a class User with it's variables, getter and setters and a toString
- Create a class Employee with it's variables, getter and setters and a toString
- Create a class Store containing the lsit of games, a list of users and a list of employees with getters and an addToUserList, addToGamesList, addToEmployeeList as well as a toString method
- Create a utility Class to login in after login in pass the user and store to the utility class
- Create a utility class that shows to handle the menu
- create a Mainclass that creates a Storeinstance and start the menu passing the store as parameter
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Joel Drake wrote:. . . I wanted to use the setters so I can create my games from the class Admin. . . .

Like that. I shall let you work out what the method names mean



Lol, to be honest this kinda looks like a top tier thing to do. I'm a newbie in Java, I mean I've got logic,like this won't be a problem in C++,but I'm kinda not that good in Java. What you wrote looks interesting though
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:This how I would structure it
- Create a class Game with it's variables, getter and setters and a toString
- Create a class User with it's variables, getter and setters and a toString
- Create a class Employee with it's variables, getter and setters and a toString
- Create a class Store containing the lsit of games, a list of users and a list of employees with getters and an addToUserList, addToGamesList, addToEmployeeList as well as a toString method
- Create a utility Class to login in after login in pass the user and store to the utility class
- Create a utility class that shows to handle the menu
- create a Mainclass that creates a Storeinstance and start the menu passing the store as parameter



Since I'm creating an application-like program where there are only users and one manager to add games and supervise over things, I won't be needing an employee class.
Regarding the store class, should I place the two arrays(users' & games' ) in the store class? If so, how would  use setters and getters from there?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at anytime the will only be one instance for your store, which you pass on from method to method.

 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:at anytime the will only be one instance for your store, which you pass on from method to method.



Excuse my ignorance,but now that I have a class called store,where should I receive my input for the data for both users and games?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have your menu already in place don't you?
I see an option to register... Which would create a new user?
After creating the new user call the addUsermethod of your store instance and pass the user to it, same when you're creating a game
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:You have your menu already in place don't you?
I see an option to register... Which would create a new user?
After creating the new user call the addUsermethod of your store instance and pass the user to it, same when you're creating a game



So, I did as you said ,but I'm having a bit of a trouble displaying the users' info,sry but this is a new style for me.

Here's the main method




Here's the store class



 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have maded a toString method in your user and gameClass (like I sugested) you can call the toString, but I would remove the foreach out of your informationStorrage, you also still have 2 scanner instances
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would do something like:
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I would do something like:




I just added a toString in my client/user class and I managed to display the info.However, users' info get overwritten  with the data of the last user in the system.What am I doing wrong?




Here's a sample output.



 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
show your userClass, yiur informationStorrage and your MainClaas as it is now...
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:show your userClass, yiur informationStorrage and your MainClaas as it is now...



Client/User






InfoStorage





Main method class




 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where to begin...
Your clientlist you'll keep in your informationStorrage, not in you clientClass.
I showed you the full information storageClass, why did you wen't an other way?
Get your loginmethod out of your clientclass.
At risk getting the comment of writting to mutch code, it easier to write an example then to explain so give me a sec
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My example:



 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Mr.Daniel. This looks very helpful although it's kinda a new style to me, and sorry for my many questions :')
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're all here to learn, how can you learn without asking questions
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:We're all here to learn, how can you learn without asking questions



Hi again :$, I hope I'm not disturbing you, but I have a question if I may.

I've been working on the menu class and everything looks fine and smooth so far. However, for some reason I can't add money to any user's wallet. The problem is either from menu class or client,but I can't seem to locate it

Client class:





Menu class:







[/code]


Main:



InfoStorage class :





 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You Don 't have a addToWallet method, you only have a setWallet methode. So everytime  you call it, it will overide your wallet...
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh sorry... you do have one. Im on my phone know, which isnt verry practical. When Im home i will have a look
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:Oh sorry... you do have one. Im on my phone know, which isnt verry practical. When Im home i will have a look


Np mate,take your time.
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please avoid abbreviations like Np. What does that mean? “No problem”?


Oh,sorry my bad. I did not know about such a rule.
 
Campbell Ritchie
Marshal
Posts: 63781
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apology accepted
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a quick look, my guess is that the problem is that you creating a new client in your addToWallet method, what you want to to is get the list of clients from the informationStorage compare the usernames of the list with the client you wan't to add to it's wallet and the call the add to wallet method of that specific client
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I had a quick look, my guess is that the problem is that you creating a new client in your addToWallet method, what you want to to is get the list of clients from the informationStorage compare the usernames of the list with the client you wan't to add to it's wallet and the call the add to wallet method of that specific client



But I'm already logged in as that specific user. So, shouldn't I just call the addmoney method?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a consoleapp, your loging in is pure for show, the program dosn't know who is using the program. If you wan't somebody actually to be logged in, you can keep an additional client in your informationStorrage and set that one everytime someone logs in
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:this is a consoleapp, your loging in is pure for show, the program dosn't know who is using the program. If you wan't somebody actually to be logged in, you can keep an additional client in your informationStorrage and set that one everytime someone logs in



I fixed it. I moved the data which the user inputs to log in and made them as global variable rather than them being defined inside the login method. In addition, I put a loop inside the addMoneyToWallet method to compare the last data was entered(while the user was trying to login) with the client list,so now the program knows who he is logged in. I don't know if you understood me,but do you think this is a good solution for later?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't work, add some money to your logged in user, then get the list of clients, search for the logged in user and see how mutch his wallet is... I bet it won't be the expected result
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:It won't work, add some money to your logged in user, then get the list of clients, search for the logged in user and see how mutch his wallet is... I bet it won't be the expected result


Well, have a look. I hope I'm not missing something,and sorry for limited output. Could not capture the whole thing.


 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got confused, I expected that when you use a global variable the client in your list wasn't going to be updated, but it saves a references to the object, not the object itself, so your fine
 
Joel Drake
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Daniel Demesmaecker wrote:I got confused, I expected that when you use a global variable the client in your list wasn't going to be updated, but it saves a references to the object, not the object itself, so your fine



Thank you again Daniel, let's hope that I won't be bothering you again...at least for now xD.
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol, don't see it as boughtering, I'm happy to help
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!