Im currently working on a simple Library program in Java I w

I\'m currently working on a simple Library program in Java. I want a method that reads in from an external file 10 book names. Enter those names into an array or list. Each of the books have 2 copies. The user will enter the book they want and the method compares the name and the array, if they match, decrease the copy to 1. How would that be coded?

Solution

import java.util.ArrayList;
public static void removeDuplicate(String name) throws IOException {
   FileInputStream fis = new FileInputStream(new File(\"abc.txt\"));

   BufferedReader br = new BufferedReader(new InputStreamReader(fis));
ArrayList<String> al=new ArrayList<String>();
   String line = null;
   while ((line = br.readLine()) != null) {
       al.add(line);
   }
for(int i=0;i<al.size();i++){
   if(al.get(i).trim().equalsIgnoreCase(name))
       al.remove(i);
}
   br.close();
}

I\'m currently working on a simple Library program in Java. I want a method that reads in from an external file 10 book names. Enter those names into an array o

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site