-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListOfObjects.java
More file actions
51 lines (46 loc) · 1.33 KB
/
Copy pathListOfObjects.java
File metadata and controls
51 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
class Student{
private int id;
private String name,address;
public Student(int id,String name,String address){
this.id = id;
this.name = name;
this.address = address;
}
private int getId(){
return id;
}
public String getAddress(){
return address;
}
public void showData(){
System.out.println("Name:"+name+"\nID:"+getId()+" Address:"+getAddress());
}
}
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Student> student = new ArrayList<>();
int n = sc.nextInt();
for(int i=0;i<n;i++){
System.out.println("Enter your id:");
int id = sc.nextInt();
System.out.println("Enter your name:");
String name = sc.next();
System.out.println("enter your address:");
String address = sc.next();
student.add(new Student(id,name,address));
}
System.out.println("The data stored in the arraylist is:");
for(Student ptr : student){
// System.out.println(ptr.showData());
ptr.showData();
}
// Student s1 = new Student(1,"charan","warangal");
// s1.showData();
//System.out.println("Hello World");
}
}