Kim:Name Shifter
From OpenWetWare
import java.io.*; import java.util.*;
public class Name_Shifter_KG {
public static void main(String []args) throws FileNotFoundException {
Scanner console = new Scanner(System.in); PrintStream removeables = new PrintStream( new File("removeables.txt")); String more = "y"; while (more.equals("y")){ System.out.println("enter a name to delete"); removeables.println(console.nextLine()); System.out.println("any more names? y/n"); more = console.nextLine(); } PrintStream out1 = new PrintStream(new File("template.txt")); PrintStream out2 = new PrintStream(new File("pics.txt")); PrintStream out3 = new PrintStream(new File("names.txt")); PrintStream FormerMembers = new PrintStream(new File("Former_Members.txt")); Scanner input = new Scanner(new File("original_code.txt")); Scanner template = new Scanner(new File("template.txt")); Scanner pics = new Scanner(new File("pics.txt")); Scanner names = new Scanner(new File("names.txt")); clearer(input, out1, out2, out3); compiler(template, pics, names); }
public static void clearer(Scanner input, PrintStream out1, PrintStream out2,
PrintStream out3) throws FileNotFoundException { while (input.hasNextLine()) {
String line = input.nextLine(); if (line.startsWith("|[[Image:")) { out1.println("||");
if (keep(line)) {
out2.println(line);
} } else if (line.startsWith("|width=\"175\"|")) {
out1.println("|width=\"175\"|");
if (keep(line)) { out3.println(line); }
} else { out1.println(line); } }
}
public static boolean keep(String line) throws FileNotFoundException { Scanner toRemove = new Scanner(new File("removeables.txt")); line = line.replace(" ", ""); line = line.replace("_", ""); int same = 0; while (toRemove.hasNextLine()) { String reference = toRemove.nextLine(); reference = reference.replace(" ", ""); reference = reference.replace("_", ""); if (line.contains(reference)) { same++; } } return same == 0; }
public static void compiler(Scanner template, Scanner pics, Scanner names) {
while (template.hasNextLine()) { String line = template.nextLine(); if (line.startsWith("||") && pics.hasNextLine()) { System.out.println(pics.nextLine()); } else if (line.startsWith("|width=\"175\"|") && names.hasNextLine()) { System.out.println(names.nextLine()); } else { System.out.println(line); } } }
}