BookShop.java - import import import import import import import import import import java.io.BufferedReader java.io.BufferedWriter java.io.File

BookShop.java - import import import import import import...

This preview shows page 1 - 2 out of 3 pages.

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.Scanner; class Book { private String title; private String author; Book(String title, String author){ this.title = title; this.author = author; } public void setTitle(String title){ this.title = title; } public void setAuthor(String author){ this.author = author; } public String getTitle(){ return title; } public String getAuthor(){ return author; } public String toString(){ return String.format("%s %s", title,author); } } //////////////////////////////////////////// public class BookShop { public static void main(String[] args) { ArrayList<Book> list = new ArrayList<Book>(); File file = new File("book.dat"); list=readFromFile(file); int option=0; try{ while(true){ menu(); option = new Scanner(System.in).nextInt(); switch(option){ case 1: addNewBook(list); break; case 2: for(Book t: list) System.out.println(t); break; case 3: int i=search(list,"DLD"); if(i>=0) System.out.println("Found at index " +i);
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 3 pages?

  • Fall '19
  • Return statement, Void type, public void setTitle

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture