Új hozzászólás Aktív témák

  • Ablakos

    őstag

    Egy kis szakértést szeretnék kérni, mert nem tudom megfejteni miért nem akar a contains metodus nekem működni. :( (book class a simple pojo)
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    ArrayList<Book> books = new ArrayList<>();

    while (true) {
    System.out.println("Name (empty will stop):");
    String name = scanner.nextLine();
    if (name.isEmpty()) {
    break;
    }

    System.out.println("Publication year:");
    int publicationYear = Integer.valueOf(scanner.nextLine());
    Book book = new Book(name, publicationYear);
    if (books.contains(book)) {
    System.out.println("The book is already on the list. Let's not add the same book again. \n Name (empty will stop):");
    } else {
    books.add(book);
    }

    System.out.println("Thank you! Books added: " + books.size());
    }
    for(Book b:books) {System.out.println(b.getName() + " " + b.getPublicationYear());}
    }

Új hozzászólás Aktív témák