Answer to Question #299977 in Java | JSP | JSF for Kamalesh

Question #299977

Write a program in Java, define a STUDENT class with Roll No, Name and Marks of 3 subjects. Define one function to find the best two subject marks for student.


Hint:-

-get user input from user of student name, roll no and mark of 3 subjects

-give best two subject mark along with student information


1
Expert's answer
2022-02-19T16:56:16-0500


import java.util.*;


class STUDENT {
	public String RollNo;
	private String Name;
	private int Marks[];
	private int counter;


	public STUDENT(String RollNo, String Name) {
		this.RollNo = RollNo;
		this.Name = Name;
		this.Marks = new int[3];
		this.counter = 0;
	}


	public void addMark(int mark) {
		Marks[counter] = mark;
		counter++;
	}


	public void display() {
		Arrays.sort(Marks);
		System.out.println("RollNo: " + RollNo);
		System.out.println("Name: " + Name);
		System.out.println("The best two subject marks for student: " + Marks[1] + " " + Marks[2]);
	}
}


class App {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);


		System.out.print("Enter a RollNo: ");
		String RollNo = in.nextLine();
		System.out.print("Enter a Name: ");
		String Name = in.nextLine();
		STUDENT s = new STUDENT(RollNo, Name);
		for (int i = 0; i < 3; i++) {
			System.out.print("Enter a mark: ");
			int mark = in.nextInt();
			s.addMark(mark);
		}
		s.display();
		in.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS