Untitled

 avatar
unknown
java
2 years ago
4.5 kB
2
Indexable
package my.example;

//В классе WebResource создай:
// метод удаления аккаунта по заданным фамилии и имени.
// метод поиска и вывода всех аккаунтов с заданной фамилией.

import java.util.ArrayList;
import java.util.Iterator;
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 static 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);
		sc.close();
	}
	
	// вывод всех аккаунтов
	void PrintAll() {
		int num = 1;
		for( Account elem : lst) {
			System.out.println(num++ + ")" + elem);
		}
	}


	
	public static void Delete(String firstName,String lastName) {
		Iterator<Account> itr = lst.iterator();
		while (itr.hasNext()) {
			Scanner sc = new Scanner(System.in);
			System.out.println("Введите фамилию для удалиния: ");
			String last = (String) sc.next();
			System.out.println("Введите имя для удалиния: ");
			String first = (String) sc.next();	  
            if (last == lastName && first == firstName)
            sc.close();
            {
            	itr.remove();
            	}
           	}
	}
	public static void Search(String lastName) {
		Iterator<Account> itr = lst.iterator();
		while (itr.hasNext()) {
			Scanner sc = new Scanner(System.in);
			System.out.println("Введите фамилию для удалиния: ");
			String last = (String) sc.next();
			System.out.println("Введите имя для удалиния: ");	  
            if (last == lastName)
            sc.close();
            {
            	System.out.println(itr);;
            	}
           	}
	}
// 

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();
		 
		 res.Delete();
		 res.Search();
		 }
	}
	
}