• Post Reply Bookmark Topic Watch Topic
  • New Topic

need help with burger restaurant project  RSS feed

 
Adrian Coria
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I am currently stuck on a school assignment and i would gladly appreciate your help. The assignment is to make a burger restaurant program that will serve three customers. The menu is loaded from a text file on my computer using FileReader. I uploaded these items to an ArrayList. I have uploaded the menu data just fine, but i am having trouble pulling out the values I want from the ArrayList. Here is my code: Any suggestions where to go from here?



 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch! I added code tags to make the code easier to read.

Adrian Coria wrote: but i am having trouble pulling out the values I want from the ArrayList. Here is my code: Any suggestions where to go from here?

Can you describe how you know which one you want in English? Is it that you want the first one? A specific one using some criteria?
 
Adrian Coria
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what my text file looks like:

burger,2.50,50
fries,1.50,40
soda,1.00,100


So i created a 'BurgerJoint' class that looks like this



If i wanted to pull out, for instance, the price of a burger i'm not sure how to go about it. I tried this code thinking i could use menu.get(i) but it did not work like i wanted it to..



Thanks again for any help

 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

My first question would be, where is your Burger class?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian Coria wrote: I tried this code thinking i could use menu.get(i) but it did not work like i wanted it to..

It seems to me like you don't really know what you want it to do. You seem to be writing code and just hoping it works.

There is a basic fact that no class I've ever been in has ever taught: Coding is 90% thinking, and 10% typing. you should KNOW exactly what your code should do before you write a single line.

I would suggest you read our StopCoding FAQ, and follow the advice given there.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've said in many other threads in these forums that it's important to choose the right names when you're programming. Names can make or break your code. The names you have in your code right now are not helping you. You need to get the concepts that you're dealing with straight in your head. As it is now, your "story" doesn't make a whole lot of sense. How does a Burger Joint represent one food item with a name, price, and quantity? When I hear "Burger Joint" I think of McDonald's or Wendy's or Five Guys. The attributes you're assigning to your BurgerJoint class don't make sense -- there's a conceptual incongruence there. It's like saying a Car has a driver's license.

A few more names that could be made better to help clarify the story where they're used: br, menuData, and line

You can't read the name br out loud and sound like you're saying anything meaningful, unless you wanted to let people know you're feeling feeling cold. What does this thing do? What is the intent? What is the idea/concept behind it? If you were to explain what the code is doing in plain English wouldn't it make more sense to say something like "this thing is reading a line that contains information about a single menu item"? You need to find names that will allow your code to convey that idea concisely: ???.readLine() -- what name can you use in place of ??? to convey that idea? FYI, files and databases that hold data are usually called "stores" or "repositories".

The same kind of thought process would go into picking better names for menuData and line. These names tell more about implementation details inherent "beingness" rather than a specific purpose or intent associated with them. Kind of like calling something nebulous/generic like "Person" or "Thingy" rather than "Cashier" or "KetchupBottle".

When you find better names for the things involved in your program, you'll be able to get your story straight in your head and organize the different elements so that it makes more sense to you and other people reading the code. Then you'll have a better shot at giving the correct instructions for the computer to do what you want it to do.
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adrian Coria wrote:




Using public variables is just poor design. These variables should be private and use getter/setter methods to retrieve/assign values accordingly.

If the variables are private, you can have a constructor like BurgerJoint(String item, double price, int quantity). If you do this, make sure you explicitly have a default constructor if you want to do "new BurgerJoint()"

Quantity should really be integer.

To get the values? You can then do:




Looping list? Every object you get is a BurgerJoint right? See above for getting values.
 
Adrian Coria
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Fred for directing me to the StopCoding FAQ. That really helped me a lot. Im going to write down on a piece of paper what I want my program to achieve and take another crack at this project.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!