Answer the question
In order to leave comments, you need to log in
Why is the StrProcess object not being created?
When I try to compile, it gives errors, please tell me what is the problem:
code Main
package lab3;
import java.util.ArrayList;
public class Main
{
public static void main(String[] args)
{
String query1 = "query1.txt";
String query2 = "query2.txt";
String query4 = "query4.txt";
String regex1 = "*69$";
String regex2 = "SPORT";
String regex4 = "*1{1}[0-9]{3}$";
StrProcess condition1 = new StrProcess(query1, regex1);
StrProcess condition2 = new StrProcess(query2, regex2);
StrProcess condition3 = new StrProcess(query4, regex4);
ArrayList<String> result1 = condition1.GetAll();
ArrayList<String> result2 = condition2.GetAll();
ArrayList<String> result3 = condition3.GetAll();
}
}
package lab3;
import java.io.File;
import java.util.regex.Pattern;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.FileNotFoundException;
public class StrProcess
{
private String filename, regex;
ArrayList<String> Str = new ArrayList<String>();
StrProcess(String filename, String regex)
{
try
{
File query = new File(filename);
Scanner reader = new Scanner(query);
while(reader.hasNextLine())
{
if(Pattern.matches(regex, reader.nextLine()))
{
Str.add(reader.nextLine());
}
}
}
catch(FileNotFoundException e)
{
System.out.println("File Not Found");
}
}
private void Sort()
{
}
public ArrayList<String> GetAll()
{
return(Str);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question