Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package story;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintStream;
- import java.util.Scanner;
- /**
- *
- *
- */
- public class Story {
- /**
- * @param args the command line arguments
- */
- public static void setPlaceHolder(Scanner inputFile, String[] names) {
- int i = 0;
- int count = 0;
- while (inputFile.hasNextLine()) {
- String line = inputFile.nextLine();
- String[] tokens = line.split(" ");
- for (String s : tokens) {
- if (!s.contains("<")) {
- System.out.print(s + " ");
- }
- if (s.contains("<")) {
- count++;
- }
- if (count == 2) {
- i++;
- }
- if (s.contains("<")) {
- System.out.print(names[i] + " ");
- if (count == 2) {
- count = 0;
- }
- }
- }
- count = 0;
- System.out.println();
- i++;
- }
- public static void main(String[] args) throws FileNotFoundException {
- Scanner input = new Scanner(System.in);
- Scanner inputFile = null;
- String fileName;
- String[] names = new String[6];
- String[] questions = {"Please enter an adjective: ",
- "Please enter a plural noun: ",
- "Please enter a noun: ",
- "Please enter an adjective: ",
- "Please enter a place: "};
- System.out.print("Input file name?: ");
- fileName = input.nextLine();
- try {
- File file = new File(fileName);
- inputFile = new Scanner(file);
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- for (int i = 0; i < questions.length; i++) {
- System.out.print(questions[i]);
- names[i] = input.nextLine();
- }
- System.out.println();
- setPlaceHolder(inputFile, names);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement