Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.06 KB | None | 0 0
  1. package ls223iu_assign4;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.util.Scanner;
  7.  
  8. public class ObscureLovecraft {
  9.     static boolean isInteger(String string) {
  10.         String temp = string.trim();
  11.         try
  12.         {
  13.             Integer.parseInt(temp);
  14.         }
  15.         catch (NumberFormatException e) {
  16.             return false;
  17.         }
  18.         return true;
  19.     }
  20.     public static void main(String[] args) throws IOException {
  21.         Scanner userInputReader = new Scanner(System.in);
  22.         File fileIn = new File("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\lovecraft.txt");
  23.         File fileOutObscure = new File("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\obscure.txt");
  24.         File fileOutReadable = new File ("C:\\Users\\lucas\\private\\java\\java_courses\\1DV506\\src\\ls223iu_assign4\\readableLovecraft.txt");
  25.         Scanner fileInScan = new Scanner(fileIn);
  26.         Scanner fileOutScan = new Scanner(fileOutObscure);
  27.         Scanner userInputScan = new Scanner(System.in);
  28.         PrintWriter printerObscure = new PrintWriter(fileOutObscure);
  29.         PrintWriter printerReadable = new PrintWriter(fileOutReadable);
  30.         boolean status = true;
  31.  
  32.         String userInput = "";
  33.         while (status) {
  34.  
  35.             System.out.println("Obscure");
  36.             System.out.println("========");
  37.             System.out.println("1. Make obscure");
  38.             System.out.println("2. Make readable");
  39.             System.out.println("3. Print obscure");
  40.             System.out.println("4. Print readable");
  41.             System.out.println("0. Exit");
  42.             System.out.print("\n==> ");
  43.             userInput = userInputScan.nextLine();
  44.  
  45.             String test = "abc";
  46.             String testResultReadable = "";
  47.             String testResultCipher = "";
  48.             int lineAmount = 0;
  49.  
  50.  
  51. //            System.out.println(testResultCipher);
  52.  
  53. //        while(fileOutScan.hasNextLine()) {
  54. //            String word = fileOutScan.nextLine();
  55. //            System.out.println(word);
  56. //        }
  57.  
  58. //            lineAmount = 0;
  59. //            while (fileOutScan.hasNextLine()) {
  60. //                testResultReadable = "";
  61. //                if (lineAmount == 100) {
  62. //                    break;
  63. //                }
  64. //                String currentLine = fileOutScan.nextLine();
  65. //                if (currentLine.length() == 0) {
  66. //                    int lol = 0;
  67. //                } else if (isInteger(currentLine)) {
  68. //                    testResultReadable += currentLine;
  69. //                } else {
  70. //                    for (int i = 0; i < currentLine.length(); i++) {
  71. //                        char tempChar = currentLine.charAt(i);
  72. //                        int newNumericValue = tempChar;
  73. //                        newNumericValue += -3;
  74. //                        char newTempChar = (char) newNumericValue;
  75. //                        testResultReadable += newTempChar;
  76. //                    }
  77. //                }
  78. //                testResultReadable += "\n";
  79. //                printerReadable.print(testResultReadable);
  80. //                System.out.println(testResultReadable);
  81. //                lineAmount++;
  82. //            }
  83.  
  84.             switch (userInput) {
  85.                 case "0":
  86.                     status = false;
  87.                     break;
  88.  
  89.                 case "1":
  90.                     while (fileInScan.hasNextLine()) {
  91.                         testResultCipher = "";
  92.                         if (lineAmount == 100) {
  93.                             printerObscure.close();
  94.                             break;
  95.                         }
  96.                         String currentLine = fileInScan.nextLine();
  97.                         if (currentLine.length() == 0) {
  98. //                testResultCipher += "\n";
  99.                         } else if (isInteger(currentLine)) {
  100.                             testResultCipher += currentLine;
  101.                         } else {
  102.                             for (int i = 0; i < currentLine.length(); i++) {
  103.                                 char tempChar = currentLine.charAt(i);
  104.                                 int newNumericValue = tempChar;
  105.                                 newNumericValue += 3;
  106.                                 char newTempChar = (char) newNumericValue;
  107.                                 testResultCipher += newTempChar;
  108.                             }
  109.                         }
  110.                         testResultCipher += "\n";
  111.                         lineAmount++;
  112.                         printerObscure.print(testResultCipher);
  113.                     }
  114.                     break;
  115.  
  116.                 case "2":
  117.                     lineAmount = 0;
  118.                     while (fileOutScan.hasNextLine()) {
  119.                         testResultReadable = "";
  120.                         if (lineAmount == 100) {
  121.                             break;
  122.                         }
  123.                         String currentLine = fileOutScan.nextLine();
  124.                         if (currentLine.length() == 0) {
  125.                         } else if (isInteger(currentLine)) {
  126.                             testResultReadable += currentLine;
  127.                         } else {
  128.                             for (int i = 0; i < currentLine.length(); i++) {
  129.                                 char tempChar = currentLine.charAt(i);
  130.                                 int newNumericValue = tempChar;
  131.                                 newNumericValue += -3;
  132.                                 char newTempChar = (char) newNumericValue;
  133.                                 testResultReadable += newTempChar;
  134.                             }
  135.                         }
  136.                         testResultReadable += "\n";
  137.                         lineAmount++;
  138.                         printerReadable.print(testResultReadable);
  139.                     }
  140.                     break;
  141.  
  142.                     default:
  143.                         System.out.println("That is not an option.");
  144.                         break;
  145.             }
  146.         }
  147.  
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement