Skip to content

Instantly share code, notes, and snippets.

@M0N57R0517Y
Created March 6, 2018 16:52
Show Gist options
  • Save M0N57R0517Y/5d077b8afcadfccbd1784d5ae10fa150 to your computer and use it in GitHub Desktop.
Save M0N57R0517Y/5d077b8afcadfccbd1784d5ae10fa150 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//Variables:
// [Shelf #, First Call No, Last Call No, First Call No Comp, Last Call No Comp.]
// Note: Shelf arrays[0] is a blank.
// Make sure that the first Shelf # is 1, not 0. Leave Shelf # = 0 blank.
//int[] ShelfNumber = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
double[] FirstCallNo = new double[] {10000, 10000, 10000, 700.000, 800.000, 900.000, 10000, 0.001, 300.000, 400.000, 500.000, 600.000, 10000, 10000};
double[] LastCallNo = new double[] {10000, 10000, 10000, 799.999, 899.999, 999.999, 10000, 299.999, 399.999, 499.999, 599.999, 699.999, 10000, 10000};
//ActiveShelf -- Used as a counter/progress monitor for keeping track of find
int ActiveShelf = 1;
//CorrectShelf -- Marks whether shelf has been found, then marks the Shelf # of the correct shelf when found.
int CorrectShelf = 0;
//InputCallNoComp -- User inputed Call NO translated to all digits as follows:
//Dewey 011.111 ABC --> 011.111.000102
double InputCallNoComp = 0;
//Alphabet -- Used to convert letters to numbers. Counts 01-26, not 00-25. TrueLetter -- Used to convert.
String[] Alphabet = new String[] {"A", "B", "C", "D", "E", "F", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A"};
System.out.println("TESTING Array Alphabet: " + Alphabet[0] + Alphabet[1] + Alphabet[2] + ". The array is " + "characters long.");
double TrueLetter = 0.0;
//Gets user input of call number
System.out.println("Please input the call number of your book in the format: 123.456 ABC, then press enter.");
Scanner scanner = new Scanner(System.in);
String InputCallNoText = scanner.nextLine();
System.out.println("You inputed: " + InputCallNoText);
System.out.println("Your input is " + InputCallNoText.length() + " characters long.");
////Converts InputCallNoText to InputCallNoComps
//InputNumbers == 123.000
String InputNumbers1 = InputCallNoText.substring(0, 3);
System.out.println("TESTING: The first phrase of your input is: " + InputNumbers1 + ".");
InputCallNoComp = Long.parseLong(InputNumbers1);
//InputNumbers2 == 000.456
String InputNumbers2 = InputCallNoText.substring(4, 7);
double InputCallNoComp2 = Long.parseLong(InputNumbers2);
System.out.println("TESTING: The second phrase of your input is: " + InputCallNoComp2 + ".");
InputCallNoComp2 = InputCallNoComp2/ (double) 1000;
System.out.println("TESTING: The second phrase of your input is now: " + InputCallNoComp2 + ".");
InputCallNoComp = InputCallNoComp + InputCallNoComp2;
System.out.println("TESTING: The full digits of the call number are: " + InputCallNoComp + ".");
//InputAuthName == ABC
String InputAuthName = InputCallNoText.substring(8, 11);
String InputAuthNameSplit[] = InputAuthName.split("");
System.out.println("TESTING: Your Author tag is " + InputAuthName + ", and it is " + InputAuthName.length() + " characters long.");
System.out.println("TESTING: Your Author tag is " + InputAuthNameSplit[0] + InputAuthNameSplit[1] + InputAuthNameSplit[2] + ", and it is " + InputAuthName.length() + " characters long.");
Double[] InputAuthNameNumbers = new Double[] {0.0, 0.0, 0.0};
//Converts InputAuthName == ABC to InputAuthNameNumbers[01, 02, 03]
for(int AuthName = 0; AuthName < 3; AuthName++) {
System.out.println("TESTING: The letter being checked is the " + AuthName + "th letter and the letter is " + InputAuthNameSplit[AuthName] + ".");
for(int Letter = 0; Letter < 25; Letter++) {
System.out.println("TESTING: Checking letter " + AuthName + " against letter " + Alphabet[Letter] + ".");
System.out.println(Alphabet[Letter].equals(InputAuthNameSplit[AuthName]));
if (Alphabet[Letter].equals(InputAuthNameSplit[AuthName])) {
System.out.println("TESTING: The letter was " + Alphabet[Letter]);
if (Letter == 0) {TrueLetter = 26;} //Turns A into 26 to play around, so 0/100000 isn't 0, but instead 26/100000 = 0.00026
//else if (Letter < 10) {TrueLetter = Letter/10;} // Turns 1 into 0.1, so divides properly (May be useless? Commented out for now. Test.)
else {TrueLetter = Letter;}; // Marks the correct letter as an int (finally).
System.out.println("TESTING: The found letter is: " + InputAuthNameNumbers[AuthName] + ".");
InputAuthNameNumbers[AuthName] = TrueLetter; //Marks the letter into the array of input strings
Letter = 27; //Kills letter < 26 "for" loop. Feels more efficient.
System.out.println("TESTING: The found letter is: " + TrueLetter + ".");
}
}
}
InputAuthNameNumbers[0] = InputAuthNameNumbers[0]/ (double) 100000;
System.out.println("TESTING: The first value is: " + InputAuthNameNumbers[0]);
InputCallNoComp = InputCallNoComp + InputAuthNameNumbers[0];
System.out.println("TESTING: The current Call Number is: " + InputCallNoComp);
InputAuthNameNumbers[1] = InputAuthNameNumbers[1]/ (double) 10000000;
System.out.println("TESTING: The second value is: " + InputAuthNameNumbers[1]);
InputCallNoComp = InputCallNoComp + InputAuthNameNumbers[1];
System.out.println("TESTING: The current Call Number is: " + InputCallNoComp);
InputAuthNameNumbers[2] = InputAuthNameNumbers[2]/ (double) 1000000000;
System.out.println("TESTING: The third value is: " + InputAuthNameNumbers[2]);
InputCallNoComp = InputCallNoComp + InputAuthNameNumbers[2];
System.out.println("TESTING: The current Call Number is: " + InputCallNoComp);
//Searches for Correct Shelf
boolean Found = false;
while (Found == false){
//while (ActiveShelf > CorrectShelf && ActiveShelf <= MaxShelves){
if (InputCallNoComp >= FirstCallNo[ActiveShelf] && InputCallNoComp <= LastCallNo[ActiveShelf]) {
CorrectShelf = ActiveShelf;
Found = true;
}
else {ActiveShelf++;};
}
System.out.println("Our system found your book on shelf " + CorrectShelf + ".");
System.out.println("Here's how to get there:");
//Then generate/print a picture of path.
//This next bit is just a user survey, essentially.
System.out.println("If you used this system, please email pteti@pds.org with the subject line: Library Book Finder.");
System.out.println("In the body of your message, please include the call number of the book you were looking for and whether or not this program found the correct location.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment