Skip to content

Commit 3b807b2

Browse files
committed
OOPS - designing of student management
1 parent d21c9bb commit 3b807b2

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

src/OOPS/Student.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ public class Student {
44
int age;
55
String name;
66

7-
/* *** this is compulsory in case of conflict
8-
Means - without this keyword it will target the nearest variable
9-
with this keyword it will target only the data members/attributes/instance fields. */
7+
/* *** this keyword is compulsory in case of conflict
8+
Means - without this keyword it will target the nearest variable.
9+
With this keyword it will target only the data members/attributes/instance fields. */
1010

1111

12-
// initialization via method
12+
// initialization via method
1313
void init(String n, int a) {
1414
this.name = n;
1515
this.age = a;
1616
}
17-
// compile time polymorphism
18-
//constructor overloading
17+
// compile time polymorphism
18+
// constructor overloading
1919
Student(){
2020

2121
}
2222

23-
// constructor initialisation
23+
// constructor initialisation
2424
Student(String n, int a) {
2525
this.name = n;
2626
this.age = a;

src/OOPS/StudentManagement.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package OOPS;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
public class StudentManagement {
10+
public static class Student{
11+
int studentId;
12+
String name;
13+
int age;
14+
String grade;
15+
HashMap<String, Integer> marks = new HashMap<>();
16+
double percentage;
17+
void accept() throws IOException {
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
System.out.println("Enter student id: ");
20+
studentId = Integer.parseInt(br.readLine());
21+
System.out.println("Enter name: ");
22+
name = br.readLine();
23+
System.out.println("Enter age: ");
24+
age = Integer.parseInt(br.readLine());
25+
System.out.println("Enter grade: ");
26+
grade = br.readLine();
27+
System.out.println("Enter marks of Maths: ");
28+
int mathsMarks = Integer.parseInt(br.readLine());
29+
System.out.println("Enter marks of English: ");
30+
int englishMarks = Integer.parseInt(br.readLine());
31+
System.out.println("Enter marks of Science: ");
32+
int scienceMarks = Integer.parseInt(br.readLine());
33+
marks.put("Maths: ", mathsMarks);
34+
marks.put("English: ", englishMarks);
35+
marks.put("Science: ", scienceMarks);
36+
}
37+
38+
void calculate(){
39+
int sum = 0;
40+
int noOfSubs = 0;
41+
for (Map.Entry<String, Integer> e: marks.entrySet()){
42+
sum += e.getValue();
43+
noOfSubs++;
44+
}
45+
percentage = (double) sum /noOfSubs;
46+
}
47+
void display(){
48+
System.out.println("Student Id: " + studentId);
49+
System.out.println("Name: " + name);
50+
System.out.println("Age: " + age);
51+
System.out.println("Grade: " + grade);
52+
System.out.println("Marks :-");
53+
for(var e: marks.entrySet()){
54+
System.out.println(e.getKey() + ": " + e.getValue());
55+
}
56+
System.out.printf("percentage: %.2f", percentage);
57+
}
58+
}
59+
public static void main(String[] args) throws IOException {
60+
Student s1 = new Student();
61+
s1.accept();
62+
s1.calculate();
63+
s1.display();
64+
}
65+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy