-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseProgram solution.txt
More file actions
125 lines (103 loc) · 2.88 KB
/
CourseProgram solution.txt
File metadata and controls
125 lines (103 loc) · 2.88 KB
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
package practice;
import java.util.Arrays;
import java.util.Scanner;
public class courseProgram {
public static void main(String[] args) {
Course[] courses=new Course[4];
Scanner sc=new Scanner(System.in);
for (int i = 0; i < 4; i++) {
int a=sc.nextInt();
sc.nextLine();
String b=sc.nextLine();
String c=sc.nextLine();
int d=sc.nextInt();
sc.nextLine();
int e=sc.nextInt();
sc.nextLine();
courses[i]=new Course(a,b,c,d,e);
}
String input1=sc.nextLine();
int input2=sc.nextInt();
sc.nextLine();
int ans1 = aab(courses, input1);
if(ans1>0)
{
System.out.println(ans1);
}
else
{
System.out.println("No Course found.");
}
Course[] ans2= sortCourseByHandsOn(courses,input2);
if(ans2==null)
{
System.out.println("No Course found with mentioned attribute.");
}
else
{
for (int i = 0; i <ans2.length ; i++) {
System.out.println(ans2[i].courseName);
}
}
}
public static int aab(Course[] courses,String input1)
{
int sum=0;
int count=0;
for (int i = 0; i <courses.length ; i++) {
if(courses[i].courseAdmin.equalsIgnoreCase(input1))
{
sum=sum+courses[i].quiz;
count=count+1;
}
}
if(sum>0)
{
return sum/count;
}
return 0;
}
public static Course[] sortCourseByHandsOn(Course[] courses,int input2)
{
Course[] help=new Course[0];
for (int i = 0; i <courses.length ; i++) {
if(courses[i].handsOn<input2)
{
help= Arrays.copyOf(help,help.length+1);
help[help.length-1]=courses[i];
}
}
//bubble sort
for (int i = 0; i <help.length-1 ; i++) {
for (int j = 0; j <help.length-i-1 ; j++) {
if(help[j].handsOn>help[j+1].handsOn)
{
Course temp=help[j];
help[j]=help[j+1];
help[j+1]=temp;
}
}
}
if(help.length>0)
{
return help;
}
return null;
}
}
class Course
{
int courseId;
String courseName;
String courseAdmin;
int quiz;
int handsOn;
//parametrized constructor
public Course(int courseId, String courseName, String courseAdmin, int quiz, int handsOn) {
this.courseId = courseId;
this.courseName = courseName;
this.courseAdmin = courseAdmin;
this.quiz = quiz;
this.handsOn = handsOn;
}
}