Advertisement
Guest User

KREIDÅ

a guest
Nov 20th, 2014
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Krisu {
  5. public static void main (String []args) {
  6.  
  7. ArrayList<String> list = new ArrayList<String>();
  8. Scanner sc = new Scanner(System.in);
  9.  
  10. String author;
  11. String title;
  12. String publisher;
  13. String answer;
  14. int sum = 0;
  15.  
  16. System.out.println("Do you want to input a book? (y/n)");
  17. answer = sc.nextLine();
  18.  
  19. while (answer.equals("y")) { //Ywhile
  20.  
  21. System.out.println("Please write the author's name: ");
  22. author = sc.nextLine();
  23. list.add(author);
  24.  
  25. System.out.println("Please write the title: ");
  26. title = sc.nextLine();
  27. list.add(title);
  28.  
  29. System.out.println("Please write the publisher : ");
  30. publisher = sc.nextLine();
  31. list.add(publisher);
  32.  
  33. sum++;
  34. System.out.println("Do you want to enter another book? (y/n)");
  35. answer = sc.nextLine();
  36. }// Nwhile
  37.  
  38. if (!answer.equals("y")) { //Yif
  39. System.out.println("Case closed");
  40.  
  41. } //Nif
  42.  
  43. int size = list.size();
  44. System.out.println("The library contains: " + sum + " books");
  45. System.out.println("The arraylist contains the following elements: "+ list);
  46.  
  47.  
  48.  
  49.  
  50.  
  51. }//1
  52. }//2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement