• Post Reply Bookmark Topic Watch Topic
  • New Topic

using a textfield to add an object to a vector??  RSS feed

 
Ron Sibayan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ppl,
please can someone explain something to me or at least point me in the right direction. I'm trying to make a program (for school) which accepts a number from a textfield and adds a corresponding food menu item to a 'bill' vector. Am I supposed to be using some sort of referencing to show that the number entered should be used as the code for the menu object??

I hope someone can clear my head up on this as i'm completely flummoxed.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if you're in the UK. Anyway, you should try to do assignments for school on your own, you know!
From what you've said, I'm assuming you mean the textfield will have an ID code for a food item, and you must store some lookup between all the food item names and their ID codes in order to add the food item name to a Vector, right?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ron and welcome to JavaRanch. Before we get too far with this, no one here is going to do your home work for you. You need to give a little more information so that we can point you in the right direction to figure this out for yourself. How does the number in the text field relate to the food menu? Is the menu an array? Is it a Collection?
 
Ron Sibayan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks 4 the replies Mike n Huey.
I am TRYING, but I thought I'd use all available resources do you think i need to write a method which uses the number entered as a lookup value to add a menu item object into the vector? if so please could you suggest a site which could help me?
cheers
Ron Sibayan
(Oh and yes, i'm in the UK)
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ron,
You didn�t really answer Michael�s question:

How does the number in the text field relate to the food menu? Is the menu an array? Is it a Collection?

You said your program "accepts a number from a textfield and adds a corresponding food menu item to a 'bill' vector"
Michael was asking how does the number relate to the food item (an important Object-Oriented question) AND how are they stored in your program? Related to that is how are the menu items obtained (i.e. from a text file, hard-coded in your program, already in another class, database lookup, etc)
And you really didn�t answer S.C Huey's question. And strangely enough, they were both asking basically the same question. People can't help you if you don�t answer their questions. Answer their questions and people can help guide you in the right direction.
In the meantime, let me give you these two hints:
1) Be sure to think in Objects. It�s all about Objects and their Attributes. Look at the real world objects you have (FoodItem, Menu, Bill) and figure out how to represent them, and how they interrelate.
2) Look at Sun�s Collections Tutorial - but don�t necessarily jump at the first thing you see. Work through the entire tutorial. Then look at the APIs (JavaDocs) of the things you learn about in that tutorial. Then relate what you learned about to your problem.
Again, no one here will give you the answer. It is not because we want to be mean and vicious but because the best way to learn programming is to figure things out (as well as the ethical question of doing someone�s homework for them). Remember, programming is all about problem solving; that�s what we all love about it. You can solve this problem.
Oh, and welcome to the wonderful world of Java. It�s a cool place to be.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!