Untitled
unknown
plain_text
2 years ago
3.1 kB
0
Indexable
Never
package my.example; import java.util.ArrayList; import java.util.List; import java.util.Scanner; class Person { private String firstName; private String lastName; private int year; public Person(String firstName, String lastName, int year) { super(); this.firstName = firstName; this.lastName = lastName; this.year = year; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } @Override public String toString() { return "firstName=" + firstName + ", lastName=" + lastName + ", year=" + year; } } class Account { String email; String status; Person person; @Override public String toString() { return "email=" + email + ", status=" + status + ", firstName=" + person.getFirstName() + ", lastName=" + person.getLastName() + ", year=" + person.getYear(); } public Account(String email, String status, Person person) { super(); this.email = email; this.status = status; this.person = person; } public Account(String email, String status, String firstName, String lastName, int year) { super(); this.email = email; this.status = status; this.person = new Person( firstName, lastName, year); } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public Person getPerson() { return person; } public void setPerson(Person person) { this.person = person; } } class WebResource { private List<Account> lst; public WebResource() { lst = new ArrayList<Account>(); } public List<Account> getLst() { return lst; } void AppendAccount() { Scanner sc = new Scanner(System.in); System.out.print("Email: "); String email = sc.nextLine(); System.out.print("Роль: "); String status = sc.nextLine(); System.out.print("Имя: "); String firstname = sc.nextLine(); System.out.print("Фамилия: "); String lastname = sc.nextLine(); System.out.print("Год рождения: "); int year = sc.nextInt(); Account acc = new Account(email, status, firstname, lastname, year); lst.add(acc); } // вывод всех аккаунтов void PrintAll() { int num = 1; for( Account elem : lst) { System.out.println(num++ + ")" + elem); } } } // public class Main { public static void main(String[] args) { //Account acc = new Account("rtyu@gmail.com", "ADMIN", "Slavik", "Petrov", 2000); //System.out.println(acc); WebResource res = new WebResource(); res.AppendAccount(); res.AppendAccount(); res.PrintAll(); } }