Q: Book class in Java with Enum and a HashSet Need to create a book class with some features:name,author,price.The type of the book must be an enum and also i need to add some books using hashset.
public class Book {

    enum Type {
        Classic_Literature, THRILLER, Psychology, MANUAL, Self_Improvement;
    }
        String name;
        String author;
        double price;


    public Book(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;

      }

    public String get.name() {
   return name;

    }
}

public class Books extends Book {


    public Books(String name, String author, double price) {
        super(name, author, price);
    }

    public static void main(String[] args) {
        HashSet<String> books = new HashSet<>();
        carti.add("Baltagul");                //classical literature
        carti.add("Morometii");               //classical literature
        carti.add("Dezvoltarea personalitatii");
        carti.add("Criminalul ABC");
        carti.add("In mintea ta");
        carti.add("Abecedar");
        carti.add("Assassin's Creed Revelations");
        carti.add("In mintea lui");
        carti.add("Culegere Mate");
        carti.add("Public Speaking");
    }
}

The books are in Romanian so don't mind them.
My problem is:
-How can I make a link so that I can print out all books from "Literatura clasica"(Classical Literature)?
I don't exactly know how to implement such a method.

A: Some ideas to start improving your code.....
public class Book {

    enum Type {
        Classic_Literature, THRILLER, Psychology, MANUAL, Self_Improvement;
    }

    String name;
    String author;
    double price;
    Type type;

    public Book(String name) {
        this.name = name;
    }

    public Book(String name, Type type) {
        this.name = name;
        this.type = type;
    }

    public String getName() {
        return name;
    }
}   

    public static void main(String[] args) {
        HashSet<Book> books = new HashSet<>();
        books.add(new Book("Baltagul", Book.Type.Classic_Literature));                //classical literature
        books.add(new Book("Morometii", Book.Type.Classic_Literature));               //classical literature
        books.add(new Book("Dezvoltarea personalitatii"));
        books.add(new Book("Criminalul ABC"));
        books.add(new Book("In mintea ta"));

        //here you retrieve the classical literature books

        Set<Book> classicBooks = books.stream()
                .filter(b -> b.type == Book.Type.Classic_Literature)
                .collect(Collectors.toSet());
    }


A: There are some misconceptions on the code.

1. Have the item as book and not use it within main. 
So why was defined ?
Maybe this is required:
//colection of books
HashSet<Book> books = new HashSet<>();
2. Why Books should extends Book ?
No need here. Books is just a regular class where you do aggregation via HashSet
3.Basic Book instantiation.
Maybe it's needed: 
 books.put(new Book("Poezii", "Eminescu", 123))
.4.Where is the classification of book linked ?
Maybe altering the constructor:
public Book(String name, String author, double price, BookType bookType) and after do a proper instantiation
.5. Display the books within a classification. Just use a regular loop within collection and validate only for a certain BookType (eg: Classic_Literature)
... 
