Sorry for my newb question but I am here to learn!
I don't understand the set up of the task. Why are we reading a file from the console but also checking args? It says that the program is started with an argument - does that mean we are to assume that there will be data within the args array and then we read from the file to add more to the table?
Clarity
Under discussion
Comments (10)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa
24 August 2021, 10:23useful
Yeah, you're absolutely right 🤓
Oh, by the way, I'm back. I hope you are as happy about it as I am? 🥳🥂
Whether the procedure makes sense... there is no need to argue about that. You can do it and that's why our friends from Codegym will do it. You could also enter everything via the args or even everything via the keyboard, only, the task creators have decided otherwise.
To test your task you can add arguments to the run configuration (right click the little green arrow next to the main method and select modify run configuration).
And again another brilliant contribution from Lisa who managed to give Gellert a bit of a helping hand. But now spots on Gellert, who tirelessly and competently helps others here in the forum. 🥳🦸♂️👍👑
yeah, yeah, I'm back, what the heck, I'm back... crazy back 😜🤪
+1
Gellert Varga
24 August 2021, 10:39
:) yes, sometimes I need help too...
But I still don't know what "-c" is:(
The requirements of the task and the examples show that the arguments received by main() :
- productName is 30 characters and is a string
- price is 8 characters and must be a double.
etc.
But what the hell is "-c"?:) I understand what it is supposed to cause, but:
- How many characters is it?
- And what type is it?
0
Lisa
24 August 2021, 11:04
It's just a made up identifier. You could name it create as well. It does not matter at all. You just pass it to your program when you start it like java myproggie -c value1 value2 value3
Now inside your program you can access your args array and work with that passed data (which of course is of type String). Here the task creator asks you to check the first argument, and if it is equal to -c, you should create a new dataset and save it to file.
yeah, yeah... glad to help 😜🤪
0
Gellert Varga
24 August 2021, 11:18
OK, I finally get it now, thanx!:)
+1
Gellert Varga
24 August 2021, 12:33
I often use the command line to test my programs.
But until now, I didn't know that this is how to send arguments to start a prg, like this:
C:\TEST> java Solution C:\TEST\sourceFile.txt C:\TEST\outFile.txt
So thanks for the very useful information!!:)
Until now I could only test such argument passing tasks with the following trick:
:-D +1
Lisa
24 August 2021, 12:49
Yippie, an useful information from me 🥳💃🎊🎈
Maybe you can use the next as well. Program arguments are space delimited. However, if you need multiple space-delimited words in one element, you can group these words using quotation marks.
eg.: java Solution "Lisa the Great" Lisa the Great
inside your program you'll see that args[0] contains "Lisa the Great" whilst args[1] contains "Lisa"
Enough chit chat for today, back to the hard work, yeah yeah 🤪😜
0
Gellert Varga
24 August 2021, 13:13
Thank you, indeed useful!:)
0
Guadalupe Gagnon
24 August 2021, 14:37
The main() method accepts arguments just like any other method. These are called command line arguments because they are input when starting the program. IDE's are great and handle a lot of that work for you today, but before their time you literally had to start programs from the command line and add the correct program arguments. Nowadays, however, most programs, even written in java, are started on the GUI with a simple double click and you don't have to go through all those barbaric steps to start a program from the command line interface and enter command line arguments; but that doesn't mean they are completely obsolete. My home computer is a linux machine and there are still programs on it I start from the command line. The command line arguments are similar to this task, where I need a tag (such as "-c") first and then the values. You use different tag/values for different program operations.
0
Gellert Varga
25 August 2021, 14:16
Thanks for the explanation.
0
Gellert Varga
24 August 2021, 09:40useful
I have not yet done this task, I am only reading the requirements for the first time.
I also think the way the task is written is a bit confusing. For example, I don't understand what "-c" is.
Regarding your question, I think the String args is where main() should get the new product data, and the fileName is needed because that's the file you need to write the new product to, added to the end of the file, continuing the content already in the file (after reading the maximum id value from the file.)
+1