Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* (c) Tyler Holley January, 2018
- * CitationGenerator Version 0.3
- *
- * 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.
- */
- import java.util.Scanner;
- import java.awt.datatransfer.*; // First import for clipboard copying
- import java.awt.Toolkit; // Second import for clipboard copying
- class CitationGenerator {
- public static String bookFormat(String author, String title, String publisher, int pubDate) {
- String bFormat = author + ". " + title + ", " + publisher + ", " + pubDate + ".";
- return bFormat;
- }
- public static String siteFormat(String author, String siteName, String publisher, String pubFull, String url, String accessDate) {//Need to add date after consulting Mr. Blake.
- String sFormat = author + ". " + siteName + ". " + publisher + ", " + pubFull + ", " + url + ". Accessed " + accessDate;
- return sFormat;
- }
- public static String dateMerge(String pubY, String pubMB4, String pubD) {
- String pubM = pubMB4.substring(0,3) + ".";
- String pubFull = pubD + pubM + pubY;
- return pubFull;
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String error1 = "ERROR 001: INVALID INPUT."; // Catchall error
- String errorN = "\nERROR 002: That other format is currently not supported in this version. Please rerun the program."; // Filler error while WIP
- System.out.println("Welcome to Tyler Holley's CitationGenerator v0.2!");
- System.out.print("What format is your citation in? MLA/APA: "); // Add APA/Chicago support
- String format = in.next();
- if (format.equalsIgnoreCase("MLA")) { // equalsIgnoreCase ignores case inputted so MLA, mLa, mla, etc. are all valid
- System.out.print("\nIs your source a book, website, or other? ");
- String sourceType = in.next();
- // Try and figure out how to clear the console after the user inputs sourceType
- if (sourceType.equalsIgnoreCase("book")) {
- System.out.print("\nAuthor's First Name: ");
- String fName = in.next();
- System.out.print("Author's Last Name: ");
- String lName = in.next();
- in.nextLine();
- System.out.print("\nBook Title: ");
- String title = in.nextLine();
- System.out.print("\nPublisher Name: ");
- String publisher = in.nextLine();
- System.out.print("\nPublication Year: ");
- int pubDate = in.nextInt();
- String author = lName + ", " + fName; // Converts fName and lName to one concatonated String
- System.out.print("\n\nYour citation is ready, would you like to save it to the clipboard? y/n ");
- String option = in.next();
- if (option.equalsIgnoreCase("y") || option.equalsIgnoreCase("yes")) {
- String doneFormatting = bookFormat(author, title, publisher, pubDate);
- StringSelection stringSelection = new StringSelection(doneFormatting);
- Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
- clpbrd.setContents(stringSelection, null);
- }
- else {
- System.out.println("\n\nHere is your citation! Don't forget to italicize the title!\n");
- System.out.println(bookFormat(author, title, publisher, pubDate));
- }
- }
- else if (sourceType.equalsIgnoreCase("website")) {
- System.out.print("\nIs it an entire website (Example: wikihow.com) or a specific page (Example: \"How To Make Pasta\")? Site/Page: ");
- String webType = in.next();
- if (webType.equalsIgnoreCase("site")) {
- System.out.print("\n\nAuthor First Name: ");
- String fName = in.next();
- System.out.print("Author Last Name: ");
- String lName = in.next();
- in.nextLine();
- String author = lName + ", " + fName;
- System.out.print("\nName of Site (Example: wikiHow): ");
- String siteName = in.nextLine();
- System.out.print("\nSite Publsiher: ");
- String publisher = in.nextLine();
- System.out.print("\nPublication Year: ");
- int pubY = in.nextInt();
- System.out.print("Publication Month (Name of Month): ");
- String pubMB4 = in.next();
- System.out.print("Publication Day: ");
- String pubD = in.next();
- String pubFull = dateMerge(pubY, pubMB4, pubD);
- System.out.println(pubFull);
- System.out.print("Website URL (Example: www.wikihow.com/): ");
- String url = in.next();
- System.out.println("Date Accessed: ");
- System.out.print("Day: ");
- String accessD = in.next();
- System.out.print("Month: ");
- String accessMB4 = in.next();
- System.out.print("Year: ");
- String accessY = in.next();
- String accessDate = dateMerge(accessD, accessMB4, accessY);
- //System.out.print("\n\nYour citation is ready, would you like to save it to the clipboard? y/n ");
- //String option = in.next();
- //if (option.equalsIgnoreCase("y") || option.equalsIgnoreCase("yes")) {
- //String doneFormatting = bookFormat(author, title, publisher, pubDate);
- //StringSelection stringSelection = new StringSelection(doneFormatting);
- //Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
- //clpbrd.setContents(stringSelection, null);
- //}
- //else {
- //System.out.println("\n\nHere is your citation! Don't forget to italicize the title!\n");
- //System.out.println(bookFormat(author, title, publisher, pubDate));
- //}
- }
- else {
- System.out.println("\n" + error1);
- }
- }
- else if (webType.equalsIgnoreCase("page")) {
- System.out.println(errorN);
- }
- }
- else {
- System.out.println("\n" + errorN);
- // Add if-statements to support citations such as magazine/newspaper articles, tweets, etc.
- }
- }
- else { // >> HERE IS THE ERROR! <<
- System.out.println(error1 + "\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement