Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 69 additions & 33 deletions assignemntOne.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,92 @@


import java.util.Scanner;

class Student{
class Student {

int usn;
char sem;
int marks[] = new int[8];
<TO DO:Add Constructor to initialize sem and usn>
<TO DO : Add constructor with no intializations>
public void setSem() {
Scanner sc = new Scanner(System.in);
this.sem=sc.next().charAt(0);
}
public void setUsn(int usn) {
Scanner sc = new Scanner(System.in);
this.usn=sc.nextInt();

//Constructor to initialize sem and usn
Student(int USN, char SEM) {
this.usn = USN;
this.sem = SEM;
}

<TO DO : ADD METHOD TO SET MARKS>
// constructor with no intialization
Student() {
}

public int[] getMarks() {
return marks;
public void setUsn() {
Scanner inobj = new Scanner(System.in);
int usn = inobj.nextInt();
this.usn=usn;
}

public char getSem() {
return sem;
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;
}
<TO DO: Add a method to find maximum marks>

}

public char getSem() {
return sem;
}

public class assignemntOne {
public int[] getMarks() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in a different class ?

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 = new Student();
int usn;
int sem;
Student eeeStudent2 = new Student(usn,sem);
<TO DO: Assign marks to students>

<TO DO: Print the max marks of both students>

<TO DO: Take input of a subject index from user and print
which student has more marks in that subject>

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());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get max marks in inside a class in student1, will this call work ?

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]);

}
}