Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*; //scanner and ArrayList
- public class ALBook {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- //variables declared at the top
- Book book=null;
- Book bk = null;
- int isbn=0;
- String title="";
- String yn= "";
- ArrayList al = new ArrayList( );
- System.out.println("The size of the array list is "+ al.size( ));
- do{
- try{
- System.out.print("Enter the ISBN: ");
- isbn = sc.nextInt( );
- sc = new Scanner(System.in);
- System.out.print("Enter the Title: ");
- title = sc.nextLine( );
- book = new Book (isbn, title);
- al.add(book);
- sc = new Scanner(System.in);
- System.out.println("another? y/n");
- yn = sc.nextLine( );
- }//closes try
- catch(InputMismatchException ime){
- System.out.println("You did not enter a number");
- System.out.println("This program will end now");
- }
- catch(BookException be){
- System.out.println(be.getMessage( ));
- }
- }while((yn.equalsIgnoreCase("Y")));
- System.out.println("- - -Printing all books - - -");
- for (int i=0; i<al.size(); i++){
- bk = (Book) al.get(i);
- System.out.println(bk.toString( ));
- System.out.println(al.get(i));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement