Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * String to Poop 1.0 Converter
- * @author Maximilian Krause
- * @since 11-07-2015
- * @ver 1.1
- *
- * Changelog
- * 1.1
- * - Added uppercase/lowercase output through char uppercase detection
- *
- * This converter is capable of getting a String from a file and outputting the equivalent for Poop 1.0. Due to Poops limits, the Poop 1.0 output will not support spaces but will write every word into a new line.
- *
- * Licensed under CC-BY 4.0.
- */
- package de.maxkrause;
- //importing needed tools
- import java.io.*;
- import java.util.Scanner;
- public class main {
- static boolean debug = false; //debug bool, activate if you want debug output
- public static void main(String[] args) {
- System.out.println("String to Poop 1.0 Translator, made by Maximilian Krause. Licensed under CC-BY 4.0. Please input a file without any new-lines. Change new-lines to spaces if needed. Poop 1.0 doesn't support new-lines, every new word will get into a new line anyway.");;
- Scanner in = new Scanner(System.in); //opening a scanner to get the input filename
- //setting some needed, accessible vars
- int curIndex = 0;
- String chars = "0123456789abcdefghijklmnopqrstuvwxyz.,-!?+*<>#@$โฌยง%&/()[]"; //Poop 1.0 supported characters
- String input = "";
- String output = "";
- boolean gotFile = false;
- String str_input_file = "";
- while(!gotFile){ //always asking for input until a valid file was opened
- System.out.print("File with content to translate: ");
- str_input_file = in.next();
- try {
- Scanner input_file = new Scanner(new FileReader(str_input_file)); //opening a new scanner to get the file content
- input = input_file.nextLine(); //reading the file content into input
- gotFile = true; //closing the loop
- //closing the scanners
- input_file.close();
- in.close();
- while(input.endsWith(" ")){
- input = input.substring(0, input.length()-2); //removing a last space if found
- }
- System.out.println("Got input: " + input);
- } catch (FileNotFoundException e) {
- System.out.println("File not found."); //file not found, looping back
- }
- }
- System.out.println("Now calculating. Please wait...");
- for(int i = 0; (input.length()) > i; i++){ //starting calculation process
- if(debug){
- System.out.println("[DEBUG] Now checking character #" + i + ", which is " + input.charAt(i) + ", which got the Poop index #" + chars.indexOf(input.toLowerCase().charAt(i)));
- }
- if(input.charAt(i) == ' '){ //checking if current character is a space
- if(debug){
- System.out.println("Received a space character, printing sniff\\nflush\\n.");
- }
- output += "sniff\nflush\n"; //if so, doing a "sniff" and a "flush" to print the last word
- curIndex = 0; //resetting the current Poop 1.0 character index, as flush does so as well
- }else{
- boolean isPuke = false;
- if(debug){
- System.out.println("[DEBUG] Previous index: " + curIndex);
- }
- int eats = chars.indexOf(input.toLowerCase().charAt(i)) - curIndex;
- curIndex = chars.indexOf(input.toLowerCase().charAt(i));
- if(debug){
- System.out.println("[DEBUG] Got the command for " + eats + " eats, checking if I should puke.");
- }
- if(eats < 0){
- //eats is negative, which means that we need to go back on the Poop 1.0 index -> puke instead of eat
- eats = eats * -1;
- if(debug){
- System.out.println("[DEBUG] Puking " + curIndex + " times.");
- }
- isPuke = true;
- }
- //printing the needed times of eat or puke
- if(isPuke){
- output += new String(new char[eats]).replace("\0", "puke ");
- }else{
- output += new String(new char[eats]).replace("\0", "eat ");
- }
- //checking if we needed an uppercase letter
- if(Character.isUpperCase(input.charAt(i))){
- output += "\nPOOP\n";
- }else{
- output += "\npoop\n";
- }
- }
- }
- //last String output
- output += "sniff";
- //writing to output file (input + "_poo")
- Writer writer = null;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(str_input_file + "_poo"), "utf-8"));
- writer.write(output);
- } catch (IOException ex) {} finally {
- try {writer.close();} catch (Exception ex) {}
- }
- System.out.println("Output written to " + str_input_file + "_poo.");
- }
- }
Add Comment
Please, Sign In to add comment