Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to sort the alphabetic tokens on ascending order with their number of occurrence, Valid Social Security Numbers , Valid Times and total, and

I need to sort the alphabetic tokens on ascending order with their number of occurrence,Valid Social Security Numbers, Valid Times and total, and Total time from input file (Data5.txt)

---------------------------------------------------------------------------------------------------------

Data5.txt

CS 1302 A 1 / 1 / 2019 Smith

An Exception can be anything which interrupts the normal flow of the program. When an exception occurs program processing gets terminated and doesn't continue further In such cases we get a system generated error message The good thing about exceptions is that they can be handled

Test1 89.5 Test2 100 Test3 55.75 Final 100.50.759 Quiz 25.

When are we going to have a test? Are the PPT slides helpful?

You have done a good job!!!

RegularExpressions

Often, you need to write code time=1ms to validate user input time=12ms ssn23-345-8765 time=123ms ssn23-ABC-8765 time=12Xms ssn987-65-4321 time=321ms ssn123-45-6789 ssn34-455-98761 time=1000ms ABCssn345-55-4321xyz Abctime=1ams 1234

-----------------------------------------------------------------------------------------------------------image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

-----------------------------------------------------------------------------------------------------------

Below code is similar but not showing the ascending order with their number of occurrence, Valid Social Security Numbers, Valid Times and total, and Total time.

ProccessTokens.java

import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.nio.file.Files; import java.util.ArrayList; import java.util.Scanner;

public class ProcessTokens { private ArrayList alphaTokens; private ArrayList intTokens; private ArrayList doubleTokens; private ArrayList otherTokens; private ArrayList allTokens; private int nonEmptyLines; private int otherchars; private int digits; private int letters; private String longestAlphaToken; private double largestNumeric ; private String inFilename, outFilename; public ProcessTokens(String inFname, String outFname) { this.inFilename = inFname; this.outFilename = outFname; allTokens = new ArrayList(); alphaTokens = new ArrayList(); intTokens = new ArrayList(); doubleTokens = new ArrayList(); otherTokens = new ArrayList(); longestAlphaToken=""; } public void parse() throws IOException { Scanner fileScanner = new Scanner(new File(inFilename)); while(fileScanner.hasNextLine()) { String line = fileScanner.nextLine(); //if(line.trim().equals("")) //continue; nonEmptyLines++; Scanner lineScanner = new Scanner(line); String token; while(lineScanner.hasNext()) { token = lineScanner.next(); allTokens.add(token); if(token.matches("[a-zA-z]+")) // letters only { alphaTokens.add(token); if(token.length() > longestAlphaToken.length()) longestAlphaToken = token; letters += token.length(); } else if(token.matches("[0-9]+")) //int token { intTokens.add(token); digits += token.length(); Integer num = Integer.parseInt(token); if(num > largestNumeric) largestNumeric = num; } else if(token.matches("[0-9]+\\.[0-9]+")) { Double num = Double.parseDouble(token); doubleTokens.add(token); digits += token.length() - 1; //count all but the decimal point otherchars++; //for the decimal point if(num > largestNumeric) largestNumeric = num; } else { // not a double value otherTokens.add(token); char ch; for(int i = 0; i

-----------------------------------------------------------------------------------------------------------

ProcessTokensTester.java

import java.io.IOException;

public class ProcessTokensTester {

public static void main(String[] args) {

if(args.length != 2)

{

System.out.println("Need 2 arguments - inputfile and outputfile");

System.exit(1);

}

ProcessTokens counter = new ProcessTokens(args[0], args[1]);

try {

counter.parse();

counter.printStats();

} catch (IOException e) {

System.out.println(e.getMessage());

}

}

}

Sample output 1. Sorted alphabetic tokens with their frequencies 2 An 3 Are 4 CS 5 Exception 6 Fares 7 Final 8 In 9 Often 10 PPT 11 Quiz 12 RegularExpressions1 13 The 14 When 15 You 16 a 17 about an 19 and 20 anything are 22 be 23 can 24 cases 25 code 26 continue 27 done 28 error 29 exception 30 exceptions 31 flow 32 further 33 generated 34 get 35 gets 36 going 37 good 38 handled 39 have 40 helpful 41 input 42 interrupts 43 1S 44 message 45 need 46 normal 47 occurs 48 of 49 processing 50 program 51 slides 52 such 53 system 54 terminated 55 test 56 that 57 the 58 they 59 thing 60 to 61 user 62 validate 63 we 64 which 65 write 66 you 4 II.2. Integer tokens 1302 18. 4 2019 100 1234. 6 II.3. Valid Social Security Numbers- 987-65-4321 123-45-6789 345-55-4321- II.4. Valid Times and total 4 12 123 321 1000 2 4 Total Time is:1457 Sample output 1. Sorted alphabetic tokens with their frequencies 2 An 3 Are 4 CS 5 Exception 6 Fares 7 Final 8 In 9 Often 10 PPT 11 Quiz 12 RegularExpressions1 13 The 14 When 15 You 16 a 17 about an 19 and 20 anything are 22 be 23 can 24 cases 25 code 26 continue 27 done 28 error 29 exception 30 exceptions 31 flow 32 further 33 generated 34 get 35 gets 36 going 37 good 38 handled 39 have 40 helpful 41 input 42 interrupts 43 1S 44 message 45 need 46 normal 47 occurs 48 of 49 processing 50 program 51 slides 52 such 53 system 54 terminated 55 test 56 that 57 the 58 they 59 thing 60 to 61 user 62 validate 63 we 64 which 65 write 66 you 4 II.2. Integer tokens 1302 18. 4 2019 100 1234. 6 II.3. Valid Social Security Numbers- 987-65-4321 123-45-6789 345-55-4321- II.4. Valid Times and total 4 12 123 321 1000 2 4 Total Time is:1457

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions