aspose file tools*
The moose likes Beginning Java and the fly likes Help with code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with code" Watch "Help with code" New topic
Author

Help with code

sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
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

Joined: Apr 22, 2011
Posts: 18
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

Joined: Mar 31, 2011
Posts: 66

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?


Oracle Java SE6 Certified Programmer
Oracle Java EE5 Certified Web Component Developer
sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
i dont know..I use netbeans....this is my first programming class!
jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

Please use code tags!!


If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra

sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

sandy skiathitis wrote:
jishnu dasgupta wrote:Please use code tags!!


i dont know how to!

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


luck, db
There are no new questions, but there may be new answers.
sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
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

Joined: Oct 13, 2005
Posts: 39435
    
  28
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

Joined: Apr 22, 2011
Posts: 18
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

Joined: Oct 13, 2005
Posts: 39435
    
  28
Well done

But how did you get it to work?
sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
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

Joined: Oct 02, 2003
Posts: 11420
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sandy skiathitis
Greenhorn

Joined: Apr 22, 2011
Posts: 18
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

Joined: Apr 22, 2011
Posts: 18
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

Joined: Mar 11, 2011
Posts: 103

OMG!! I think i just made a record in being IN a single post!!!

cheers!!!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
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

Joined: Oct 13, 2005
Posts: 39435
    
  28
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?
 
 
subject: Help with code