Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Produced by Jonathan Slotter
- // Assignment 6 is made to get book(s) from a user and catalog them based on some different information the user inputs.
- import java.io.*;
- import java.util.Scanner;
- public class AssignmentSix1
- {
- public static void main(String [] args) throws IOException
- {
- Scanner input = new Scanner(System.in);
- Scanner keyboard = new Scanner (System.in);
- final int NUMBERS = 20; // Maximum number of books the user can enter
- String [] ISBNList = new String[NUMBERS]; //Array for ISBN
- String [] firstNameList = new String[NUMBERS];
- String [] lastNameList = new String[NUMBERS];
- String [] titleList = new String[NUMBERS];
- String [] publisherList = new String[NUMBERS];
- double [] priceList = new double[NUMBERS];
- int [] quantityList = new int[NUMBERS];
- int index = 0;
- String isbn = "";
- String firstName;
- String lastName;
- String title;
- String publisher;
- double price;
- int quantity;
- String ascendingISBN = "";
- String ascendingAuthor = "";
- System.out.println("Enter the information needed to complete the list for the books. Enter quit into the ISBN number when finished.");
- System.out.print("Enter the name of the file you would like for ascending ISBN number: ");
- ascendingISBN = keyboard.nextLine();
- File fileISBN = new File(ascendingISBN);
- File fileAuthor = new File(ascendingAuthor);
- if (fileISBN.exists())
- {
- System.out.println("This file already exists, please choose another");
- System.out.print("Enter the name of the file you would like for ascending ISBN number: ");
- ascendingISBN = keyboard.nextLine();
- fileISBN = new File(ascendingISBN);
- }
- System.out.print("Enter the name of the file you would like for ascending author names: ");
- ascendingAuthor = keyboard.nextLine();
- fileAuthor = new File(ascendingAuthor);
- if (fileAuthor.exists())
- {
- System.out.println("This file already exists, please choose another");
- System.out.print("Enter the name of the file you would like for ascending author names ");
- ascendingAuthor = keyboard.nextLine();
- fileAuthor = new File(ascendingAuthor);
- }
- while (isbn != "quit")
- {
- System.out.print("What is the ISBN number for the book? ");
- isbn = keyboard.next();
- ISBNList[index]=isbn;
- if(isbn.equals("quit"))
- {
- break;
- }
- System.out.print("What is the authors first name? ");
- firstName = keyboard.next();
- firstNameList[index] = firstName;
- if (firstName.length() < 1)
- {
- System.out.print("You did not enter a valid input, please try again: ");
- firstName = keyboard.next();
- firstNameList[index] = firstName;
- }
- System.out.print("What is the authors last name? ");
- lastName = keyboard.next();
- lastNameList[index] = lastName;
- if (lastName.length() < 1)
- {
- System.out.print("You did not enter a valid input, please try again: ");
- lastName = keyboard.next();
- lastNameList[index] = lastName;
- }
- System.out.print("What is the title for the book? ");
- title = keyboard.next();
- titleList[index] = title;
- System.out.print("Who is the publisher for the book? ");
- publisher = keyboard.next();
- publisherList[index] = publisher;
- if (publisher.length() < 2)
- {
- System.out.print("You did not enter a valid input, please try again: ");
- publisher = keyboard.next();
- publisherList[index] = publisher;
- }
- System.out.print("What is the price of the book? ");
- price = keyboard.nextDouble();
- priceList[index] = price;
- System.out.print("How many books do you have? ");
- quantity = keyboard.nextInt();
- quantityList[index] = quantity;
- index = (index + 1);
- }
- PrintWriter outputFileISBN = new PrintWriter(ascendingISBN);
- for (int i = 0; i < index; i++)
- {
- 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");
- }
- outputFileISBN.close();
- PrintWriter outputFileAuthor = new PrintWriter(ascendingAuthor);
- for (int i = 0; i < index; i++)
- {
- 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");
- }
- outputFileAuthor.close();
- System.exit(0);
- }
- public static int[] sortArrayISBN(String[] ISBNList, int index)
- {
- int startScan, count, minIndex;
- String minValue;
- int [] ISBNSort = new int[index];
- for (int i = 0; 0 < count; i++)
- {
- ISBNSort[i] = i;
- }
- for(startScan = 0; startScan < (ISBNList.length - 1); startScan++)
- {
- minIndex = startScan;
- minValue = ISBNList[startScan];
- for(count = startScan + 1; count < ISBNList.length; count++)
- {
- if (ISBNList[count].compareTo(minValue) < 0)
- {
- minValue = ISBNList[count];
- minIndex = count;
- }
- }
- ISBNList[minIndex] = ISBNList[startScan];
- ISBNList[startScan] = minValue;
- }
- return ISBNSort;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment