-
Notifications
You must be signed in to change notification settings - Fork 9
todo assignment #5
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
Open
vyomsaxena
wants to merge
1
commit into
satishba:master
Choose a base branch
from
vyomsaxena:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() { | ||
| 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()); | ||
|
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. 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]); | ||
|
|
||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this in a different class ?