-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudent.java
155 lines (148 loc) · 5.13 KB
/
Student.java
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.util.Scanner;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
class Student{
private String Name;
private String PhoneNumber;
private String[] SubjectName;
private double Marks[];
private double TotalMarks;
private double Total;
private double Percentage;
private char Grade;
Student(){
}
Student(String name,String phoneNumber,String [] subjectName,double marks[]){
Name = name;
PhoneNumber = phoneNumber;
SubjectName = subjectName;
Marks = marks;
TotalMarks = marksCalculator();
Total=(100.0f)*Marks.length;
Percentage = (TotalMarks/Total)*100.0;
Grade = gradeCalculator();
}
public String getName(){
return Name;
}
public void setName(String name){
Name = name;
}
public String getPhoneNumber(){
return PhoneNumber;
}
public void setPhoneNumber(String phoneNumber){
PhoneNumber = phoneNumber;
}
public String [] getSubjectName(){
return SubjectName;
}
public void setSubjectName(String[] subjectName){
SubjectName = subjectName;
}
public double[] getMarks(){
return Marks;
}
public void setMarks(double[] marks){
Marks = marks;
}
public double getTotalMarks(){
return TotalMarks;
}
public double getPercentage(){
return Percentage;
}
public char getGrade(){
return Grade;
}
public double marksCalculator(){
double totalMarks = 0.0f;
for(int j=0;j<Marks.length;j++){
totalMarks+=Marks[j];
}
return totalMarks;
}
public char gradeCalculator()
{
char grade='D';
if(Percentage>=90.0){
grade='A';
}
else if(Percentage<90.0 && Percentage>=70.0){
grade='B';
}
else if(Percentage<70.0 && Percentage>=60.0){
grade='C';
}
else{
grade='D';
}
return grade;
}
public void printReport()
{
System.out.println("-----------------------------------------------------");
System.out.println(" REPORT CARD ");
System.out.println("-----------------------------------------------------");
System.out.println("Name : "+getName());
System.out.println("Phone Number : "+getPhoneNumber());
System.out.println("Marks : ");
for(int i=0;i<Marks.length;i++){
System.out.println((i+1)+" - "+SubjectName[i]+" : "+Marks[i]);
}
System.out.println("\nTotal Marks : "+getTotalMarks()+" Out Of "+Total);
System.out.print("Percentage : ");
System.out.printf("%.2f",getPercentage());
System.out.println(" %");
System.out.println("Grade : "+getGrade());
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
System.out.println("-----------------------------------------------------");
System.out.println(" Generated On : "+dtf.format(now));
System.out.println("-----------------------------------------------------");
}
public static String convertTitleCase(String input){
StringBuilder output = new StringBuilder(input.length());
boolean nextTitleCase = true;
for (char c : input.toCharArray()) {
if (Character.isSpaceChar(c)) {
nextTitleCase = true;
} else if (nextTitleCase && Character.isLowerCase(c)) {
c = Character.toTitleCase(c);
nextTitleCase = false;
}else if(Character.isUpperCase(c))
{
c=Character.toLowerCase(c);
}
output.append(c);
}
return output.toString();
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Number of Students : ");
int n = scanner.nextInt();
for(int i=1;i<=n;i++) {
System.out.println("Enter Name : ");
scanner.nextLine();
String name = scanner.nextLine();
System.out.println("Enter Phone Number : ");
String phoneNumber = scanner.next();
scanner.nextLine();
System.out.println("Enter Number of Subjects :");
int subjectNumber = scanner.nextInt();
String subject[]= new String[subjectNumber];
double marks[]=new double[subjectNumber];
System.out.println("Enter Subject Name Then Enter Marks of that Subject : ");
for(int j=0;j<subjectNumber;j++)
{
subject[j]=scanner.next();
marks[j]=scanner.nextDouble();
}
name = convertTitleCase(name);
Student ob=new Student(name,phoneNumber,subject,marks);
ob.printReport();
}
scanner.close();
}
}