0% found this document useful (0 votes)
182 views2 pages

SBQ Solution

The document defines a Student class with fields for id, name, marks, and age. It also contains a main method that reads in student data, searches for a student by marks and finds the oldest student, printing out their details. It defines methods to search for a student by marks and find the student with the maximum age.

Uploaded by

rahul singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
182 views2 pages

SBQ Solution

The document defines a Student class with fields for id, name, marks, and age. It also contains a main method that reads in student data, searches for a student by marks and finds the oldest student, printing out their details. It defines methods to search for a student by marks and find the student with the maximum age.

Uploaded by

rahul singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {


public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Student[] s = new Student[n];
for(int i = 0; i < n; i++) {
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
double marks = sc.nextDouble();
int age = sc.nextInt();
s[i] = new Student(id, name, marks, age);
}
double m = sc.nextDouble();
Student s1 = searchStudentByMarks(s, m);
if(s1 == null) {
System.out.println("No Student found with mentioned marks.");
} else {
System.out.println("id-"+s1.getId());
System.out.println("name-"+s1.getName());
System.out.println("marks-"+s1.getMarks());
System.out.println("age-"+s1.getAge());
}
Student s2 = findStudentWithMaximumAge(s);
if(s2 == null) {
System.out.println("No Student found with mentioned marks.");
} else {
System.out.println("id-"+s2.getId());
System.out.println("name-"+s2.getName());
System.out.println("marks-"+s2.getMarks());
System.out.println("age-"+s2.getAge());
}

public static Student searchStudentByMarks(Student[] s,double marks){


int l = s.length;
for(int i = 0; i < l; i++) {
if(marks == s[i].getMarks()) return s[i];
}
return null;
}

public static Student findStudentWithMaximumAge(Student[] s){


int max = 0;
Student s1 = null;
for(int i = 0; i < s.length; i++) {
if(s[i].getAge() >= max) {
max = s[i].getAge();
s1 = s[i];
}
}
return s1;
}

}
class Student {
int id;
String name;
double marks;
int age;
Student(int id, String name, double marks, int age) {
this.id = id;
this.name = name;
this.marks = marks;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String Name) {
this.name = name;
}
public double getMarks() {
return marks;
}
public void setMarks(double marks) {
this.marks = marks;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy