Java Forum / General / March 2006
Really basic data entry question [Beginner]
AMT2K5 - 07 Mar 2006 21:49 GMT Hello,
I have a simple data script that looks like this:
Box of Hammer(s) # 6 Pack of Washer(s) #
Which is stored in a StringBuffer
I have the code
InventoryItem[] InvItems = new InventoryItem[10];
for(int i = 0; i < 10; i++) { InvItems[i] = new InventoryItem(); InvItems[i].inventoryId = i+1; // ? InvItems[i].quantityInStock = 2.5 * InvItems[i].inventoryId; InvItems[i].update(a); }
Where (a) is the passed into the method as a StringBuffer consisting of that data script read at an earlier time.
I want to update each object's attributes consisting of Product and Unit/Package, by using the update function (public int update(StringBuffer sb)) .
How would I go about doing that?
So InvItems[0] has a product of 'Hammer(s)' and a unit/package of 'Box Of', in the for loop when InvItems[1] comes along, it has a product of 'Washer(s)' and a unit/package of '6 Pack-of'
Thanks in advance, any help appreciated.
PS: I figure it will look something like this to start
public int update(StringBuffer sb){ String temp = new String(); StringTokenizer tk = new StringTokenizer(sb.toString(),"#"); while (tk.hasMoreTokens()) { System.out.println(tk.nextToken()); }
return 0; }
My data script looks like this
Box of 100 Bolt(s) # Motherload of Widget(s) # Box of 25 Grommet(s) # Box of 50 Hammer(s) # 24-Pack of Washer(s) # Box of Gizmo(s) # One Blade(s) # 6-Pack of O-Ring(s) # Motherload of Thingy(ies) # Box of Nut(s) #
Each pair between the sharps are the two attributes for the current object this.
Rhino - 07 Mar 2006 22:22 GMT > Hello, > [quoted text clipped - 84 lines] > Each pair between the sharps are the two attributes for the current > object this. "Data script"???
Is this a term you invented yourself? Because if your teacher told you this, you need a new teacher. In 25+ years in IT, I've never heard of a 'data script'. The normal term for this is 'input file' as anyone with 20 minutes of IT experience could tell you. Do a Google search on "data script" and then another on "input file" and I think you will see that the latter gets a lot more hits.....
--
Aside from that point, do you really have to read in data in the exact format you show in your post? Because I can't picture any professional organization doing it that way. At the very least, they would mentally translate the data into columns. More likely, they would store this data in a database where it belongs. I've never once had to write a program to turn a two line text string like:
24-Pack of Washers
into:
Washers 24-pack
I doubt I'd use a StringBuffer for this program either.
Please note that I don't mean to ridicule _you_; it's the assignment (and the person who created it) that I'm ridiculing.
I was going to go on and help answer the question but it's just so unrealistic I don't think I can play along after all.
Sorry.
-- Rhino
Tail_Spin - 08 Mar 2006 00:17 GMT > "Data script"??? > > Is this a term you invented yourself? He already stated that he was a [Beginner]
>Because if your teacher told you this, > you need a new teacher. In 25+ years in IT, I've never heard of a 'data > script'. > Please note that I don't mean to ridicule _you_; it's the assignment (and > the person who created it) that I'm ridiculing. I think he was looking for help not an observation on how stupid the assignment was!
> I doubt I'd use a StringBuffer for this program either. Why not tell him what you would do then to solve this problem???
> I was going to go on and help answer the question but it's just so > unrealistic I don't think I can play along after all. If you weren't going to provide any help, what was the point of your post? other than to tell him that his terminology was incorrect, the assignment was dumb and useless, and finally that you weren't going to help???
SPECIAL NOTE: Many times college and university professors hand out really dumb and totally useless assignments. Your job as a student is to complete those assignments to the best of your abilities. Providing comments about how useless and stupid the assignments are doesn't help get the job done!
> Rhino Rhino - 08 Mar 2006 05:06 GMT >> "Data script"??? >> [quoted text clipped - 23 lines] > assignments to the best of your abilities. Providing comments about how > useless and stupid the assignments are doesn't help get the job done! I'd say your post didn't help him/her very much either....
-- Rhino
Tail_Spin - 08 Mar 2006 09:08 GMT My replay was not to him but to YOU. With your 25+ years of IT you couldn't comprehend that part?
> >> "Data script"??? > >> [quoted text clipped - 28 lines] > -- > Rhino Rhino - 08 Mar 2006 17:51 GMT > My replay was not to him but to YOU. With your 25+ years of IT you > couldn't > comprehend that part? Yeah, I got that but instead of attacking me you could have been helping the original poster instead of attacking ME for not helping the original poster. That was my point - or didn't you comprehend that part?
And I stand by my remark that if a _teacher_ used the term 'data script' he wasn't very experienced in IT. I've never heard an input file called a 'data script' in my life and I do have 25+ years in IT. If a newbie calls it that, that is a perfectly reasonable guess at what such a thing should be called but if he/she heard that from a teacher, he/she should have reservations about what the qualifications of the teacher.
-- Rhino
>> >> "Data script"??? >> >> [quoted text clipped - 34 lines] >> -- >> Rhino Thomas Weidenfeller - 08 Mar 2006 08:17 GMT > I think he was looking for help not an observation on how stupid the > assignment was! This is a discussion group, not a help desk. In particular, this is not a do-my-homework service, and this group does not replace tutors, professors and teachers. And, probably the most important, it is not a replacement for engaging the own brain and reading the course textbook and course notes.
> If you weren't going to provide any help, what was the point of your post? > other than to tell him that his terminology was incorrect, the assignment > was dumb and useless, and finally that you weren't going to help??? Setting one straight on the terminology is indeed help. If one can't communicate in the language of the trade he has a serious problem he might want to work on. And since the primary job of a student is to learn something, such a hint is a great opportunity to learn.
A student like you who gets annoyed when someone is presented with an an opportunity to learn something should seriously ask if studying is the right thing to do.
> SPECIAL NOTE: > Many times college and university professors hand out really dumb and > totally useless assignments. Your job as a student is to complete those > assignments to the best of your abilities. Ye,. *YOUR* abilities, not ours. We do you students a courtesy if we point out where their abilities are lacking. E.g. abilities in formulating a coherent question.
> Providing comments about how > useless and stupid the assignments are doesn't help get the job done! It is not up to you to dictate what people have to answer. You have no right to get an answer at all. You have no right to get the answer you want to hear. You have not even a right to get read.
If one can't stand criticisms one better not posts to a public discussion group. If one wants to cheat on an homework assignment one better not posts to a public discussion group, too.
/Thomas
 Signature The comp.lang.java.gui FAQ: ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
Chris Uppal - 08 Mar 2006 10:10 GMT [...]
> It is not up to you to dictate what people have to answer. You have no > right to get an answer at all. You have no right to get the answer you > want to hear. You have not even a right to get read. I don't think Tail_Spin is connected with the OP.
-- chris
Tail_Spin - 08 Mar 2006 10:14 GMT > > I think he was looking for help not an observation on how stupid the > > assignment was! [quoted text clipped - 4 lines] > replacement for engaging the own brain and reading the course textbook > and course notes. Agreed completely!
> > If you weren't going to provide any help, what was the point of your post? > > other than to tell him that his terminology was incorrect, the assignment [quoted text clipped - 4 lines] > might want to work on. And since the primary job of a student is to > learn something, such a hint is a great opportunity to learn. To learn, know, and use the terminology correctly is a great asset and you must be able to communicate correct meanings in your post. However, I took exception with the attitude and presentation of Rhino's post.
> A student like you who gets annoyed when someone is presented with an > an opportunity to learn something should seriously ask if studying is > the right thing to do. I don't recall saying anywhere that I am currently a student? Yes I was a student of Computer Information Systems at my local university where I worked hard enough to be on the dean's list for 3 consecutive years, (Unfortunately because of medical reasons I was unable to continue with school.). But that doesn't give me the right to impress upon people how smart I am or imply how stupid their questions or projects are. I also didn't see anywhere where AMT2K5 said he was in school, maybe he is trying to learn Java on his own and doesn't have a clear enough understanding of what it is he is trying to do. You know what they say about assumptions right?
I too have been involved with computers both with hardware and programming for about 20 years. So I'm not a total newbie but I am a relative newbie to java. One thing I have learned is the more you learn about computers and programming, the more you realize you've only scratch the surface in this whole technologically changing world. So all of us need to be wary about trying impress people with how much we know in any area of technology, it's a constant learning environment.
> > SPECIAL NOTE: > > Many times college and university professors hand out really dumb and [quoted text clipped - 4 lines] > point out where their abilities are lacking. E.g. abilities in > formulating a coherent question. True, my bad, ... I forgot you are so much smarter than the rest of us newbies, "We do you students a courtesy". Don't tell me, ... let me guess, you're some college or university professor with a head-up-your-a.s attitude, probably with a masters or doctorate, and you feel your are so much superior than all the rest of us right?
> > Providing comments about how > > useless and stupid the assignments are doesn't help get the job done! > > It is not up to you to dictate what people have to answer. You have no > right to get an answer at all. You have no right to get the answer you > want to hear. You have not even a right to get read.
> If one can't stand criticisms one better not posts to a public > discussion group. If one wants to cheat on an homework assignment one > better not posts to a public discussion group, too. Fine criticise if you feel the need, but at least provide a viable solution, if not then your are just spewing out trash. And as far as the cheating goes, I agree completely. I've seen too many students that don't deserve to be in any kind of IT program. They think IT is the way to big $$$$ and they don't have a first clue what to do when it comes to writing code, can't even perform any kind of premitive debugging without some kind of fancy wysiwyg IDE to help them.
So there, I've said my negative piece and only about 2 weeks after I made a comment on this news group about all the negativism you keep seeing on news groups these days. I feel ashamed to have to stoop to such a low level, but I also feel I have to say my piece too.
Oh and remember --> If one can't stand criticisms one better not posts to a public discussion group.
> /Thomas > -- > The comp.lang.java.gui FAQ: > ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq > http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/ Rhino - 08 Mar 2006 18:00 GMT >> > I think he was looking for help not an observation on how stupid the >> > assignment was! [quoted text clipped - 22 lines] > took > exception with the attitude and presentation of Rhino's post. Well, if it makes you feel any better, it wasn't my proudest moment either. But I stand by the contention that it is an unrealistic assignment.
>> A student like you who gets annoyed when someone is presented with an >> an opportunity to learn something should seriously ask if studying is [quoted text clipped - 3 lines] > student of Computer Information Systems at my local university where I > worked hard enough to be on the dean's list for 3 consecutive years, Hmm, now who's trying to impress people....
> (Unfortunately because of medical reasons I was unable to continue with > school.). But that doesn't give me the right to impress upon people how [quoted text clipped - 13 lines] > it's > a constant learning environment. You could stand to take some of your own advice with regards to assumptions. I was NOT trying to impress anyone; I was simply saying that in 25 years in IT, I had never heard of a 'data script'. This may be a common term in some areas but it isn't in any of the areas where I have worked. I only mentioned 25 years to indicate that I was not an IT newbie that may not have heard the term yet. Period.
>> > SPECIAL NOTE: >> > Many times college and university professors hand out really dumb and >> > totally useless assignments. Your job as a student is to complete >> > those >> > assignments to the best of your abilities. In my opinion, giving out dumb and totally useless assignments is almost a total waste of time for the student who wants to learn something that will be useful in later professional work. That's why I reacted the way I did; it just feels wrong to cater to the kind of silliness inherent in the assignment - assuming it WAS an assignment; it sounded like one to me.
>> Ye,. *YOUR* abilities, not ours. We do you students a courtesy if we >> point out where their abilities are lacking. E.g. abilities in [quoted text clipped - 37 lines] > but > I also feel I have to say my piece too. Rhino
> Oh and remember --> If one can't stand criticisms one better not posts to > a [quoted text clipped - 5 lines] >> ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq >> http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/ Tail_Spin - 08 Mar 2006 20:39 GMT Sorry for the personal attack, Rhino. I didn't start out trying to get personal, I guess I just went overboard. I'm get'n a little bit tired of people in the news groups being negative and I guess I let it get to me. I see a lot of people in the computing industry trying to usurp their level on the tech pecking order. We all were newbies at one time and shouldn't forget that fact. And when people are asking a questions that seem really dumb at the time, we as a programming community should try to help them as much as we can.
I absolutely agree %100 about students doing their own assignments though. Most assignments are doable if you pay attention and do the prep-work that is required to compete the assignments. Because of my previous experience in assembler and C, I had a lot of fellow students ask to see my code when I was in school, (usually when the assignment was due the next day). However, I would not give them much if any of my code, but rather try to provide direction and basic pseudo-code. I'm no brain, probably a bit below average because I'm a bit ADD, (attention deficit disorder), so I had to bust me a.s to get decent grades, and it really pissed me off to see lazy-a.s kids coasting though school, just riding on other peoples work.
I just think one of the main purpose of the news groups should be to help people with their programming problems. But as in all aspects of pretty well any kind of programming, there always seems to be this "I'm starter than you" or "I'm more experienced than you (insult)" pecking-order attitude that seems to be quite prevelent. And I really hate that, because we are all just trying to figure this stuff out and get better at it.
> >> > I think he was looking for help not an observation on how stupid the > >> > assignment was! [quoted text clipped - 125 lines] > >> ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq > >> http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/ Chris Uppal - 08 Mar 2006 10:19 GMT > "Data script"??? > > Is this a term you invented yourself? Because if your teacher told you > this, you need a new teacher. In 25+ years in IT, I've never heard of a > 'data script'. Ah, but you are also the person who thought that splitting certain ranges of characters out of every line of an input file was an unrealistic excersize for a student. The guy[*] who had never heard of any real-world application for such an operation in all his years in the industry ;-)
([*] I assume for simplicity of grammar)
> Because I can't picture any professional > organization doing it that way. I can. I can also imagine the same organisation using the term "data script". It looks very like a format that was designed originally for data-entry clerks to type in. (In which case a file containing the same format text is quite naturally called a "data script"). Obviously that would be quite some time ago -- before these updstart SQL databases became fashionable -- but that doesn't mean the term was never valid. And some teachers are quite old too, you know. What's more, they may know a lot that we (who hardly ever have to deal with bandwidth/latency/RAM issues when simply processing data) miss out on.
-- chris
Rhino - 08 Mar 2006 18:13 GMT >> "Data script"??? >> [quoted text clipped - 9 lines] > for > such an operation in all his years in the industry ;-) You should reread that thread. I explained that I was construing that question in a much narrower way than the rest of the group had. Maybe you missed that?
> ([*] I assume for simplicity of grammar) Your assumption is correct.
>> Because I can't picture any professional >> organization doing it that way. [quoted text clipped - 7 lines] > ago -- before these updstart SQL databases became fashionable -- but that > doesn't mean the term was never valid. Agreed. I did not state categorically that this term was never used anywhere at any time in the course of human history though; I simply said *I* had never heard it. Have you heard anyone use the term 'data script'? Maybe this is a common term in the UK?
By the same token, I've never once seen an input file that was laid out like the original poster describes. Have you? It seems to me that such a file would always be cleaned up at least a little bit along the lines I suggested, even if it wasn't properly normalized.
>And some teachers are quite old too, > you know. What's more, they may know a lot that we (who hardly ever have > to > deal with bandwidth/latency/RAM issues when simply processing data) miss > out > on. Agreed. I still remember learning from 'old-timers' when I was getting started and use some of their lessons to this day, although I've found that I had to discard many as being inapplicable to modern computing. But basic values like clarity, avoiding 'cutesy' code, documenting your work are key parts of what I do.
Aside from the terminology nitpick over 'data script', my concern was basically that the assignment wasn't very representative of what a real life IT person would encounter in a real IT organization. Frankly, I think that makes the assignment almost pointless. It's a bit like learning how to build ramps so that you can jump your car over a narrow river; yes it's possible but it isn't how most people use a car so it makes more sense to learn something useful, like how to drive in heavy traffic. I think the original poster's teacher was largely wasting the original poster's time. In the end, I didn't feel right about reinforcing that foolishness by helping the student solve a silly question.
-- Rhino
Chris Uppal - 09 Mar 2006 11:26 GMT > You should reread that thread. I explained that I was construing that > question in a much narrower way than the rest of the group had. Maybe you > missed that? Fair enough. I didn't take that message from the post where you "recanted".
> Agreed. I did not state categorically that this term was never used > anywhere at any time in the course of human history though; I simply said > *I* had never heard it. Have you heard anyone use the term 'data script'? > Maybe this is a common term in the UK? I haven't heard it myself (I would have said so if I had). But it seems perfectly reasonable that it would turn up. "Data" is obvious. "Script" makes sense when you consider that one meaning of that word is as a transcript of something that has occurred, and especially a transcript that can be replayed. And it was that later sense, of a transcript of a data-entry session which had been saved to file, and which could be re-entered by "replaying" the file, that I find persuasive.
It does sound like the kind of expression that is more likely to have come from fairly old contexts (where a lot of concepts are given different names), but since the "old" contexts are still alive and well....
> By the same token, I've never once seen an input file that was laid out > like the original poster describes. Have you? It seems to me that such a > file would always be cleaned up at least a little bit along the lines I > suggested, even if it wasn't properly normalized. Yes, I have. Quite often.
Note that it is formally identical to CSV or the like. Instead of using the line-terminator to delimit records, and comma or tab to delimit fields within a record, it uses a line-terminator to delimit fields, and a # (or newline-#-newline) to delimit records. Perfectly normal, and in some ways more readable than CSV. But the important thing is that it is (with some fudging about what a line terminator is exactly) the /same/ as CSV. If one makes sense then so does the other.
It's difficult to tell whether it's a sensible programming exercise because I don't know what tools (concepts, classes, packages) the students have already covered[*]. But assuming a reasonable coverage of IO and iteration concepts, I would say that it's a pretty good example of simple parsing.
([*] My impression from the OPs post is that in this case the example has been used too soon, before concepts like streams have been introduced.)
> Aside from the terminology nitpick over 'data script', my concern was > basically that the assignment wasn't very representative of what a real > life IT person would encounter in a real IT organization. Frankly, I > think that makes the assignment almost pointless. You sound as if you think that all data processing should be done via formalised relational (or at least SQL) databases. I don't know whether you /really/ think that, but I certainly don't.
In any case, this isn't an example of data processing, but of of parsing.
-- chris
Martin Gregorie - 09 Mar 2006 17:44 GMT > In any case, this isn't an example of data processing, but of of parsing. Quite.
What's more to the point is that, in a *NIX environment anyway, you wouldn't use Java to process that sort of data: its a job for awk or Perl (and for Perl in a lot of other environments too).
I'd expect a programmer to be able to justify not using awk or Perl just as I'd expect a properly designed student project to deduct marks for not using them without a good explanation.
OK, I'll stretch a point and allow the use of Coco/R to generate a Java program or lex+yacc to do the same for C, *but* I'd still want to hear justification.
 Signature martin@ | Martin Gregorie gregorie. | Essex, UK org |
Oliver Wong - 07 Mar 2006 22:30 GMT > Hello, > [quoted text clipped - 84 lines] > Each pair between the sharps are the two attributes for the current > object this. It's not clear (to me at least) what your program is supposed to do. What does it mean to have a "data script in a StringBuffer"? What are the types of the fields of InventoryItem?
Maybe you should post an SSCCE http://mindprod.com/jgloss/sscce.html
- Oliver
Chris Uppal - 08 Mar 2006 10:52 GMT > I want to update each object's attributes consisting of Product and > Unit/Package, by using the update function (public int > update(StringBuffer sb)) . This is really very odd. Are you sure that's what the question is asking you to do ? It's not normal to use a StringBuffer to hold data that you are reading from, they are much more commonly use to build Strings.
You /can/ use one to take input data apart, but you'll destroy the data in the process, and it's not a way of doing it that would occur to an ordinary Java programmer.
What you can do is use a loop, plus characterAt() to find where the first line in the buffer ends. The use substring() to create a new String from the first However many characters that is. Then use delete() to remove those characters from the start of the buffer (including the line terminator). Then you do that again to pull out the second line. Then you do it a third time to pull out the line that consists of just # (which you discard). That gives you the two strings which you can use to update one InventoryItem. Then you put all that inside another loop which will update all the InventoryItems. By the end of the loop, you shouldn't have any data left in the StringBuffer, and you shouldn't have any InventoryItems left to process. If you have, then you've done something wrong ;-)
But I repeat: code like that is /very/ strange, and you'd never (I hope!) see a working Java programmer writing it. So I still suspect that the question was actually asking for something else entirely.
-- chris
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|