hello, I have errors in my code, and i'm not sure on how fix my some of my myethods. I have the outline for my code bellow, as well as the rubric: description:  Write a java application that will open an input file and open an output file. The file names can be entered fromthe command line, if a command line parameter is included, it will be used as the input file name. If a second command line parameter is included, it will be used as the output file name. Any missing parameters will be prompted for and read by the program. When the input file does not exist the user will be prompted to re-enter an input file name. When nothing is entered for the input file name, on a prompt, the program will proceed to the end of the program and terminate. When the output file exists the user will havea choice of entering a new output file name, backing up the existing output file first, overwriting the existingoutput file, or quitting the program without opening any files. Again, not entering a file name will alsoterminate the program. The program will catch any file open error and print a message. Using StringTokenizer, the program will parse the input file and identify words and integers. Words are notcase sensitive and can only contain letters, apostrophes, hyphens, and digits but must start with a letter. The numbers are a sequence of digits. They can be positive or negative integers. If the number is negative, there is no space between the negative sign, -, and the first digit. A sum will be made form the integers contained in the input file.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

hello, I have errors in my code, and i'm not sure on how fix my some of my myethods. I have the outline for my code bellow, as well as the rubric:

description:

 Write a java application that will open an input file and open an output file. The file names can be entered fromthe command line, if a command line parameter is included, it will be used as the input file name. If a second command line parameter is included, it will be used as the output file name. Any missing parameters will be
prompted for and read by the program. When the input file does not exist the user will be prompted to re-enter
an input file name. When nothing is entered for the input file name, on a prompt, the program will proceed to
the end of the program and terminate. When the output file exists the user will havea choice of entering a new output file name, backing up the existing output file first, overwriting the existingoutput file, or quitting the program without opening any files. Again, not entering a file name will alsoterminate the program. The program will catch any file open error and print a message.
Using StringTokenizer, the program will parse the input file and identify words and integers. Words are notcase sensitive and can only contain letters, apostrophes, hyphens, and digits but must start with a letter. The
numbers are a sequence of digits. They can be positive or negative integers. If the number is negative, there is
no space between the negative sign, -, and the first digit. A sum will be made form the integers contained in the
input file.

code:
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
 
 
 class Program2
{
       public static void main (String[]args) throws IOException {
   
        IOFile Myfiles= new IOFile();
   
        int i= 0;    // Array index 
   int count =0;             // number of Word objects in words array 
   int sum =0 ;                 // sum of integers 
   String word= null;     // token 
   String num = null;    // String of number 
   String inbuffer;          // input file buffer 
   String[]ionames = new String [2];        //array for input and output file names 
   Word[]words = new Word [100];      // Array of word objects
   StringTokenizer inline ;                       //Stringtokenizer  of current line 
   BufferedReader infile;                        // input  file handle 
   PrintWriter outfile;                            // output file handle 
 
    BufferedReader in=IOFile.openin(Myfiles[0]); 
        if(Myfiles.getnames(args,ionames)){
        infile=IOFile.openin(ionames[0]);
        outfile=IOFile.openout(ionames[1]);
       } 
  else 
        System.out.println("error, file not found");
 
 
 
 }
}
        
 
    
    class IOFile
    {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 String input;
   boolean getnames(String[] args, String[] ioname){
 switch(args.length){
 
 case 0 :
 System.out.print("enter input file : ");
 System.out.flush();
 input= br.readLine();
  // check if file path is empty , 
 case 1 : 
 case 2 :
 }
 }
 boolean FileExist(String name) {
    File dummy = new File (name);
     exists = dummy.exists();
     return exists;
 }
 
 Void FileBackup(String name, String ext){
String BKP;
BKP= name.substring(0, name.lastindexOf("."))+"." +ext;
  File old= new File(name);
      File back = new File(newname);
           if(FileExist(newname)){
  back.delete();
  }
   old.renameTo(back);
 }
 String FileExtension (String name ) {
 if (!name.lastindexOf(".")= -1)
 { 
 String after = name.lastindexOf(".")+1;
 return  after;
 }
 return null;
 }
     String FileName (String name) 
     {
String check = name.substring(name.lastindexOf("\\")+1,name.lastindexOf("."));
 return check;
 }
 String FilePath(String name ){
String check = name.substring(name.lastindexOf(":")+1,name.lastindexOf("\\")+1);
 return check;
 }
BufferedReader openin ( String name ){
  BufferedReader in = null; 
try{
in = new BufferedReader(new FileReader(name));
 }
 catch(FileNotFoundException e) {
 System.out.println("error, file not found");
 }   
 
 return in;
 }
 PrintWriter openout (String name){
 PrintWriter out = null;
 try{
 out= new PrintWriter(new FileWriter(name));
 }
  catch(FileNotFoundException e) {
 System.out.println("error, file not found");
 }   
 return out;
 }  
    }
     
    
    class Word {
            Word (String word){}
int getCount(){}
String getWord(){}
Boolean isWord(String word){}
Boolean isWordIgnoreCase(String word){}
Void addOne(){}
Void print( PrintWriter out ){}
            int FindWord(Word[] list, String Word, int n ){}
}
    
cannot find symbol
String after = name.lastindexOf(".")+1;
Program2.java:83: error:
method lastindexOf(String)
location: variable name of type String
Program2.java:90: error: cannot find symbol
String check =
symbol:
name.substring(name.lastindexOf ("\\")+1,name.lastindexof ("."));
method lastindexOf(String)
location: variable name of type String
Program2.java:90: error: cannot find symbol
String check =
symbol:
name.substring(name.lastindexOf ("\\")+1,name.lastindexof ("."));
method lastindexOf(String)
symbol:
location: variable name of type String
Program2.java:94: error: cannot find symbol
String check = name.substring(name.lastindexof (":")+1,name.lastindexof ("\\")+1);
Transcribed Image Text:cannot find symbol String after = name.lastindexOf(".")+1; Program2.java:83: error: method lastindexOf(String) location: variable name of type String Program2.java:90: error: cannot find symbol String check = symbol: name.substring(name.lastindexOf ("\\")+1,name.lastindexof (".")); method lastindexOf(String) location: variable name of type String Program2.java:90: error: cannot find symbol String check = symbol: name.substring(name.lastindexOf ("\\")+1,name.lastindexof (".")); method lastindexOf(String) symbol: location: variable name of type String Program2.java:94: error: cannot find symbol String check = name.substring(name.lastindexof (":")+1,name.lastindexof ("\\")+1);
Program2.java:36: error: non-static method openout(String) cannot be referenced from a static context
outfile=IOFile.openout(ionames[1]);
Program2.java:66: error: cannot find symbol
dummy.exists();
exists =
variable exists
symbol:
location: class IOFile
Program2.java:67: error: cannot find symbol
return exists;
symbol:
location: class IOFile
variable exists
Program2.java:72: error: cannot find symbol
BKP= name.substring(0, name.lastindexOf ("."))+"." +ext;
method lastindexOf(String)
symbol:
location: variable name of type String
Transcribed Image Text:Program2.java:36: error: non-static method openout(String) cannot be referenced from a static context outfile=IOFile.openout(ionames[1]); Program2.java:66: error: cannot find symbol dummy.exists(); exists = variable exists symbol: location: class IOFile Program2.java:67: error: cannot find symbol return exists; symbol: location: class IOFile variable exists Program2.java:72: error: cannot find symbol BKP= name.substring(0, name.lastindexOf ("."))+"." +ext; method lastindexOf(String) symbol: location: variable name of type String
Expert Solution
Step 1

package bartleby;

import java.io.*;
import java.nio.file.Files;
import java.util.StringTokenizer;

public class Program2 {
 public static void main(String[] args) throws IOException {

  IOFile myFilesObj = new IOFile();

  int i = 0; // Array index
  int count = 0; // number of Word objects in words array
  int sum = 0; // sum of integers
  // Word[] words = new Word[100]; // Array of word objects
  StringTokenizer inline; // Stringtokenizer of current line
  BufferedReader infile; // input file handle
  PrintWriter outfile; // output file handle

  myFilesObj.validateNames(args);

  infile = myFilesObj.openIn(myFilesObj.inputFileName);
  outfile = myFilesObj.openOut(myFilesObj.outputFileName);

 }
}

class IOFile {
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 String inputFileName, outputFileName;

 void validateNames(String[] args) {
  switch (args.length) {
  case 0:
   getInputFileName();
   getOutputFileName();
   break;
  case 1:
   getInputFileName(args[0]);
   getOutputFileName();
   break;
  case 2:
   getInputFileName(args[0]);
   getOutputFileName(args[1]);
   break;
  }
 }

 private void getOutputFileName() {
  try {
   System.out.print("enter output file : ");
   outputFileName = br.readLine();
   if (outputFileName.equals(""))
    System.exit(0);
   if (!fileExists(outputFileName)) {
    createFile(outputFileName);
   } else {
    backup(outputFileName, getBackupFileName(outputFileName));
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 private void getOutputFileName(String outputFileName) {
  this.outputFileName = outputFileName;
  if (!fileExists(outputFileName)) {
   createFile(outputFileName);
  } else {
   backup(outputFileName, getBackupFileName(outputFileName));
  }
 }

 private void createFile(String outputFileName) {
  File fileObj = new File(outputFileName);
  try {
   fileObj.createNewFile();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }

 private String getBackupFileName(String outputFileName) {
  return outputFileName.substring(0, outputFileName.lastIndexOf('.')) + "-backup"
    + outputFileName.substring(outputFileName.lastIndexOf('.'));
 }

 private void getInputFileName(String inputFileName) {
  this.inputFileName = inputFileName;
  if (!fileExists(inputFileName)) {
   System.out.println("File " + inputFileName + " does not exist.");
   getInputFileName();
  }
 }

 private void getInputFileName() {
  try {
   System.out.print("enter input file : ");
   inputFileName = br.readLine();
   if (inputFileName.equals(""))
    System.exit(0);
   if (!fileExists(inputFileName)) {
    System.out.println("File " + inputFileName + " does not exist.");
    getInputFileName();
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 boolean fileExists(String name) {
  File dummy = new File(name);
  return dummy.exists();
 }

 void backup(String fileName, String backupFileName) {
  fileBackup(fileName, backupFileName);
  System.out.println("Backup File created: " + new File(fileName).getName());
 }

 void fileBackup(String fileName, String backupName) {
  try {
   Files.copy(new File(fileName).toPath(), new File(backupName).toPath());
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 BufferedReader openIn(String name) {
  BufferedReader in = null;
  try {
   in = new BufferedReader(new FileReader(name));
  } catch (FileNotFoundException e) {
   System.out.println("error, file not found");
  }

  return in;
 }

 PrintWriter openOut(String name) {
  PrintWriter out = null;
  try {
   out = new PrintWriter(new FileWriter(name));
  } catch (IOException e) {
   System.out.println("error, file not found");
  }
  return out;
 }
}
//
//class Word {
// Word(String word) {
// }
//
// int getCount() {
// }
//
// String getWord() {
// }
//
// Boolean isWord(String word) {
// }
//
// Boolean isWordIgnoreCase(String word) {
// }
//
// Void addOne() {
// }
//
// Void print(PrintWriter out) {
// }
//
// int FindWord(Word[] list, String Word, int n) {
// }
//}

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY