Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ls223iu_assign4;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class ObscureLovecraft {
- static boolean isInteger(String string) {
- String temp = string.trim();
- try
- {
- Integer.parseInt(temp);
- }
- catch (NumberFormatException e) {
- return false;
- }
- return true;
- }
- public static void main(String[] args) throws IOException {
- Scanner userInputReader = new Scanner(System.in);
- File fileIn = new File("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\lovecraft.txt");
- File fileOutObscure = new File("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\obscure.txt");
- File fileOutReadable = new File ("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\readableLovecraft.txt");
- Scanner fileInScan = new Scanner(fileIn);
- Scanner fileOutScan = new Scanner(fileOutObscure);
- Scanner userInputScan = new Scanner(System.in);
- PrintWriter printerObscure = new PrintWriter(fileOutObscure);
- PrintWriter printerReadable = new PrintWriter(fileOutReadable);
- boolean status = true;
- String userInput = "";
- while (status) {
- System.out.println("Obscure");
- System.out.println("========");
- System.out.println("1. Make obscure");
- System.out.println("2. Make readable");
- System.out.println("3. Print obscure");
- System.out.println("4. Print readable");
- System.out.println("0. Exit");
- System.out.print("\n==> ");
- userInput = userInputScan.nextLine();
- String test = "abc";
- String testResultReadable = "";
- String testResultCipher = "";
- int lineAmount = 0;
- // System.out.println(testResultCipher);
- // while(fileOutScan.hasNextLine()) {
- // String word = fileOutScan.nextLine();
- // System.out.println(word);
- // }
- // lineAmount = 0;
- // while (fileOutScan.hasNextLine()) {
- // testResultReadable = "";
- // if (lineAmount == 100) {
- // break;
- // }
- // String currentLine = fileOutScan.nextLine();
- // if (currentLine.length() == 0) {
- // int lol = 0;
- // } else if (isInteger(currentLine)) {
- // testResultReadable += currentLine;
- // } else {
- // for (int i = 0; i < currentLine.length(); i++) {
- // char tempChar = currentLine.charAt(i);
- // int newNumericValue = tempChar;
- // newNumericValue += -3;
- // char newTempChar = (char) newNumericValue;
- // testResultReadable += newTempChar;
- // }
- // }
- // testResultReadable += "\n";
- // printerReadable.print(testResultReadable);
- // System.out.println(testResultReadable);
- // lineAmount++;
- // }
- switch (userInput) {
- case "0":
- status = false;
- break;
- case "1":
- while (fileInScan.hasNextLine()) {
- testResultCipher = "";
- if (lineAmount == 100) {
- printerObscure.close();
- break;
- }
- String currentLine = fileInScan.nextLine();
- if (currentLine.length() == 0) {
- // testResultCipher += "\n";
- } else if (isInteger(currentLine)) {
- testResultCipher += currentLine;
- } else {
- for (int i = 0; i < currentLine.length(); i++) {
- char tempChar = currentLine.charAt(i);
- int newNumericValue = tempChar;
- newNumericValue += 3;
- char newTempChar = (char) newNumericValue;
- testResultCipher += newTempChar;
- }
- }
- testResultCipher += "\n";
- lineAmount++;
- printerObscure.print(testResultCipher);
- }
- break;
- case "2":
- lineAmount = 0;
- while (fileOutScan.hasNextLine()) {
- testResultReadable = "";
- if (lineAmount == 100) {
- break;
- }
- String currentLine = fileOutScan.nextLine();
- if (currentLine.length() == 0) {
- } else if (isInteger(currentLine)) {
- testResultReadable += currentLine;
- } else {
- for (int i = 0; i < currentLine.length(); i++) {
- char tempChar = currentLine.charAt(i);
- int newNumericValue = tempChar;
- newNumericValue += -3;
- char newTempChar = (char) newNumericValue;
- testResultReadable += newTempChar;
- }
- }
- testResultReadable += "\n";
- lineAmount++;
- printerReadable.print(testResultReadable);
- }
- break;
- default:
- System.out.println("That is not an option.");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement