-
Notifications
You must be signed in to change notification settings - Fork 9
final-code #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
final-code #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
|
|
@@ -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; | ||
|
|
@@ -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(); | ||
| } | ||
| System.out.println("for student 2"); | ||
| for(int i=0;i<8;i++){ | ||
| eeeStudent2.marks[i]=inputobj.nextInt(); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
| } | ||
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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