-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path32_ObjectPassing2.java
More file actions
126 lines (117 loc) · 3.35 KB
/
32_ObjectPassing2.java
File metadata and controls
126 lines (117 loc) · 3.35 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Program on object passing taking input from user
*******NOT POSSIBLE*******
Cannot copy one object to another
*/
package javaprograms;
import java.io.*;
/**
*
* @author Geeky Keshav
*/
public class ObjectPassing2
{
String name;
int rollno;
float perc;
String grade;
void disp()
{
System.out.println("***********************");
System.out.println("Student name: "+name);
System.out.println("Student Roll no.: "+rollno);
System.out.println("Student's Percentage: "+perc);
System.out.println("Student's Grade: "+grade);
System.out.println("***********************");
}
}
class std_marks2
{
public static void main(String [] args)throws Exception
{
DataInputStream obj=new DataInputStream(System.in);
System.out.print("Enter name of the Student: ");
String n=obj.readLine();
System.out.print("Enter Roll No.: ");
int r=Integer.parseInt(obj.readLine());
System.out.print("Enter Percentage of the Student: ");
float p=Float.parseFloat(obj.readLine());
ObjectPassing2 obj1=new ObjectPassing2();
obj1.name=n;
obj1.rollno=r;
obj1.perc=p;
std_grade(obj1);
obj1.disp();
System.out.println("***********************");
System.out.print("Enter name of the Student: ");
n=obj.readLine();
System.out.print("Enter Roll No.: ");
r=Integer.parseInt(obj.readLine());
System.out.print("Enter Percentage of the Student: ");
p=Float.parseFloat(obj.readLine());
ObjectPassing2 obj2=new ObjectPassing2();
obj2=obj1;
std_grade(obj2);
obj2.disp();
System.out.println("***********************");
System.out.print("Enter name of the Student: ");
n=obj.readLine();
System.out.print("Enter Roll No.: ");
r=Integer.parseInt(obj.readLine());
System.out.print("Enter Percentage of the Student: ");
p=Float.parseFloat(obj.readLine());
ObjectPassing2 obj3=new ObjectPassing2();
obj3=obj1;
std_grade(obj3);
obj3.disp();
}
static void std_grade(ObjectPassing2 g)
{
if(g.perc>=80)
{
g.grade="A";
}
else if(g.perc>60 && g.perc<75)
{
g.grade="B";
}
else if(g.perc>=60 && g.perc<50)
{
g.grade="C";
}
else
g.grade="F";
}
}
/******OUTPUT****
run:
Enter name of the Student: kp
Enter Roll No.: 1
Enter Percentage of the Student: 60.5
***********************
Student name: kp
Student Roll no.: 1
Student's Percentage: 60.5
Student's Grade: B
***********************
***********************
Enter name of the Student: lp
Enter Roll No.: 2
Enter Percentage of the Student: 95
***********************
Student name: kp
Student Roll no.: 1
Student's Percentage: 60.5
Student's Grade: B
***********************
***********************
Enter name of the Student: kpkpk
Enter Roll No.: 3
Enter Percentage of the Student: 85.0
***********************
Student name: kp
Student Roll no.: 1
Student's Percentage: 60.5
Student's Grade: B
***********************
*/