Skip to content

Commit 1c849f0

Browse files
committed
Student (IPA-35)
1 parent 6166c30 commit 1c849f0

File tree

2 files changed

+138
-141
lines changed

2 files changed

+138
-141
lines changed
Lines changed: 138 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,139 @@
1-
//C:\Users\ariji\OneDrive\Desktop\Mouse\Java\TCS-IPA3.docx
2-
package Java;
3-
4-
import java.util.*;
5-
6-
public class IPA3 {
7-
public static void main(String[] args) {
8-
Student[] student = new Student[4];
9-
Scanner sc = new Scanner(System.in);
10-
for(int i=0; i<student.length; i++)
11-
{
12-
int a = sc.nextInt();sc.nextLine();
13-
String b = sc.nextLine();
14-
String c = sc.nextLine();
15-
double d = sc.nextDouble();sc.nextLine();
16-
boolean e = sc.nextBoolean();
17-
18-
student[i] = new Student(a,b,c,d,e);
19-
}
20-
21-
int ans1 = findCountofDayscholarStudents(student);
22-
if(ans1>0)
23-
{
24-
System.out.println(ans1);
25-
}
26-
else
27-
{
28-
System.out.println("No student found");
29-
}
30-
31-
Student ans2 = findStudentWithSecondHighestScore(student);
32-
if(ans2== null)
33-
{
34-
System.out.println("No student found");
35-
}
36-
else{
37-
System.out.println(ans2.getRollNo()+"#"+ans2.getName()+"#"+ans2.getScore());
38-
}
39-
}
40-
public static int findCountofDayscholarStudents(Student[] student)
41-
{
42-
int count=0;
43-
for(int i=0; i<student.length; i++)
44-
{
45-
if (student[i].getDayScholar()==true && student[i].getScore()>80)
46-
{
47-
count++;
48-
}
49-
}
50-
if(count>0)
51-
{
52-
return count;
53-
}
54-
return 0;
55-
}
56-
public static Student findStudentWithSecondHighestScore(Student[] student)
57-
{
58-
double[] arr = new double[0]; // length of array = 0
59-
for(int i=0; i<student.length; i++)
60-
{
61-
if(student[i].getDayScholar()==false)
62-
{
63-
arr = Arrays.copyOf(arr,arr.length+1); // length of array = 1
64-
arr[arr.length-1] = student[i].getScore();
65-
}
66-
}
67-
Arrays.sort(arr);
68-
double shs = arr[arr.length-2];
69-
for(int i=0; i<student.length; i++)
70-
{
71-
if(student[i].getScore()== shs)
72-
{
73-
return student[i];
74-
}
75-
}
76-
77-
return null;
78-
}
79-
}
80-
class Student
81-
{
82-
private int rollNo;
83-
private String name;
84-
private String branch;
85-
private double score;
86-
private boolean dayScholar;
87-
88-
// constructor
89-
90-
public Student(int rollNo, String name, String branch, double score, boolean dayScholar)
91-
{
92-
this.rollNo = rollNo;
93-
this.name = name;
94-
this.branch = branch;
95-
this.score = score;
96-
this.dayScholar = dayScholar;
97-
}
98-
99-
// getter and setter to access by main method
100-
101-
public int getRollNo()
102-
{
103-
return rollNo;
104-
}
105-
public void setRollNo(int rollNo)
106-
{
107-
this.rollNo = rollNo;
108-
}
109-
public String getName()
110-
{
111-
return name;
112-
}
113-
public void setName(String name)
114-
{
115-
this.name= name;
116-
}
117-
public String getBranch()
118-
{
119-
return branch;
120-
}
121-
public void setBranch(String branch)
122-
{
123-
this.branch = branch;
124-
}
125-
public double getScore()
126-
{
127-
return score;
128-
}
129-
public void setScore(double score)
130-
{
131-
this.score = score;
132-
}
133-
public boolean getDayScholar()
134-
{
135-
return dayScholar;
136-
}
137-
public void setDayScholar(boolean dayScholar)
138-
{
139-
this.dayScholar = dayScholar;
140-
}
141-
1+
package IPA3;
2+
import java.util.*;
3+
public class IPA3 {
4+
public static void main(String[] args) {
5+
Student[] student = new Student[4];
6+
Scanner sc = new Scanner(System.in);
7+
for(int i=0; i<student.length; i++)
8+
{
9+
int a = sc.nextInt();sc.nextLine();
10+
String b = sc.nextLine();
11+
String c = sc.nextLine();
12+
double d = sc.nextDouble();sc.nextLine();
13+
boolean e = sc.nextBoolean();
14+
15+
student[i] = new Student(a,b,c,d,e);
16+
}
17+
18+
int ans1 = findCountofDayscholarStudents(student);
19+
if(ans1>0)
20+
{
21+
System.out.println(ans1);
22+
}
23+
else
24+
{
25+
System.out.println("No student found");
26+
}
27+
28+
Student ans2 = findStudentWithSecondHighestScore(student);
29+
if(ans2== null)
30+
{
31+
System.out.println("No student found");
32+
}
33+
else{
34+
System.out.println(ans2.getRollNo()+"#"+ans2.getName()+"#"+ans2.getScore());
35+
}
36+
}
37+
public static int findCountofDayscholarStudents(Student[] student)
38+
{
39+
int count=0;
40+
for(int i=0; i<student.length; i++)
41+
{
42+
if (student[i].getDayScholar()==true && student[i].getScore()>80)
43+
{
44+
count++;
45+
}
46+
}
47+
if(count>0)
48+
{
49+
return count;
50+
}
51+
return 0;
52+
}
53+
public static Student findStudentWithSecondHighestScore(Student[] student)
54+
{
55+
double[] arr = new double[0]; // length of array = 0
56+
for(int i=0; i<student.length; i++)
57+
{
58+
if(student[i].getDayScholar()==false)
59+
{
60+
arr = Arrays.copyOf(arr,arr.length+1); // length of array = 1
61+
arr[arr.length-1] = student[i].getScore();
62+
}
63+
}
64+
Arrays.sort(arr);
65+
double shs = arr[arr.length-2];
66+
for(int i=0; i<student.length; i++)
67+
{
68+
if(student[i].getScore()== shs)
69+
{
70+
return student[i];
71+
}
72+
}
73+
74+
return null;
75+
}
76+
}
77+
class Student
78+
{
79+
private int rollNo;
80+
private String name;
81+
private String branch;
82+
private double score;
83+
private boolean dayScholar;
84+
85+
// constructor
86+
87+
public Student(int rollNo, String name, String branch, double score, boolean dayScholar)
88+
{
89+
this.rollNo = rollNo;
90+
this.name = name;
91+
this.branch = branch;
92+
this.score = score;
93+
this.dayScholar = dayScholar;
94+
}
95+
96+
// getter and setter to access by main method
97+
98+
public int getRollNo()
99+
{
100+
return rollNo;
101+
}
102+
public void setRollNo(int rollNo)
103+
{
104+
this.rollNo = rollNo;
105+
}
106+
public String getName()
107+
{
108+
return name;
109+
}
110+
public void setName(String name)
111+
{
112+
this.name= name;
113+
}
114+
public String getBranch()
115+
{
116+
return branch;
117+
}
118+
public void setBranch(String branch)
119+
{
120+
this.branch = branch;
121+
}
122+
public double getScore()
123+
{
124+
return score;
125+
}
126+
public void setScore(double score)
127+
{
128+
this.score = score;
129+
}
130+
public boolean getDayScholar()
131+
{
132+
return dayScholar;
133+
}
134+
public void setDayScholar(boolean dayScholar)
135+
{
136+
this.dayScholar = dayScholar;
137+
}
138+
142139
}
File renamed without changes.

0 commit comments

Comments
 (0)