0% found this document useful (0 votes)
10 views3 pages

Students BQ 7

The document contains a Java program that manages student information, allowing the user to input details for multiple students and retrieve information based on the maximum age or a specific student ID. It defines a 'Student' class with attributes such as id, name, marks, and age, and includes methods for finding the student with the maximum age and searching for a student by ID. The program utilizes standard input and output for interaction with the user.

Uploaded by

Siddharth Kumar
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)
10 views3 pages

Students BQ 7

The document contains a Java program that manages student information, allowing the user to input details for multiple students and retrieve information based on the maximum age or a specific student ID. It defines a 'Student' class with attributes such as id, name, marks, and age, and includes methods for finding the student with the maximum age and searching for a student by ID. The program utilizes standard input and output for interaction with the user.

Uploaded by

Siddharth Kumar
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/ 3

import java.io.

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

// import edu.stanford.nlp.util.logging.Style;

public class Solution {


public static void main(String args[]) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */

Scanner sc= new Scanner(System.in);

int n = sc.nextInt();

Student[] student = new Student[n];

for(int i=0;i<n;i++){
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
int marks = sc.nextInt();
sc.nextLine();
int age = sc.nextInt();
sc.nextLine();

student[i]= new Student(id, name, marks, age);


}

int input =sc.nextInt();

Student maxAge= findStudentWithMaximumAge(student);

if(maxAge!=null){
System.out.println("id-"+maxAge.getId());
System.out.println("name-"+maxAge.getName());
System.out.println("marks-"+maxAge.getMarks());
System.out.println("age-"+maxAge.getAge());
}

Student obj = searchStudentById(student,input);

if(obj!=null){

System.out.println("id-"+obj.getId());
System.out.println("name-"+obj.getName());
System.out.println("marks-"+obj.getMarks());
System.out.println("age-"+obj.getAge());
}
else{
System.out.println("No Student found with mentioned attribute.");
}

static Student findStudentWithMaximumAge(Student[] student){


int maxAge = student[0].getAge();
Student obj = null;
for(Student s: student){
if(s.getAge()>maxAge){
maxAge = s.getAge();
obj = s;
}
}

return obj;
}

static Student searchStudentById(Student[] student, int input){

Student obj = null;

for(Student s:student){
if(input==s.getId()){
obj = s;
}
}

return obj;
}
}

class Student{

int id;
String name;

int marks;

int age;

Student(int id,String name,int 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 int getMarks() {


return marks;
}
public void setMarks(int 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