Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,010 members, 7,814,447 topics. Date: Wednesday, 01 May 2024 at 01:04 PM

Java Programmers Plz Help Out - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Programmers Plz Help Out (1824 Views)

Java Programmers / Help Me Out Java Programmers / Java Programmers ,I Need Help Fixing This Code. (2) (3) (4)

(1) (Reply) (Go Down)

Java Programmers Plz Help Out by Austano2020: 10:01am On May 29, 2019
Pls I have some kind of difficulty in this java code.
Am building an inventory system that requires random multiple selections of checkboxes. I did it in a such a way that once I click on any checkboxes the item and the price will display on TextArea(Cart) . I want if I clicked on the button "TOTAL" the total amount amount of the items selected from the checkboxes will display on the TextArea (Cart) . So I just need a method/function that will get the information(prices)from the TextArea (Cart), sum it all and display my Total .
I have tried doing it shaa but my code is too long although I couldn't implement the one that will just loop through My Textarea
Re: Java Programmers Plz Help Out by asalimpo(m): 10:55am On May 29, 2019
Post your code here for review.
Re: Java Programmers Plz Help Out by masterfactor(m): 12:34pm On May 29, 2019
post ur code
Re: Java Programmers Plz Help Out by stanliwise(m): 3:55pm On May 29, 2019
Austano2020:
Pls I have some kind of difficulty in this java code.
Am building an inventory system that requires random multiple selections of checkboxes. I did it in a such a way that once I click on any checkboxes the item and the price will display on TextArea(Cart) . I want if I clicked on the button "TOTAL" the total amount amount of the items selected from the checkboxes will display on the TextArea (Cart) . So I just need a method/function that will get the information(prices)from the TextArea (Cart), sum it all and display my Total .
I have tried doing it shaa but my code is too long although I couldn't implement the one that will just loop through My Textarea
Aside from long code, did it work?
Checkout topics like
Java Event
All you need to do is to have an event listener that react and collate button value when total is clicked.
Re: Java Programmers Plz Help Out by lincsnuel: 5:32pm On May 30, 2019
Create a new Integer object, parse the numbers (values) in the TextArea which are in String to an "int" by using the parseInt(String s) method. After parsing them to "int" (or double... i.e if the values are not integers e.g 123.45), then, you can add them together in a new "int" or "double" variable. Hope you get my point

1 Like

Re: Java Programmers Plz Help Out by Austano2020: 7:15am On Jun 01, 2019
stanliwise:
Aside from long code, did it work?
Checkout topics like
Java Event
All you need to do is to have an event listener that react and collate button value when total is clicked.
Tanx alot I have gotten the solution
Re: Java Programmers Plz Help Out by Austano2020: 7:17am On Jun 01, 2019
lincsnuel:
Create a new Integer object, parse the numbers (values) in the TextArea which are in String to an "int" by using the parseInt(String s) method. After parsing them to "int" (or double... i.e if the values are not integers e.g 123.45), then, you can add them together in a new "int" or "double" variable. Hope you get my point
Tanx bro, I used JTable instead of TextArea and I wrote a functio/method that loop through the rows of JTable and sum it together

1 Like

Re: Java Programmers Plz Help Out by kudaisi(m): 7:29pm On Jun 02, 2019
I know this is outside the scope of your question and since I don't know how your application works I shouldn't be too quick to judge.

But I'm concerned about how you implemented the Cart functionality in your application, considering it requires you to pull up entities from a JTable or JTextArea when you need to get the sum total. For one, I see performance issues if your application gets bigger (remember Big O notation, considering the cost of looping every time you need a total), secondly your implementation will eventually make you code hardly reusable. For me, the idea would be that I should be to use the same Cart class in a Java SE or Java EE application with little or no changes (which can be achieved by inheritance), hence I would avoid tying items directly to my view.

Correct me if I am wrong, but isn't the normal workflow to have a list of entities somewhere, then use it as a model for a view component where required rather than adding items to the view directly.

For example, if I was going to implement something like that, I would probably have a class Cart that defines a method void addItem(ICartItem item), void removeItem(ICartItem item) and a int getSumTotal(), subsequently, each time I want to add an item to a cart I will simply call the addItem method which will in turn add the item to a list in the Cart and add the cost of that item to the a sumTotal variable within the Cart class, while the removeItem method will do the reverse. This way I have my sum total on-the-fly anytime I need it at no extra computational cost.

So, to display in a JTextArea for example I would simple override the toString method (native to all Java classes) of the Cart class so that I can easily update the JTextArea by doing someTextArea.setText(someCart) and for the JTable I would then use the list of items as a model for the a JTable such that updating the list, updates the table.

PS: These are just my opinions, it doesn't make it any better that what you might have implemented, but given the facts... , I hope you find this helpful.

2 Likes

Re: Java Programmers Plz Help Out by asalimpo(m): 12:07am On Jun 03, 2019
kudaisi:
I know this is outside the scope of your question and since I don't know how your application works I shouldn't be too quick to judge.

But I'm concerned about how you implemented the Cart functionality in your application, considering it requires you to pull up entities from a JTable or JTextArea when you need to get the sum total. For one, I see performance issues if your application gets bigger (remember Big O notation, considering the cost of looping every time you need a total), secondly your implementation will eventually make you code hardly reusable. For me, the idea would be that I should be to use the same Cart class in a Java SE or Java EE application with little or no changes (which can be achieved by inheritance), hence I would avoid tying items directly to my view.

Correct me if I am wrong, but isn't the normal workflow to have a list of entities somewhere, then use it as a model for a view component where required rather than adding items to the view directly.

For example, if I was going to implement something like that, I would probably have class Cart that defines a method void addItem(ICartItem item), void removeItem(ICartItem item) and a int getSumTotal(), subsequently, each time I want to add an item to a cart I will simply call the addItem method which will in turn add the item to a list in the Cart and add the cost of that item to the a sumTotal variable within the Cart class, while the removeItem method will do the reverse. This way I have my sum total on-the-fly anytime I need it at no extra computational cost.

So, to display in a JTextArea for example I would simple override the toString method (native to all Java classes) of the Cart class so that I can easily update the JTextArea by doing someTextArea.setText(someCart) and for the JTable I would then use the list of items as a model for the a JTable such that updating the list, updates the table.

PS: These are just my opinions, it doesn't make it any better that what you might have implemented, but given the facts... , I hope you find this helpful.
i find the word sumTotal to be tautalogical. What is a sum ? And what is a total ? Aren't they one and the same? You can use sum or total as a verb . "sum up the expenses for me". "have them total the cost for me" etc but you cannot say "sumtotal" it for me i.e u can't use sumtotal as a verb ,further proving it's wrongness.
Re: Java Programmers Plz Help Out by seadog2000(m): 2:42am On Jun 03, 2019
Oga U r still using Swing? Haha upgrade cos now GUI development in Java MUST BE JAVAFX


Also in modern technology world the web will soon overshadow desktop platform. So maybe u should start thinking of cloud based solutions
Re: Java Programmers Plz Help Out by kudaisi(m): 8:38am On Jun 03, 2019
asalimpo:

i find the word sumTotal to be tautalogical. What is a sum ? And what is a total ? Aren't they one and the same? You can use sum or total as a verb . "sum up the expenses for me". "have them total the cost for me" etc but you cannot say "sumtotal" it for me i.e u can't use sumtotal as a verb ,further proving it's wrongness.

Sum total is synonymous to grand total. Furthermore, according to Webster dictionary
Sum total is a total arrived at through the counting of sums
While Cambridge dictionary has it as
The sum total of something is the whole of it, or everything

So can you please clarify this statement ?
but you cannot say "sumtotal"
FYI, English was besides the point of the post, and even if it was an error, I fail to see how it affects the message passed in the post.
Re: Java Programmers Plz Help Out by asalimpo(m): 12:29pm On Jun 05, 2019
kudaisi:


Sum total is synonymous to grand total. Furthermore, according to Webster dictionary While Cambridge dictionary has it as

So can you please clarify this statement ?
FYI, English was besides the point of the post, and even if it was an error, I fail to see how it affects the message passed in the post.
sumtotal is a valid english word.
I thought it was a nigerian construction. But i had a niggling sense tht it was valid english but didnt check bf i posted.

Why is it wrong? It does'nt sound right. There's something off about it!
That's why you wont see high grade financial software using tht word. It just doesnt sound right when used with numbers.
Can you imagine excel or any spreadsheet documntation having a line saying sumTotal?
They'd rather use a better word like: grandtotal or just plainly total or mayb aggregate.

"Can you please clarify ... "- i meant the words sum and total can be used interchangeably as nouns and verbs.
But sumtotal can only b used as a noun. As a verb it is to akward,if it is even correct.

"Fyi english was besides the point ... "- yeah,it was. The correction makes no difference to the core of d message. But ... That's d issue with a public forum and freedom of speech. People will express themselves on issues. What is a small/no deal to another is a big deal to others.
Actually,in d long run,seemingly little things can matter a lot! Little things could hav a significantly greater impact than you think,so ignoring the little things may not b wise.
Re: Java Programmers Plz Help Out by asalimpo(m): 2:58pm On Jun 06, 2019
seadog2000:
Oga U r still using Swing? Haha upgrade cos now GUI development in Java MUST BE JAVAFX


Also in modern technology world the web will soon overshadow desktop platform. So maybe u should start thinking of cloud based solutions
until hard drives bcom cloud based (and computers become thin clients only),they will always be room for desktop apps.
Re: Java Programmers Plz Help Out by stanliwise(m): 5:50pm On Jun 07, 2019
asalimpo:

sumtotal is a valid english word.
I thought it was a nigerian construction. But i had a niggling sense tht it was valid english but didnt check bf i posted.

Why is it wrong? It does'nt sound right. There's something off about it!
That's why you wont see high grade financial software using tht word. It just doesnt sound right when used with numbers.
Can you imagine excel or any spreadsheet documntation having a line saying sumTotal?
They'd rather use a better word like: grandtotal or just plainly total or mayb aggregate.

"Can you please clarify ... "- i meant the words sum and total can be used interchangeably as nouns and verbs.
But sumtotal can only b used as a noun. As a verb it is to akward,if it is even correct.

"Fyi english was besides the point ... "- yeah,it was. The correction makes no difference to the core of d message. But ... That's d issue with a public forum and freedom of speech. People will express themselves on issues. What is a small/no deal to another is a big deal to others.
Actually,in d long run,seemingly little things can matter a lot! Little things could hav a significantly greater impact than you think,so ignoring the little things may not b wise.
Haven't your heard of Grand Total? so why should sum Total sound awkward? perhaps this discussion is derailing the thread.
Re: Java Programmers Plz Help Out by asalimpo(m): 1:19am On Jun 09, 2019
stanliwise:
Haven't your heard of Grand Total? so why should sum Total sound awkward? perhaps this discussion is derailing the thread.
it has to do with fine grainedness and an ear for words. I mentioned grand total as a better alternative. Or Aggregate but this one sounds too ,well, pretentious or big sounding.
Sumtotal isnt normally used for numbers, it's usually used for events usually of a negative nature, and the tautology - saying the same thing in different ways - is used create emphasis or for exaggeration. E.g some1 may narrate an event: "i went for an interview, waking up at 6am to beat d traffic. But, i arrived 2 mins late. And got d last seat. Then, we were told to present our certificates. I had from waec to my msc. But we were told that we must tender primary school results also. I begged tht i would bring mine first thing tomorrow. They let me in. On getting in, the test took 4 gruelling hours, i thought it would take only two. I finished first,passed and promptly went home,hoping theyd text me my result. I got an sms alert the next day. It wasnt pleasant. The sumtotal of everything-all my sweat stress nd suffering- was that i didnt get the job!"

Sumtotal is usually used for non numerical aggregates. That's y u wont see many top class finance/numeric software using that word. It doesnt sound right. It's lil thing but it matters
Re: Java Programmers Plz Help Out by Austano2020: 10:05pm On Jun 21, 2019
kudaisi:
I know this is outside the scope of your question and since I don't know how your application works I shouldn't be too quick to judge.

But I'm concerned about how you implemented the Cart functionality in your application, considering it requires you to pull up entities from a JTable or JTextArea when you need to get the sum total. For one, I see performance issues if your application gets bigger (remember Big O notation, considering the cost of looping every time you need a total), secondly your implementation will eventually make you code hardly reusable. For me, the idea would be that I should be to use the same Cart class in a Java SE or Java EE application with little or no changes (which can be achieved by inheritance), hence I would avoid tying items directly to my view.

Correct me if I am wrong, but isn't the normal workflow to have a list of entities somewhere, then use it as a model for a view component where required rather than adding items to the view directly.

For example, if I was going to implement something like that, I would probably have a class Cart that defines a method void addItem(ICartItem item), void removeItem(ICartItem item) and a int getSumTotal(), subsequently, each time I want to add an item to a cart I will simply call the addItem method which will in turn add the item to a list in the Cart and add the cost of that item to the a sumTotal variable within the Cart class, while the removeItem method will do the reverse. This way I have my sum total on-the-fly anytime I need it at no extra computational cost.

So, to display in a JTextArea for example I would simple override the toString method (native to all Java classes) of the Cart class so that I can easily update the JTextArea by doing someTextArea.setText(someCart) and for the JTable I would then use the list of items as a model for the a JTable such that updating the list, updates the table.

PS: These are just my opinions, it doesn't make it any better that what you might have implemented, but given the facts... , I hope you find this helpful.
. Tanx alot
Re: Java Programmers Plz Help Out by Austano2020: 10:08pm On Jun 21, 2019
seadog2000:
Oga U r still using Swing? Haha upgrade cos now GUI development in Java MUST BE JAVAFX


Also in modern technology world the web will soon overshadow desktop platform. So maybe u should start thinking of cloud based solutions
And you u still refer us Nigerian to cloud base computing with little or no technology to do such. Desktop applications can never go just be good which ever one u find urself. Good luck

(1) (Reply)

A PHP Programming Problem...im Stuck / A Question For Yii2 Users / What Do Programmers Do In Airports??

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 60
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.