- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentDemo.java
More file actions
Latest commit
92 lines (90 loc) · 2.34 KB
/
Copy pathStudentDemo.java
File metadata and controls
92 lines (90 loc) · 2.34 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
importjava.util.*;
classStudent
{
staticintcount=0;
introllno;
Stringname;
doublemark1,mark2;
voidsetData(intr,Stringn,doublem1,doublem2)
{
this.rollno=r;
this.name=n;
this.mark1=m1;
this.mark2=m2;
count++;
}
voidgetData()
{
System.out.println("Rollno:"+this.rollno);
System.out.println("Name:"+this.name);
System.out.println("Mark1:"+this.mark1);
System.out.println("Mark2:"+this.mark2);
}
voidgetTotal()
{
doubletotal;
total=this.mark1+this.mark2;
System.out.println("Total:"+total);
}
protectedvoidfinalize()
{
count--;
}
staticvoidtotalcount()
{
System.out.println("Count:"+count);
}
}
classStudentDemo
{
publicstaticvoidmain(Stringargs[])
{
Scannerscan=newScanner(System.in);
introll,ch;
doublem1,m2;
Stringna;
Students1=newStudent();
System.out.println("Enter roll no:");
roll=scan.nextInt();
System.out.println("Enter name:");
na=scan.nextLine();
na=scan.nextLine();
System.out.println("Enter mark1:");
m1=scan.nextDouble();
System.out.println("Enter mark2:");
m2=scan.nextDouble();
s1.setData(roll,na,m1,m2);
s1.getData();
s1.getTotal();
Students2=newStudent();
System.out.println("Enter roll no:");
roll=scan.nextInt();
System.out.println("Enter name:");
na=scan.nextLine();
na=scan.nextLine();
System.out.println("Enter mark1:");
m1=scan.nextDouble();
System.out.println("Enter mark2:");
m2=scan.nextDouble();
s2.setData(roll,na,m1,m2);
s2.getData();
s2.getTotal();
Student.totalcount();
System.out.println("Would you like to delete student 1 or student 2:");
ch=scan.nextInt();
if(ch==1)
{
s1=null;
System.gc();
System.runFinalization();
Student.totalcount();
}
elseif(ch==2)
{
s2=null;
System.gc();
System.runFinalization();
Student.totalcount();
}
}
}