Guest User

Untitled

a guest
Feb 12th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. //Produced by Jonathan Slotter
  2. // Assignment 6 is made to get book(s) from a user and catalog them based on some different information the user inputs.
  3.  
  4. import java.io.*;
  5. import java.util.Scanner;
  6. public class AssignmentSix1
  7. {
  8. public static void main(String [] args) throws IOException
  9. {
  10. Scanner input = new Scanner(System.in);
  11. Scanner keyboard = new Scanner (System.in);
  12.  
  13. final int NUMBERS = 20; // Maximum number of books the user can enter
  14. String [] ISBNList = new String[NUMBERS]; //Array for ISBN
  15. String [] firstNameList = new String[NUMBERS];
  16. String [] lastNameList = new String[NUMBERS];
  17. String [] titleList = new String[NUMBERS];
  18. String [] publisherList = new String[NUMBERS];
  19. double [] priceList = new double[NUMBERS];
  20. int [] quantityList = new int[NUMBERS];
  21. int index = 0;
  22.  
  23.  
  24.  
  25.  
  26. String isbn = "";
  27. String firstName;
  28. String lastName;
  29. String title;
  30. String publisher;
  31. double price;
  32. int quantity;
  33. String ascendingISBN = "";
  34. String ascendingAuthor = "";
  35.  
  36. System.out.println("Enter the information needed to complete the list for the books. Enter quit into the ISBN number when finished.");
  37.  
  38. System.out.print("Enter the name of the file you would like for ascending ISBN number: ");
  39. ascendingISBN = keyboard.nextLine();
  40.  
  41. File fileISBN = new File(ascendingISBN);
  42. File fileAuthor = new File(ascendingAuthor);
  43.  
  44. if (fileISBN.exists())
  45. {
  46. System.out.println("This file already exists, please choose another");
  47. System.out.print("Enter the name of the file you would like for ascending ISBN number: ");
  48. ascendingISBN = keyboard.nextLine();
  49. fileISBN = new File(ascendingISBN);
  50. }
  51.  
  52.  
  53. System.out.print("Enter the name of the file you would like for ascending author names: ");
  54. ascendingAuthor = keyboard.nextLine();
  55. fileAuthor = new File(ascendingAuthor);
  56.  
  57. if (fileAuthor.exists())
  58. {
  59. System.out.println("This file already exists, please choose another");
  60. System.out.print("Enter the name of the file you would like for ascending author names ");
  61. ascendingAuthor = keyboard.nextLine();
  62. fileAuthor = new File(ascendingAuthor);
  63. }
  64.  
  65.  
  66. while (isbn != "quit")
  67. {
  68. System.out.print("What is the ISBN number for the book? ");
  69. isbn = keyboard.next();
  70. ISBNList[index]=isbn;
  71.  
  72. if(isbn.equals("quit"))
  73. {
  74. break;
  75. }
  76.  
  77. System.out.print("What is the authors first name? ");
  78. firstName = keyboard.next();
  79. firstNameList[index] = firstName;
  80. if (firstName.length() < 1)
  81. {
  82. System.out.print("You did not enter a valid input, please try again: ");
  83. firstName = keyboard.next();
  84. firstNameList[index] = firstName;
  85. }
  86.  
  87. System.out.print("What is the authors last name? ");
  88. lastName = keyboard.next();
  89. lastNameList[index] = lastName;
  90. if (lastName.length() < 1)
  91. {
  92. System.out.print("You did not enter a valid input, please try again: ");
  93. lastName = keyboard.next();
  94. lastNameList[index] = lastName;
  95. }
  96.  
  97. System.out.print("What is the title for the book? ");
  98. title = keyboard.next();
  99. titleList[index] = title;
  100.  
  101. System.out.print("Who is the publisher for the book? ");
  102. publisher = keyboard.next();
  103. publisherList[index] = publisher;
  104. if (publisher.length() < 2)
  105. {
  106. System.out.print("You did not enter a valid input, please try again: ");
  107. publisher = keyboard.next();
  108. publisherList[index] = publisher;
  109. }
  110.  
  111. System.out.print("What is the price of the book? ");
  112. price = keyboard.nextDouble();
  113. priceList[index] = price;
  114.  
  115. System.out.print("How many books do you have? ");
  116. quantity = keyboard.nextInt();
  117. quantityList[index] = quantity;
  118.  
  119. index = (index + 1);
  120. }
  121.  
  122.  
  123. PrintWriter outputFileISBN = new PrintWriter(ascendingISBN);
  124.  
  125. for (int i = 0; i < index; i++)
  126. {
  127. outputFileISBN.println(ISBNList[i] + "\r\n" + lastNameList[i] + ", " + firstNameList[i] + "\r\n" + titleList[i] + "\r\n" + publisherList[i] +"\r\n" + priceList[i] + "\r\n" + quantityList[i] + "\r\n");
  128. }
  129.  
  130.  
  131. outputFileISBN.close();
  132.  
  133. PrintWriter outputFileAuthor = new PrintWriter(ascendingAuthor);
  134.  
  135. for (int i = 0; i < index; i++)
  136. {
  137. outputFileAuthor.println(lastNameList[i] + "," + firstNameList[i] + "\r\n" + title[i] + "\r\n " + ISBNList[i] + "\r\n" + priceList[i] + "\r\n" + publisherList[i] +"\r\n" + priceList[i] + "\r\n" + quantityList[i] + "\r\n");
  138. }
  139.  
  140. outputFileAuthor.close();
  141.  
  142. System.exit(0);
  143. }
  144.  
  145.  
  146.  
  147. public static int[] sortArrayISBN(String[] ISBNList, int index)
  148. {
  149. int startScan, count, minIndex;
  150. String minValue;
  151. int [] ISBNSort = new int[index];
  152.  
  153. for (int i = 0; 0 < count; i++)
  154. {
  155. ISBNSort[i] = i;
  156. }
  157.  
  158. for(startScan = 0; startScan < (ISBNList.length - 1); startScan++)
  159. {
  160. minIndex = startScan;
  161. minValue = ISBNList[startScan];
  162. for(count = startScan + 1; count < ISBNList.length; count++)
  163. {
  164. if (ISBNList[count].compareTo(minValue) < 0)
  165. {
  166. minValue = ISBNList[count];
  167. minIndex = count;
  168. }
  169. }
  170. ISBNList[minIndex] = ISBNList[startScan];
  171. ISBNList[startScan] = minValue;
  172. }
  173. return ISBNSort;
  174. }
  175.  
  176. }
Advertisement
Add Comment
Please, Sign In to add comment