CrUD for a table inside a file. Read a file name for CrUD operations from the console. The program is started with the following arguments: -c productName price quantity Argument values: where id is 8 characters. productName is 30 characters. price is 8 characters. quantity is 4 characters. -c adds
You must be signed in to leave a comment
26 January, 19:29
Good task. I think comments whose are below each task and help section are huge part of this site. Sometimes you read task desription, write program a few hours, can't validate, and that is the time to look into this two places. In this task description was a little not accurate (like don't show quotes mark in arguments). It was confusion, I know it was before task (or tasks) with crud, but reading this task conditions I was thinking that we need be prepare for any amount of name parts and I wrote program ready for that. Second thing I learned it was amazing String.format additional features I didn't knew before. String.format("%-8s%-30s%-8s%-4s") - I didn't knew that we can decide lenght in this (Could we call it "syntactic sugar"?). Third thing I was confused - why last four condition are red and eX. Answer was simple. My mind somehow was dazzled and I tried run program with arguments: -c 19847 "Swim trunks, blue" 59.00 12 I wrongly asummed that this element must have initial id. Never mind, thank you all guys, we run forward every day. It's pleasure for me learn with you toghether. Sorry for my english. I thought that I must upgrade my leanguage too, and I need more english practice, and I'll want write more comments.
20 February, 15:14
There is also Formatter class, which can write formated String directly to file in this example.
2 August 2022, 16:26
I feel that this exercise could do with some inputs and outputs to clarify some confusion. Hope it helps. input arguments -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket with reflection" 123456789 12345 -c "Snowboard jacket" 12345 1 output (with altered ids, manually & directly in file, so as to test incrementing indexes) 1#######Snowboard jacket with reflecti123456781234 12345678Snowboard jacket with reflecti123456781234 12345671Snowboard jacket with reflecti123456781234 12345673Snowboard jacket with reflecti123456781234 12345679Snowboard jacket with reflecti123456781234 12345678Snowboard jacket with reflecti123456781234 123456##Snowboard jacket##########12345###1### // added # instead of space because of commenting format on this site // notice that there shouldn't be a new line here // notice that you shouldn't expect that the last index is the greatest (maybe, not necessary?) // notice trimmed data from input to output, based on mentioned limits
29 March 2022, 20:08
What would happen with the given solution by CodeGym if the text file is empty? According to my test it will fail.
15 April 2021, 15:40
Wow, really tough exercise. Some of the requirements mislead me: In condition nr. 4: the quotation marks made me think that "-c productName price quantity" is the entered program argument, but it is entered without the quotation marks (big difference - array with 4 slots instead of one slot) For me, it wasn't clear if i should write the code for one set of arguments or multiple sets. (It's just for one!) And you have to check for args length to validate, even if other if - statements logically include this requirement. Still a really nice, challenging exercise. I'd love to know how other people solved this task.
17 December 2020, 12:00
The example output is confusing... Is 198479 the ID that follows 19847?
18 December 2020, 07:23
An example for seeing the structure of a file. Imagine that lines with id from 19848 to 198478 were deleted from the file.
21 October 2020, 10:47
For requirement 4 I'm getting the following recommendation message from the mentor: CodeGym security exception. You are performing a forbidden or potentially dangerous operation. When I run the task on IntelliJ the end result is as expected. Where does this security exception happens?
23 October 2020, 06:00
Please post your question with the attached solution in the section Help.
8 October 2019, 14:23
I don't have a clue why this isn't passing the test. It seems to work flawlessly with a test file. Please help me out here.
9 October 2019, 06:23
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
16 March 2019, 15:28
I have a question regarding this task and possibly the other Prices task and it is: In the args, are the values string values that contains 30 characters for productName, 8 in price, which includes the period, and 4 for quantity; and that if the string are not the mentioned lengths they have been padded out with spaces to fill the character length. And we have to add in the values without such spacing into the file. Am I correct?
18 March 2019, 08:49
in the args:in the file: 19846 - just an example | - to indicate the border
21 March 2019, 13:58
Cool, thanks for the clarification.
23 February 2021, 21:25
Where does 19846 come from? From the file or from the args? Or are we on another level of abstraction here?
4 March 2021, 15:44
19846 - just an example of id From the task condition: -c adds the product with the specified parameters to the end of the file, and generates an id by incrementing the maximum id found in the file.
14 February, 14:07
I still do not understand this sentence: "...generates an id by incrementing the maximum id found in the file." I agree with Bartlomiej. If 19846 is the current maximum id in the file, then I'd imagine the next id would be 19847.
14 February, 14:15
How I currently interpret the task conditions (to try to prevent myself from writing a dozen extra blocks of code)... is that the ids are random? And we're just iterating through and finding the largest one and incrementing that one?