What we need to do? If i understand corect we need to work with main(String [] args)... If somebody can give me a hint, or a link, or something... Tk you! I'm in a dark here! :(
I don't understand this task!
Resolved
Comments (11)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
7 February 2022, 22:47useful
The main() method can accept a String array at startup.
Its name is args.
Suppose someone sends you a String array. You just get this from somewhere.
You need to write a program that does something like this:
If you want to test your program, you can send arguments to main in the IntelliJ IDE. Someone else will explain this, because I'm not familiar with it exactly.
But there is a trick to test your program:
Just remember to delete this from the program when you want to send it to the validator...:) +2
Gellert Varga
7 February 2022, 22:57
There are good comments below the task:
https://codegym.cc/tasks/com.codegym.task.task17.task1710
0
Angel Stefan
7 February 2022, 23:35
So, i need to write a program pretend that args is an array with all the data i need? By default args[1]=name, args[2]=sex and args[3]=date, when args[0] = "-c" and all i need to do is to call the right args at the right moment... 🤔. When args[0]="-u"; i have another array and so on, no?
0
Ibrahim
8 February 2022, 07:37
Watch this video for to understanding: https://www.youtube.com/watch?v=QBLcP0kRqMw
If you don't understand the task, like myself when I went through this task, read through other people's code to gain an understanding of what to do. There is nothing wrong in doing so as long as you learn from them.
0
Gellert Varga
8 February 2022, 11:35
"So, i need to write a program pretend that args is an array with all the data i need?" - Yes.
"By default args[1]=name, args[2]=sex and args[3]=date, when args[0] = "-c". And all i need to do is to call the right args at the right moment." - Yes.
"When args[0]="-u"; i have another array and so on, no?"
When args[0] = "-u", then you have to work with an another type of args[] : this array has one more element, and the index of elements are different:
args[1] = id,
args[2] = name,
args[3] = sex,
and args[4] = date.
And so on.
0
Angel Stefan
8 February 2022, 16:58
for case -c:
if(args[0].equals("-c")) {
if (args[2].equals("m")) {
allPeople.add(Person.createMale(args[1], new Date(String.valueOf(new SimpleDateFormat(args[3], Locale.ENGLISH)))));
System.out.println(allPeople.size()-1); // here is the problem?
} else if (args[2].equals("f")) {
allPeople.add(Person.createFemale(args[1], new Date(String.valueOf(new SimpleDateFormat(args[3], Locale.ENGLISH)))));
System.out.println(allPeople.size()-1); // here is the problem?
}
}
Warning:
Be sure that the person is really added to the allPeople list. ???
This task is brutal :(
0
Guadalupe Gagnon
8 February 2022, 17:55useful
The problem is that the use of SimpleDateFormat is incorrect. Take a look at this simple java point example. This is just a brief example of how to use it with no lesson attached. You can search the java docs or other websites for this if you want.
Some tips:
- args[2] for this bit of code will either be "m" or "f", no other value. This means that you only need to check if it is one value, such as "m", and If it is not "m" then you dont need to check if it is "f". This code can be written as:
- When coding you should try not to type the same line more than one time. In the code you share the line:
is repeated twice. As it should be printed out no matter what args[2] is, then you can do this instead:
+1
Gellert Varga
8 February 2022, 20:05
Yes, the task was brutal for me too.
At first, just like you, I didn't understand a single word of the whole task-description...
I left the task there. I did 1-2 more levels of the course and after I got back to it.
I happened to read something about it somewhere (not in the CG courseware!) and then it started to become enlightened for me what the task requirement meant:)
To get Date object from a String with parse method:
Suppose we have a date string of this format:
2022/february.08-Tuesday
First you need to create an object of type DateFormat, in which you define the date pattern.
I enclose a table with the meaning of each letter (months, days, years, hours, etc.)
Based on the table, for the String with that pattern above, you need to define the following DateFormat object:
Then you can use this DateFormat object to convert the string to a Date object:
+1
Angel Stefan
8 February 2022, 20:07
Thank you all! In the end i was able to pass this killing task. After i understand what i need to do, thanks to Gellert Varga and i correct the way i used SimpleDateFormat.parse thanks to Guadalupe Gagnon i passed after 34 attempts. Tk you guy's! :)
+2
Gellert Varga
8 February 2022, 20:10
Good job!:)
+1
Guadalupe Gagnon
8 February 2022, 20:36
When I went through this course for the first time, back in 2018, it would take me just as many attempts (and sometimes more) to pass some of these tasks. It's normal when you first learn how to program so don't get discouraged and keep up the good work!!
+3