Я пытаюсь выучить объект массива в Java, но не понимаю. Я понял, как хранить ввод в объект массива, но не понимаю, как сравнить каждые элементы внутри массива, чтобы сделать #7 и #8. Я попытался искать в Интернете, но застрял оттуда. < /P>
Создать ученика класса с следующими атрибутами: имя, возраст, адрес, адрес электронной почты < /p>
< /li>
Создание пустого конструктора, который инициализирует пустые значения для всех атрибутов. Конструктор, который принимает все параметры, и инициализирует все атрибуты вместе с ним. Чтобы ввести подробную информацию о любых 5 студентах и хранить их в массиве.import java.util.*;
public class Student{
private String name;
private int age;
private String address;
private String email;
public Student(){}
public Student(String name, int age, String address, String email){
this.name = name;
this.age = age;
this.address = address;
this.email = email;
}
public void setName(String newName){
name = newName;
}
public void setAge(int newAge){
age = newAge;
}
public void setAddress(String newAddress){
address = newAddress;
}
public void setEmail(String newEmail){
email = newEmail;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getAddress(){
return address;
}
public String getEmail(){
return email;
}
public String toString() {
return "Name: " + name + ", Age: " + age + ", Address: " + address + ", Email: " + email;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Student[] s= new Student[];5
for(int i = 0; i < 5; i++){
System.out.print("Name: ");
String name = sc.nextLine();
System.out.print("Age: ");
int age = sc.nextInt();
System.out.print("Address: ");
sc.nextLine();
String address = sc.nextLine();
System.out.print("Email: ");
String email = sc.nextLine();
s = new Student(name,age,address,email);
}
for(int i = 0; i < s.size(); i++){
if(s)
}
System.out.println(Arrays.toString(s));
}
}
Подробнее здесь: https://stackoverflow.com/questions/706 ... attributes