Skip to content

Commit 58696d7

Browse files
committed
Course Program (IPA-35)
1 parent b85fdde commit 58696d7

2 files changed

Lines changed: 255 additions & 0 deletions

File tree

IPA1/courseProgram.java

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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+
}
154+
}

IPA1/courseProgram.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
create the class Course with the below Attributes.
2+
3+
courseId- int
4+
courseName- String
5+
courseAdmin- String
6+
quiz- int
7+
handson -int
8+
9+
The above methods should be private ,write getter and
10+
setter and parametrized constructor as required.
11+
12+
create class courseProgram with main method.
13+
14+
implement two static methods-
15+
findAvgOfQuizByAdmin method:this method will take array
16+
of Course objects and a String value as input parameters.
17+
This method will find out Average (as int) of Quiz questions
18+
for given Course Admin (String parametre passed)
19+
This method will return Average if found.if there is no course
20+
that matches then the method should return 0.
21+
22+
sortCourseByHandsOn method:
23+
This method will take an Array of Course Objects and int
24+
value as input parameters.
25+
This methods should return an Array of Course objects in an
26+
ascending order of their handson which are less than the
27+
given handson(int parameter passed) value. if there is no
28+
such course then the method should return null.
29+
30+
The above mentioned static methods should be called from
31+
main methods.
32+
33+
for findAvgOfQuizByAdmin method: The main method
34+
should print the average if the returned value is not 0.
35+
if the returned value is 0 then it should print "No Course
36+
found."
37+
38+
39+
for sortCourseByHandsOn method:
40+
the main method should print the name
41+
of the Course from the returned Course object Array if the
42+
returned value is not null.if the returned value is null then
43+
it should print "No Course found with mentioned attribute."
44+
45+
input1:
46+
111
47+
kubernetes
48+
Nisha
49+
40
50+
10
51+
321
52+
cassandra
53+
Roshini
54+
30
55+
15
56+
457
57+
Apache Spark
58+
Nisha
59+
30
60+
12
61+
987
62+
site core
63+
Tirth
64+
50
65+
20
66+
Nisha
67+
17
68+
69+
output1:
70+
35
71+
kubernetes
72+
Apache Spark
73+
cassandra
74+
75+
input2:
76+
111
77+
kubernetes
78+
Nisha
79+
40
80+
10
81+
321
82+
cassandra
83+
Roshini
84+
30
85+
15
86+
457
87+
Apache Spark
88+
Nisha
89+
30
90+
12
91+
987
92+
site core
93+
Tirth
94+
50
95+
20
96+
Shubhamk
97+
5
98+
99+
output 2:
100+
No Course found
101+
No Course found with mentioned attributes.

0 commit comments

Comments
 (0)