Advertisement
bluewizard3

Citation Generator v0.3

Jan 22nd, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.91 KB | None | 0 0
  1. /* (c) Tyler Holley January, 2018
  2.  * CitationGenerator Version 0.3
  3.  *
  4.  * User inputs academic source information and gets a proper citation for either copying to the clipboard completely formatted or output to the terminal for manual formatting.
  5.  */
  6.  
  7. import java.util.Scanner;
  8. import java.awt.datatransfer.*; // First import for clipboard copying
  9. import java.awt.Toolkit; // Second import for clipboard copying
  10.  
  11.  
  12. class CitationGenerator {
  13.     public static String bookFormat(String author, String title, String publisher, int pubDate) {
  14.         String bFormat = author + ". " + title + ", " + publisher + ", " + pubDate + ".";
  15.        
  16.         return bFormat;
  17.     }
  18.    
  19.     public static String siteFormat(String author, String siteName, String publisher, String pubFull, String url, String accessDate) {//Need to add date after consulting Mr. Blake.
  20.         String sFormat = author + ". " + siteName + ". " + publisher + ", " + pubFull + ", " + url + ". Accessed " + accessDate;
  21.  
  22.         return sFormat;
  23.     }
  24.    
  25.     public static String dateMerge(String pubY, String pubMB4, String pubD) {
  26.         String pubM = pubMB4.substring(0,3) + ".";
  27.         String pubFull = pubD + pubM + pubY;
  28.        
  29.         return pubFull;
  30.     }
  31.        
  32.     public static void main(String[] args) {
  33.         Scanner in = new Scanner(System.in);
  34.        
  35.         String error1 = "ERROR 001: INVALID INPUT."; // Catchall error
  36.         String errorN = "\nERROR 002: That other format is currently not supported in this version. Please rerun the program."; // Filler error while WIP
  37.        
  38.         System.out.println("Welcome to Tyler Holley's CitationGenerator v0.2!");
  39.         System.out.print("What format is your citation in? MLA/APA: "); // Add APA/Chicago support
  40.         String format = in.next();
  41.            
  42.         if (format.equalsIgnoreCase("MLA")) { // equalsIgnoreCase ignores case inputted so MLA, mLa, mla, etc. are all valid
  43.             System.out.print("\nIs your source a book, website, or other? ");
  44.             String sourceType = in.next();
  45.             // Try and figure out how to clear the console after the user inputs sourceType
  46.            
  47.             if (sourceType.equalsIgnoreCase("book")) {
  48.                 System.out.print("\nAuthor's First Name: ");
  49.                 String fName = in.next();
  50.                
  51.                 System.out.print("Author's Last Name: ");
  52.                 String lName = in.next();
  53.                 in.nextLine();
  54.                
  55.                 System.out.print("\nBook Title: ");
  56.                 String title = in.nextLine();
  57.                
  58.                 System.out.print("\nPublisher Name: ");
  59.                 String publisher = in.nextLine();
  60.                
  61.                 System.out.print("\nPublication Year: ");
  62.                 int pubDate = in.nextInt();
  63.                
  64.                 String author = lName + ", " + fName; // Converts fName and lName to one concatonated String
  65.                
  66.                 System.out.print("\n\nYour citation is ready, would you like to save it to the clipboard? y/n ");
  67.                 String option = in.next();
  68.  
  69.                 if (option.equalsIgnoreCase("y") || option.equalsIgnoreCase("yes")) {
  70.                     String doneFormatting = bookFormat(author, title, publisher, pubDate);
  71.                     StringSelection stringSelection = new StringSelection(doneFormatting);
  72.                     Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
  73.                     clpbrd.setContents(stringSelection, null);
  74.                 }
  75.                
  76.                 else {
  77.                     System.out.println("\n\nHere is your citation! Don't forget to italicize the title!\n");
  78.                     System.out.println(bookFormat(author, title, publisher, pubDate));
  79.                 }
  80.             }
  81.            
  82.             else if (sourceType.equalsIgnoreCase("website")) {
  83.                 System.out.print("\nIs it an entire website (Example: wikihow.com) or a specific page (Example: \"How To Make Pasta\")? Site/Page: ");
  84.                 String webType = in.next();
  85.                
  86.                 if (webType.equalsIgnoreCase("site")) {
  87.                     System.out.print("\n\nAuthor First Name: ");
  88.                     String fName = in.next();
  89.                     System.out.print("Author Last Name: ");
  90.                     String lName = in.next();
  91.                     in.nextLine();
  92.                     String author = lName + ", " + fName;
  93.                    
  94.                     System.out.print("\nName of Site (Example: wikiHow): ");
  95.                     String siteName = in.nextLine();
  96.                    
  97.                     System.out.print("\nSite Publsiher: ");
  98.                     String publisher = in.nextLine();
  99.                    
  100.                    
  101.                     System.out.print("\nPublication Year: ");
  102.                     int pubY = in.nextInt();
  103.                    
  104.                     System.out.print("Publication Month (Name of Month): ");
  105.                     String pubMB4 = in.next();
  106.                                                                
  107.                     System.out.print("Publication Day: ");
  108.                     String pubD = in.next();
  109.                    
  110.                     String pubFull = dateMerge(pubY, pubMB4, pubD);
  111.                     System.out.println(pubFull);
  112.                    
  113.                    
  114.                     System.out.print("Website URL (Example: www.wikihow.com/): ");
  115.                     String url = in.next();
  116.                    
  117.                    
  118.                     System.out.println("Date Accessed: ");
  119.                    
  120.                     System.out.print("Day: ");
  121.                     String accessD = in.next();
  122.                    
  123.                     System.out.print("Month: ");
  124.                     String accessMB4 = in.next();
  125.                    
  126.                     System.out.print("Year: ");
  127.                     String accessY = in.next();
  128.                    
  129.                     String accessDate = dateMerge(accessD, accessMB4, accessY);
  130.                        
  131.                     //System.out.print("\n\nYour citation is ready, would you like to save it to the clipboard? y/n ");
  132.                     //String option = in.next();
  133.  
  134.                     //if (option.equalsIgnoreCase("y") || option.equalsIgnoreCase("yes")) {
  135.                         //String doneFormatting = bookFormat(author, title, publisher, pubDate);
  136.                         //StringSelection stringSelection = new StringSelection(doneFormatting);
  137.                         //Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
  138.                         //clpbrd.setContents(stringSelection, null);
  139.                     //}
  140.                    
  141.                     //else {
  142.                         //System.out.println("\n\nHere is your citation! Don't forget to italicize the title!\n");
  143.                         //System.out.println(bookFormat(author, title, publisher, pubDate));
  144.                     //}
  145.                     }
  146.                     else {
  147.                         System.out.println("\n" + error1);
  148.                     }
  149.                 }
  150.                
  151.                 else if (webType.equalsIgnoreCase("page")) {
  152.                     System.out.println(errorN);
  153.                 }
  154.             }
  155.            
  156.             else {
  157.                 System.out.println("\n" + errorN);
  158.                 // Add if-statements to support citations such as magazine/newspaper articles, tweets, etc.
  159.             }
  160.         }
  161.        
  162.         else { // >> HERE IS THE ERROR! <<
  163.             System.out.println(error1 + "\n"); 
  164.         }
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement