0
How to enter data in instance variables of object in arraylist from user on runtime in java?
Here is the code ArrayList<Employee> list = new ArrayList<Employee>(); Employee emp1 = new Employee("Saad", 1); Employee emp2 = new Employee("Arsh", 2); list.add(emp1); list.add(emp2); for (Employee employee : list) { System.out.println(employee.toString());
9 Respostas
+ 3
S.K i didn't get your question. Can you describe more please?
+ 3
Sample input and output pls
+ 2
S.K I will. But I need to know what kind of input you are going to take and the relevant output for it
+ 1
I need object array. Data should be entered through scanner from user.
It should work exactly the same, but need to take data from user through scanner. Can you help please ? Seniru Pasan [OFFLINE 👎]
+ 1
Code it please. I am struggling with it.
+ 1
Hope this helps:
https://code.sololearn.com/cSbSjTPNB9N1/?ref=app
Maybe a Hashmap could be also interesting for you: https://www.sololearn.com/learn/Java/2181/?ref=app
to implement a scanner:
Scanner input = new Scanner (System.in);
String name = input.nextLine ();
int id = input.nextInt ();
Employee emp = new Employee (name, id);
+ 1
Thanks Denise Roßberg
0
I am writing a statement.
0
1. I need a class Employee
2. Employee should have name and id.
3. Array should be dynamic, means users should enter how many employee data he needs to enter.
4. Then enter the values through scanner i.e name and id.
5. Print it.