forked from icterguru/JavaProgrammingA2Z
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ09_34.java
More file actions
67 lines (67 loc) · 1.8 KB
/
J09_34.java
File metadata and controls
67 lines (67 loc) · 1.8 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package chapter09;
/* J09_34.java */
/* Implementing Array of Object using Vector */
import java.util.*;
class Student{
int Roll;
String Name;
double Mark;
Student NextStudent;
static Student StudentList;
static void paint()
{
Student S = StudentList;
if(S == null)
System.out.println("There is no student in the list");
else
do{
System.out.println(S);
S = S.NextStudent;
}while(S!=null);
}
Student (int Roll , String Name , double Mark)
{
this.Roll = Roll;
this.Name = Name;
this.Mark = Mark;
this.NextStudent = StudentList;
StudentList = this;
}
public String toString()
{
return new String(Roll + "\t" +Name + "\t" +Mark + "\n");
}
}
public class J09_34{
public static void main(String args[]){
Vector V = new Vector();
V.addElement(new Student(101, "Masud", 75.5));
V.addElement(new Student(102, "Monira",85.0));
V.addElement(new Student(103, "Monirul",80.0));
System.out.println("List of Students : ");
System.out.println("Roll: \t Name: \t Mark: ");
for (int i=0; i<V.size(); i++) {
System.out.print(V.elementAt(i));
// displaying i-th Element.
}
V.insertElementAt(new Student(104, "Mira",90), 1);
//Inserting a new Element at Position 1
System.out.println("\nAfter Inserting Element at Position 1 : ");
System.out.println("List of Students : ");
System.out.println("Roll: \t Name: \t Mark: ");
// displaying Modified Vector Elements.
for (int i=0; i<V.size(); i++) {
System.out.print(V.elementAt(i));
// displaying i-th Element.
}
V.removeElementAt(0);
//Removing Element of Position 0
System.out.println("\nAfter Removing Element of Position 0 : ");
System.out.println("List of Students : ");
System.out.println("Roll: \t Name: \t Mark: ");
for (int i=0; i<V.size(); i++) {
System.out.print(V.elementAt(i));
// displaying i-th Element.
}
}
}