Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with code

 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so I have started doing my code and it ran perfectly. I needed to do a menu for a restaurant in which it took the customers order and then calculated their total price. Well, now I want to be able to calculate the number of items sold from all the customers up to the last order! also I want the owner to have a total money count. Is this possible? Please help I am stuck!
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy skiathitis wrote:ok so I have started doing my code and it ran perfectly. I needed to do a menu for a restaurant in which it took the customers order and then calculated their total price. Well, now I want to be able to calculate the number of items sold from all the customers up to the last order! also I want the owner to have a total money count. Is this possible? Please help I am stuck!





i dont think the code went through as an attachment...so I will post them here...



..........................................


now the above is my main method..and this is a class to calculate num items...its probably wrong

 
Nico Van Brandt
Ranch Hand
Posts: 69
IntelliJ IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is possible (well...olmost everything )
But without the proper information we can't help you.

Like .. What info do you store in your database?
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont know..I use netbeans....this is my first programming class!
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags!!
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy skiathitis wrote:
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!

http://www.coderanch.com/how-to/java/UseCodeTags
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:
sandy skiathitis wrote:
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!

http://www.coderanch.com/how-to/java/UseCodeTags




i think i ruined it!! omg I suck at this !!!Im sooooo sorry!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy skiathitis wrote:
Darryl Burke wrote:
sandy skiathitis wrote:
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!

http://www.coderanch.com/how-to/java/UseCodeTags




i think i ruined it!! omg I suck at this !!!Im sooooo sorry!
But I know how to and I have added the tags, and removed some empty lines. Don't let it worry you.

You ought to provide correct indentation, however, using 4 spaces at a time, not tab characters.
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
sandy skiathitis wrote:
Darryl Burke wrote:
sandy skiathitis wrote:
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!

http://www.coderanch.com/how-to/java/UseCodeTags




i think i ruined it!! omg I suck at this !!!Im sooooo sorry!
But I know how to and I have added the tags, and removed some empty lines. Don't let it worry you.

You ought to provide correct indentation, however, using 4 spaces at a time, not tab characters.



nevermind I did it!!!yay!!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done

But how did you get it to work?
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nico Van Belle wrote:Everything is possible (well...olmost everything )
But without the proper information we can't help you.

Like .. What info do you store in your database?


I store the input from the customer. I mean that is what is being used to do the order. and the case statement keeps going until someone types in the word No.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12125
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post (which is why you'll see me as the 'last edited by').

To put them in, when you make or edit your post, just highlight all your source code, then click the 'code' button above where you enter your text. You'll see them pop in just before and after what you highlight. They preserve your formatting and make it easier to read.

I think your code has a few issues...

this line:


is almost without a doubt wrong. When you put that semi-colon there, you'll get either get stuck in an infinite loop, or code will run you don't think should.

This code:


looks like it will also give you an infinite loop. when you come in to the numberOfInstances() method, you set numItems to 0. you enter your while statement, and since numItems is NOT equal to -1, you add 1 to frequency. but numItems is STILL not equal to -1, so you add another 1 to frequency... etc.


The best way to approach writing code is to break down your problem first. Forget about Java, or C, or Pascal, or whatever language you are coding in. Think about it in English (or whatever your native language is).

Let's think about what we'd need to do to get totals for ALL customers. I would probably need something that remembers everything done. In the real world, I'd have a register audit tape that records every transaction.

Maybe what I need here is something that stores transactions.

OK...so what should be in a transaction? Do I need to know WHAT they ordered, or just how many total things they ordered and the total price? We can work towards either approach, but how we go forward depends on the answer.
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Well done

But how did you get it to work?


the main code worked perfectly fine, but when i tried to call the class items, it did not work. I might delete that entire class and start with the main method. How can I calculate the number of items and also the total cost for all the orders?
 
sandy skiathitis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:I added code tags to your post (which is why you'll see me as the 'last edited by').

To put them in, when you make or edit your post, just highlight all your source code, then click the 'code' button above where you enter your text. You'll see them pop in just before and after what you highlight. They preserve your formatting and make it easier to read.

I think your code has a few issues...

this line:


is almost without a doubt wrong. When you put that semi-colon there, you'll get either get stuck in an infinite loop, or code will run you don't think should.

This code:


looks like it will also give you an infinite loop. when you come in to the numberOfInstances() method, you set numItems to 0. you enter your while statement, and since numItems is NOT equal to -1, you add 1 to frequency. but numItems is STILL not equal to -1, so you add another 1 to frequency... etc.


The best way to approach writing code is to break down your problem first. Forget about Java, or C, or Pascal, or whatever language you are coding in. Think about it in English (or whatever your native language is).

Let's think about what we'd need to do to get totals for ALL customers. I would probably need something that remembers everything done. In the real world, I'd have a register audit tape that records every transaction.

Maybe what I need here is something that stores transactions.

OK...so what should be in a transaction? Do I need to know WHAT they ordered, or just how many total things they ordered and the total price? We can work towards either approach, but how we go forward depends on the answer.




well i just want to know the total price and number of items. I dont really care what they ordered. and the


my professor said that was great and to keep it in my code
 
jishnu dasgupta
Ranch Hand
Posts: 103
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG!! I think i just made a record in being IN a single post!!!

cheers!!!
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy skiathitis wrote: . . .


my professor said that was great and to keep it in my code
It's still a mistake, and he must have missed the ; when you showed him it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48967
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:I added code tags to your post (which is why you'll see me as the 'last edited by'). . . ..
So did I. Did we do it simultaneously? Is that why it looked so peculiar when I tried it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic