+ 1

Should I quit learning programming ??

Stack overflow, reddit, facebook, youtube, sololearn every forum failed me. Nobody is ready to help me with the syntax of Object arraylist. I got the replies like learn it yourself. I am seriously disappointed on that.

8th Feb 2019, 8:22 PM
S.K
10 odpowiedzi
+ 4
S.K If you are referring to this query, then I don't think you realize what the problem is. https://www.sololearn.com/Discuss/1682270/?ref=app You provided your code, which is a good start. However, when requested to narrow down the scope of the problem, making it more specific so that it's easier for others to help you, you decided that it is a good idea to just throw the task out there and tell someone to complete it for you. Even up till this point, you haven't clearly explained the issue which needs to be rectified. Do you need help on the syntax of ArrayList (as has been described by Abdul Moqueet), or do you actually need help on using Scanner to input to ArrayList? If that is the case, how many input do you need? Have you tried to use loops, by any chance? Did you receive any errors? I did not downvote anything, but perhaps it would be a good idea to read these two links: https://idownvotedbecau.se/noattempt/ https://idownvotedbecau.se/noresearch/ We need you to help us, help you.
9th Feb 2019, 5:03 AM
Hatsy Rei
Hatsy Rei - avatar
+ 3
S.K You can't add elements to ArrayList that way. Instead, use the .add() method. https://www.tutorialspoint.com/java/util/arraylist_add_index.htm Also, you have an ArrayList of Employee, so you have to add an Employee object, something like: String name = input.nextLine(); int ID = input.nextInt(); Employee obj = new Employee(name, ID); list.add(obj);
9th Feb 2019, 12:45 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
hi S.K i’ve been told that when i started learning C# and i was so annoyed with it that i deleted the thread and nearly gave up C# however you should ignore these comments as these people often haven’t completed the course themselves and if they really annoy you report them to the mods. also i have very little idea about arrayList however this link may help you with arrayLists https://www.w3schools.com/java/java_arraylist.asp
8th Feb 2019, 8:29 PM
Ollie Q
Ollie Q - avatar
+ 2
Thank you for being helpful and kind. Ollie Q
8th Feb 2019, 8:31 PM
S.K
+ 2
I am so grateful to you. Thanks a lot.
9th Feb 2019, 4:11 PM
S.K
+ 1
Thanks Hatsy Rei for being kind and helpful.
9th Feb 2019, 12:47 PM
S.K
+ 1
Thank you so much Abdul Moqueet .
9th Feb 2019, 12:51 PM
S.K
+ 1
Abdul Moqueet there is one issue. Look at the for loop. The variables (name and id) are taking one time input. When the second loop comes it crashes. It even crashes when I try name[i] and id[i]. Please check it.
9th Feb 2019, 1:28 PM
S.K
0
public class Main { public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); List<Employee> list = new ArrayList<Employee>(); for (int i = 0; i < 2; i++) { System.out.println("Enter Name: "); list[0] = input.nextLine(); // error starts from here // System.out.println("Enter ID: "); } for (Employee employee : list) { System.out.println(employee.toString()); } } public class Employee { String name; int id; public Employee(String name, int id) { this.name = name; this.id = id; } @Override public String toString() { return "name = " + name + ", id = " + id; } } } This is the code I have tried and failed to do it. I want to take input from user for the object array. Hatsy Rei
9th Feb 2019, 12:39 PM
S.K