• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with methods, getters and setters  RSS feed

 
Akira belliveau
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I got my program working correctly my own way but my professor wants us to use these specific codes:

Under initComponents();

he wants us to set purchase and numItems equal to 0

Also he wants us to use these three methods:







I've been testing it out and I'm stumped. I have no idea where to put these methods in my code, can you guys help?

Here's my full code:



 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know. You don't have any class with purchase or itemPrice or numItems variables.
How should I know where to put getters/setters for them? What are the requirements?

BTW, it is very important to indent your code correctly. Lines 100-102 make me feel dizzy .
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first blocks with all the code squashed onto a single line was just as bad.
You put that code in whichever class you need those methods. As PP has suggested, it is wherever the purchase price and count of items fields are.
Why is Counter an inner class? If you don't know about setters and getters (those methods were not setters), surely you don't know about inner classes.
 
Akira belliveau
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:I don't know. You don't have any class with purchase or itemPrice or numItems variables.
How should I know where to put them? What are the requirements?


I'm sorry for the indents but that's kind of what I'm trying to figure out. I think purchase is supposed to be the sub total, item price is item price the user enters when the dialog box pops up and numItems is the counter thing. Each time the user enters a number it adds one to the field Number of Items. The goal of this program is to ask the user for the item price and then the program takes that and adds it to the next number the user enters. Until the user clicks cancel or OK when the text box is blank the program won't calculate the total price and tax.

heres the flow of the program:

and here is the GUI:
 
Akira belliveau
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:The first blocks with all the code squashed onto a single line was just as bad.
You put that code in whichever class you need those methods. As PP has suggested, it is wherever the purchase price and count of items fields are.
Why is Counter an inner class? If you don't know about setters and getters (those methods were not setters), surely you don't know about inner classes.


That's why I'm posting here for help. I do understand but I don't. I don't know about inner classes either, but I know for sure I don't need to because he hasn't explained anything like that in class. This is my first code that I made that actually worked.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akira belliveau wrote:That's why I'm posting here for help. I do understand but I don't. I don't know about inner classes either, but I know for sure I don't need to because he hasn't explained anything like that in class. This is my first code that I made that actually worked.

So you wrote some code and have no idea how it works? This is not a good way to write a program...
You need to understand what you want to achieve. Write it on paper etc. Only if you figure out how it is supposed to work, you can start to write more java code.
StopCoding <- click this
 
Akira belliveau
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never said I didn't know how the program works. How would I write a program that works, while not knowing how it works? that doesn't make sense. Plus negative comments don't help me at all.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akira belliveau wrote:I never said I didn't know how the program works. How would I write a program that works, while not knowing how it works? that doesn't make sense. Plus negative comments don't help me at all.

You wrote I don't know about inner classes but you use one in your code. Thus my conclusion that you don't know how your program works.
Ok, I won't post more negative comments ;). But you have to help me help you. You need to be more specific. How can I (or other rancher) help you?
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akira belliveau wrote: . . . I'm sorry for the indents but that's kind of what I'm trying to figure out. . . .]
You are obviously using an IDE. Doesn't it have automatic indentation correction? I know Eclipse has: you can use ctrl‑A ctrl‑I
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can simply move the entire inner class out from inside the other class. It will need a file of its own.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!