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
84 changes: 68 additions & 16 deletions assignemntOne.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@


import java.util.Scanner;

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 Student(int usn, char sem) {
this.sem=sem;
this.usn=usn;
}

public Student() {

}



// <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);
Expand All @@ -19,7 +29,11 @@ public void setUsn(int usn) {

}

<TO DO : ADD METHOD TO SET MARKS>
//<TO DO : ADD METHOD TO SET MARKS>
public void setMarks(int []marks){
this.marks=marks;
}


public int[] getMarks() {
return marks;
Expand All @@ -32,25 +46,63 @@ public char getSem() {
public int getUsn() {
return usn;
}
<TO DO: Add a method to find maximum marks>
// <TO DO: Add a method to find maximum marks>
public int maxMarks( int []marks){
int i;


int max = marks[0];


for (i = 1; i < marks.length; i++)
if (marks[i] > max)
max = marks[i];

return max;

}

}


public class assignemntOne {
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>
Student eeeStudent1 = new Student();
int usn = 20;
char sem='v';
Student eeeStudent2 = new Student(usn,sem);
// <TO DO: Assign marks to students>
Scanner inputobj=new Scanner(System.in);
for(int i=0;i<8;i++){
eeeStudent1.marks[i]=inputobj.nextInt();

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.

Use the set marks method instead of direct assignment

}
System.out.println("for student 2");
for(int i=0;i<8;i++){
eeeStudent2.marks[i]=inputobj.nextInt();

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.

use set marks method

}
eeeStudent1.setMarks(eeeStudent1.marks);
eeeStudent2.setMarks(eeeStudent2.marks);

int max1= eeeStudent1.maxMarks(eeeStudent1.marks);

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.

There should not be any need to pass a parameter for this method


int max2= eeeStudent2.maxMarks(eeeStudent2.marks);

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.

Same as above, no need for parameter.

// <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>
System.out.println("index subject");
int sub;
sub= inputobj.nextInt();


if(eeeStudent1.marks[sub]>eeeStudent2.marks[sub]) {
System.out.println("student 1 has more marks in that subject");
}
else
System.out.println("student 2 has more marks in that subject");

<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>
}


}
}