-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathassignemntOne.java
More file actions
92 lines (81 loc) · 2.55 KB
/
Copy pathassignemntOne.java
File metadata and controls
92 lines (81 loc) · 2.55 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
import java.util.Scanner;
class Student {
int usn;
char sem;
int marks[] = new int[8];
//Constructor to initialize sem and usn
Student(int USN, char SEM) {
this.usn = USN;
this.sem = SEM;
}
// constructor with no intialization
Student() {
}
public void setUsn() {
Scanner inobj = new Scanner(System.in);
int usn = inobj.nextInt();
this.usn=usn;
}
public void setSem() {
Scanner inobj = new Scanner(System.in);
char sem = inobj.next().charAt(0);
this.sem=sem;
}
// ADD METHOD TO SET MARKS
public void setMarks() {
Scanner inobj = new Scanner(System.in);
for (int i = 0; i < this.marks.length; i++) {
this.marks[i] = inobj.nextInt();
}
}
public int getUsn() {
return usn;
}
public char getSem() {
return sem;
}
public int[] getMarks() {
return marks;
}
//to find maximum marks
public int getMaxMark() {
int m = 0;
for (int i = 0; i < marks.length; i++) {
if (marks[i] > m) {
m = marks[i];
}
}
return m;
}
}
public class todo{
public static void main(String[] args) {
Student eeestudent1;
eeestudent1=new Student();
System.out.println("assign usn and semester to student 1");
eeestudent1.setUsn();
eeestudent1.setSem();
Student eeestudent2 = new Student(123,'v');
//Assign marks to students
System.out.println("assign marks to student 1");
eeestudent1.setMarks();
System.out.println("assign marks to student 2");
eeestudent2.setMarks();
//Print the max marks of both students
System.out.println("student 1 maximum marks"+eeestudent1.getMaxMark());
System.out.println("student 2 maximum marks"+eeestudent2.getMaxMark());
//Take input of a subject index from user
Scanner inobj=new Scanner(System.in);
System.out.println("Input subject index");
int index = inobj.nextInt();
//print which student has more marks in that subject
if(eeestudent1.marks[index]>eeestudent2.marks[index])
{
System.out.println("Student 1 scored more ="+eeestudent1.marks[index]);
} else if (eeestudent1.marks[index]<eeestudent2.marks[index]) {
System.out.println("Student 2 scored more ="+eeestudent2.marks[index]);
}
else
System.out.println("both scored equal ="+eeestudent1.marks[index]);
}
}