SHARE
TWEET

Untitled

a guest Feb 21st, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. * To change this template, choose Tools | Templates
  4.  
  5. * and open the template in the editor.
  6.  
  7. */
  8.  
  9. package story;
  10.  
  11.  
  12.  
  13. import java.io.File;
  14.  
  15. import java.io.FileNotFoundException;
  16.  
  17. import java.io.PrintStream;
  18.  
  19. import java.util.Scanner;
  20.  
  21.  
  22.  
  23. /**
  24.  
  25. *
  26.  
  27. *
  28.  
  29. */
  30.  
  31. public class Story {
  32.  
  33.  
  34.  
  35. /**
  36.  
  37. * @param args the command line arguments
  38.  
  39. */
  40.  
  41.  
  42.  
  43. public static void setPlaceHolder(Scanner inputFile, String[] names) {
  44.  
  45. int i = 0;
  46.  
  47. int count = 0;
  48.  
  49.  
  50.  
  51. while (inputFile.hasNextLine()) {
  52.  
  53. String line = inputFile.nextLine();
  54.  
  55. String[] tokens = line.split(" ");
  56.  
  57. for (String s : tokens) {
  58.  
  59. if (!s.contains("<")) {
  60.  
  61. System.out.print(s + " ");
  62.  
  63. }
  64.  
  65. if (s.contains("<")) {
  66.  
  67. count++;
  68.  
  69. }
  70.  
  71. if (count == 2) {
  72.  
  73. i++;
  74.  
  75. }
  76.  
  77. if (s.contains("<")) {
  78.  
  79. System.out.print(names[i] + " ");
  80.  
  81. if (count == 2) {
  82.  
  83. count = 0;
  84.  
  85. }
  86.  
  87. }
  88.  
  89. }
  90.  
  91. count = 0;
  92.  
  93. System.out.println();
  94.  
  95. i++;
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102. public static void main(String[] args) throws FileNotFoundException {
  103.  
  104.  
  105.  
  106.  
  107.  
  108. Scanner input = new Scanner(System.in);
  109.  
  110. Scanner inputFile = null;
  111.  
  112. String fileName;
  113.  
  114. String[] names = new String[6];
  115.  
  116. String[] questions = {"Please enter an adjective: ",
  117.  
  118. "Please enter a plural noun: ",
  119.  
  120. "Please enter a noun: ",
  121.  
  122. "Please enter an adjective: ",
  123.  
  124. "Please enter a place: "};
  125.  
  126.  
  127.  
  128. System.out.print("Input file name?: ");
  129.  
  130. fileName = input.nextLine();
  131.  
  132.  
  133.  
  134. try {
  135.  
  136. File file = new File(fileName);
  137.  
  138. inputFile = new Scanner(file);
  139.  
  140. } catch (Exception e) {
  141.  
  142. System.out.println(e.getMessage());
  143.  
  144. }
  145.  
  146. for (int i = 0; i < questions.length; i++) {
  147.  
  148. System.out.print(questions[i]);
  149.  
  150. names[i] = input.nextLine();
  151.  
  152. }
  153.  
  154. System.out.println();
  155.  
  156. setPlaceHolder(inputFile, names);
  157.  
  158. }
  159.  
  160. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top