Java personal Library


#1

Please help,

I don’t have a great grasp of HashMaps, but I am attempting. I appreciate your perusal. Thank you.


import java.util.HashMap;

class Library{
  



public Library() {
  
  
	




public void getFinishedBooks(HashMap<String, Boolean> Library);
 
  if (Library.size < 1){
    System.out.println("Error! There is missing information. No data found.");
  }
  
  
  else {
    
    for (book : Library){
      
      if (Boolean book == true){
        System.out.println(book);
      }
      
    }
  
    
    
    
      
      public static void main (String[] args){
        
        
        HashMap<String, Boolean> myBooks = new HashMap<String, Boolean>();
        
        myBooks.put(Road Down The Funnel, true);
        myBooks.put(Rat: A Biology. false);
        myBooks.put(TimeIn, true);
        myBooks.put(3D Food Printing, false);
        
        myLibrary.getFinishedBooks(myBooks);
        
        
      }
      
      
      
    }
  
}

here are my error codes:

Library.java:16: error: illegal start of expression
public void getFinishedBooks(HashMap<String, Boolean> Library);
^
Library.java:16: error: illegal start of expression
public void getFinishedBooks(HashMap<String, Boolean> Library);
       ^
Library.java:16: error: ';' expected
public void getFinishedBooks(HashMap<String, Boolean> Library);
                            ^
Library.java:16: error: ';' expected
public void getFinishedBooks(HashMap<String, Boolean> Library);
                                                             ^
Library.java:25: error: bad initializer for for-loop
    for (book : Library){
         ^
Library.java:27: error: ')' expected
      if (Boolean book == true){
                 ^
Library.java:27: error: not a statement
      if (Boolean book == true){
                       ^
Library.java:27: error: ';' expected
      if (Boolean book == true){
                              ^
Library.java:37: error: illegal start of expression
      public static void main (String[] args){
      ^
Library.java:37: error: illegal start of expression
      public static void main (String[] args){
             ^
Library.java:37: error: ';' expected
      public static void main (String[] args){
                   ^
Library.java:37: error: '.class' expected
      public static void main (String[] args){
                                        ^
Library.java:37: error: ';' expected
      public static void main (String[] args){
                                            ^
Library.java:42: error: ')' expected
        myBooks.put(Road Down The Funnel, true);
                        ^
Library.java:42: error: <identifier> expected
        myBooks.put(Road Down The Funnel, true);
                                         ^
Library.java:42: error: illegal start of expression
        myBooks.put(Road Down The Funnel, true);
                                              ^
Library.java:43: error: ')' expected
        myBooks.put(Rat: A Biology. false);
                       ^
Library.java:43: error: ';' expected
        myBooks.put(Rat: A Biology. false);
                                  ^
Library.java:45: error: ')' expected
        myBooks.put(3D Food Printing, false);
                      ^
Library.java:45: error: not a statement
        myBooks.put(3D Food Printing, false);
                            ^
Library.java:45: error: ';' expected
        myBooks.put(3D Food Printing, false);
                                    ^
21 errors

#2

You have defined your methods inside of the class constructor. Move them outside of it into the class itself.