-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path31_ObjectPassing1.java
More file actions
131 lines (119 loc) · 3.41 KB
/
31_ObjectPassing1.java
File metadata and controls
131 lines (119 loc) · 3.41 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
127
128
129
130
131
/*
* Program on object passing taking input from user
*/
package javaprograms;
import java.io.*;
/**
*
* @author Geeky Keshav
*/
public class ObjectPassing1
{
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_marks1
{
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());
ObjectPassing1 obj1=new ObjectPassing1();
obj1.name=n;
obj1.rollno=r;
obj1.perc=p;
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());
ObjectPassing1 obj2=new ObjectPassing1();
obj2.name=n;
obj2.rollno=r;
obj2.perc=p;
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());
ObjectPassing1 obj3=new ObjectPassing1();
obj3.name=n;
obj3.rollno=r;
obj3.perc=p;
std_grade(obj1);
obj1.disp();
std_grade(obj2);
obj2.disp();
std_grade(obj3);
obj3.disp();
}
static void std_grade(ObjectPassing1 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: kk
Enter Roll No.: 1
Enter Percentage of the Student: 95.5
***********************
Enter name of the Student: kkk
Enter Roll No.: 2
Enter Percentage of the Student: 95.0
***********************
Enter name of the Student: kkkk
Enter Roll No.: 3
Enter Percentage of the Student: 60
***********************
Student name: kk
Student Roll no.: 1
Student's Percentage: 95.5
Student's Grade: A
***********************
***********************
Student name: kkk
Student Roll no.: 2
Student's Percentage: 95.0
Student's Grade: A
***********************
***********************
Student name: kkkk
Student Roll no.: 3
Student's Percentage: 60.0
Student's Grade: F
***********************
*/