-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathUniversity.java
More file actions
58 lines (54 loc) · 1.62 KB
/
University.java
File metadata and controls
58 lines (54 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
import java.util.TreeSet;
class Student implements Comparable<Student> {
private String name;
private int id;
private double moadel;
public Student(String name , int id , double moadel){
this.name=name;
this.id=id;
this.moadel=moadel;
}
public String getName(){
return name;
}
public int getId(){
return id;
}
public double getMoadel(){
return moadel;
}
public int compareTo(Student other) {
return Integer.compare(this.id, other.id);
}
public String toString() {
return "Name: " + name + ", id: " + id + ", Moadel: " + moadel;
}
}
public class University{
public static void main(String args[]){
Scanner input=new Scanner(System.in);
TreeSet<Student> studentSet=new TreeSet<>();
int numberOfStudent = input.nextInt();
for (int i=0 ; i<numberOfStudent ; i++){
String name=input.next();
int id=input.nextInt();
double moadel=input.nextDouble();
Student student=new Student(name, id , moadel);
studentSet.add(student);
}
//سرچ از روی id
int searchId=input.nextInt();
boolean found=false;
for(Student i: studentSet){
if(searchId==i.getId()){
System.out.println("Student Found");
System.out.println("name :" + i.getName()+ "\nId : "+ i.getId()+"\nmoadel :" + i.getMoadel());
found=true;
}
}
if(found==false){
System.out.println("Student not Found");
}
}
}