-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student
82 lines (68 loc) · 2.47 KB
/
Student
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private String name;
private int age;
private double gpa;
public Student(String name, int age, double gpa) {
this.name = name;
this.age = age;
this.gpa = gpa;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public double getGpa() {
return gpa;
}
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
", gpa=" + gpa +
'}';
}
}
public class UniversityProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();
while (true) {
System.out.println("Выберите действие:");
System.out.println("1. Добавить студента");
System.out.println("2. Вывести информацию о студентах");
System.out.println("3. Выход");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("Введите имя студента:");
String name = scanner.next();
System.out.println("Введите возраст студента:");
int age = scanner.nextInt();
System.out.println("Введите средний балл студента:");
double gpa = scanner.nextDouble();
Student newStudent = new Student(name, age, gpa);
students.add(newStudent);
System.out.println("Студент добавлен.");
break;
case 2:
System.out.println("Информация о студентах:");
for (Student student : students) {
System.out.println(student);
}
break;
case 3:
System.out.println("Программа завершена.");
System.exit(0);
break;
default:
System.out.println("Неверный выбор. Попробуйте еще раз.");
break;
}
}
}
}