1- import java .util .*;
2- public class courseProgram
3- {
4- public static void main (String [] args )
5- {
6- Scanner sc = new Scanner (System .in );
7- Course [] course = new Course [4 ];
8- for (int i =0 ; i <4 ; i ++)
9- {
10- int a = sc .nextInt ();sc .nextLine ();
11- String b = sc .nextLine ();
12- String c = sc .nextLine ();
13- int d = sc .nextInt ();sc .nextLine ();
14- int e = sc .nextInt ();sc .nextLine ();
15-
16- course [i ] = new Course (a ,b ,c ,d ,e );
17- }
18- String admin = sc .nextLine ();
19- int hand = sc .nextInt ();
20-
21- int ans1 = findAvgOfQuizByAdmin (course , admin );
22- if (ans1 !=0 )
23- {
24- System .out .println (ans1 );
25- }
26- else
27- {
28- System .out .println ("No Course found" );
29- }
30-
31- Course [] ans2 = sortCourseByHandsOn (course , hand );
32- if (ans2 !=null )
33- {
34- for (int i =0 ; i <ans2 .length ; i ++)
35- {
36- System .out .println (ans2 [i ].getCname ());
37- }
38- }
39- else
40- {
41- System .out .println ("No Course found with mentioned attribute." );
42- }
43- }
44- public static int findAvgOfQuizByAdmin (Course []course , String ad )
45- {
46- int sum =0 , count =0 ;
47- for (int i =0 ; i <course .length ; i ++)
48- {
49- if (course [i ].getCadmin ().equalsIgnoreCase (ad ))
50- {
51- sum = sum +course [i ].getQuiz ();
52- count ++;
53- }
54- }
55- if (count >0 )
56- {
57- int avg = sum /count ;
58- return avg ;
59- }
60- else
61- {
62- return 0 ;
63- }
64- }
65-
66- public static Course [] sortCourseByHandsOn (Course [] course , int h )
67- {
68- Course [] obj = new Course [0 ];
69- for (int i =0 ; i <course .length ; i ++)
70- {
71- if (course [i ].getHandson ()<h )
72- {
73- obj = Arrays .copyOf (obj , obj .length +1 );
74- obj [obj .length -1 ] = course [i ];
75- }
76- }
77- Course val ;
78- for (int i =0 ;i <obj .length ;i ++)
79- {
80- for (int j =i +1 ; j <obj .length ; j ++)
81- {
82- if (obj [i ].getHandson ()>obj [j ].getHandson ())
83- {
84- val = obj [i ];
85- obj [i ] = obj [j ];
86- obj [j ] = val ;
87- }
88- }
89- }
90- if (obj .length >0 )
91- {
92- return obj ;
93- }
94- else
95- {
96- return null ;
97- }
98- }
99- }
100- class Course
101- {
102- private int cid , quiz , handson ;
103- private String cname , cadmin ;
104-
105- public Course (int cid , String cname , String cadmin , int quiz , int handson )
106- {
107- this .cid = cid ;
108- this .cname = cname ;
109- this .cadmin = cadmin ;
110- this .quiz = quiz ;
111- this .handson = handson ;
112- }
113-
114- public int getCid ()
115- {
116- return cid ;
117- }
118- public void setCid (int cid )
119- {
120- this .cid = cid ;
121- }
122- public String getCname ()
123- {
124- return cname ;
125- }
126- public void setCname (String cname )
127- {
128- this .cname = cname ;
129- }
130- public String getCadmin ()
131- {
132- return cadmin ;
133- }
134- public void setCadmin (String cadmin )
135- {
136- this .cadmin = cadmin ;
137- }
138- public int getQuiz ()
139- {
140- return quiz ;
141- }
142- public void setQuiz (int quiz )
143- {
144- this .quiz = quiz ;
145- }
146- public int getHandson ()
147- {
148- return handson ;
149- }
150- public void setHandson (int handson )
151- {
152- this .handson = handson ;
153- }
1+ import java .util .*;
2+ public class courseProgram
3+ {
4+ public static void main (String [] args )
5+ {
6+ Scanner sc = new Scanner (System .in );
7+ Course [] course = new Course [4 ];
8+ for (int i =0 ; i <4 ; i ++)
9+ {
10+ int a = sc .nextInt ();sc .nextLine ();
11+ String b = sc .nextLine ();
12+ String c = sc .nextLine ();
13+ int d = sc .nextInt ();sc .nextLine ();
14+ int e = sc .nextInt ();sc .nextLine ();
15+
16+ course [i ] = new Course (a ,b ,c ,d ,e );
17+ }
18+ String admin = sc .nextLine ();
19+ int hand = sc .nextInt ();
20+
21+ int ans1 = findAvgOfQuizByAdmin (course , admin );
22+ if (ans1 !=0 )
23+ {
24+ System .out .println (ans1 );
25+ }
26+ else
27+ {
28+ System .out .println ("No Course found" );
29+ }
30+
31+ Course [] ans2 = sortCourseByHandsOn (course , hand );
32+ if (ans2 !=null )
33+ {
34+ for (int i =0 ; i <ans2 .length ; i ++)
35+ {
36+ System .out .println (ans2 [i ].getCname ());
37+ }
38+ }
39+ else
40+ {
41+ System .out .println ("No Course found with mentioned attribute." );
42+ }
43+ }
44+ public static int findAvgOfQuizByAdmin (Course []course , String ad )
45+ {
46+ int sum =0 , count =0 ;
47+ for (int i =0 ; i <course .length ; i ++)
48+ {
49+ if (course [i ].getCadmin ().equalsIgnoreCase (ad ))
50+ {
51+ sum = sum +course [i ].getQuiz ();
52+ count ++;
53+ }
54+ }
55+ if (count >0 )
56+ {
57+ int avg = sum /count ;
58+ return avg ;
59+ }
60+ else
61+ {
62+ return 0 ;
63+ }
64+ }
65+
66+ public static Course [] sortCourseByHandsOn (Course [] course , int h )
67+ {
68+ Course [] obj = new Course [0 ];
69+ for (int i =0 ; i <course .length ; i ++)
70+ {
71+ if (course [i ].getHandson ()<h )
72+ {
73+ obj = Arrays .copyOf (obj , obj .length +1 );
74+ obj [obj .length -1 ] = course [i ];
75+ }
76+ }
77+ Course val ;
78+ for (int i =0 ;i <obj .length ;i ++)
79+ {
80+ for (int j =i +1 ; j <obj .length ; j ++)
81+ {
82+ if (obj [i ].getHandson ()>obj [j ].getHandson ())
83+ {
84+ val = obj [i ];
85+ obj [i ] = obj [j ];
86+ obj [j ] = val ;
87+ }
88+ }
89+ }
90+ if (obj .length >0 )
91+ {
92+ return obj ;
93+ }
94+ else
95+ {
96+ return null ;
97+ }
98+ }
99+ }
100+ class Course
101+ {
102+ private int cid , quiz , handson ;
103+ private String cname , cadmin ;
104+
105+ public Course (int cid , String cname , String cadmin , int quiz , int handson )
106+ {
107+ this .cid = cid ;
108+ this .cname = cname ;
109+ this .cadmin = cadmin ;
110+ this .quiz = quiz ;
111+ this .handson = handson ;
112+ }
113+
114+ public int getCid ()
115+ {
116+ return cid ;
117+ }
118+ public void setCid (int cid )
119+ {
120+ this .cid = cid ;
121+ }
122+ public String getCname ()
123+ {
124+ return cname ;
125+ }
126+ public void setCname (String cname )
127+ {
128+ this .cname = cname ;
129+ }
130+ public String getCadmin ()
131+ {
132+ return cadmin ;
133+ }
134+ public void setCadmin (String cadmin )
135+ {
136+ this .cadmin = cadmin ;
137+ }
138+ public int getQuiz ()
139+ {
140+ return quiz ;
141+ }
142+ public void setQuiz (int quiz )
143+ {
144+ this .quiz = quiz ;
145+ }
146+ public int getHandson ()
147+ {
148+ return handson ;
149+ }
150+ public void setHandson (int handson )
151+ {
152+ this .handson = handson ;
153+ }
154154}
0 commit comments