Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your task is to complete the provided Java source code ( Source file ) by followthe requirements outlined below. You'll be given five different input
Your task is to complete the provided Java source code Source file by followthe requirements outlined below. You'll be given five different input files enclosed within along with their corresponding output files enclosed within and given reference Lexemes in Regular Expression data which you need scan. Your goal is to fix the broken program to produce the expected output for each given input. Note: you must make different input txt and different output txt file for my given text. Please do not use other scanner except given scanner in the code
Test with Input Files:
Utilize the provided input files to test the modified code. Ensure that the program produces the expected output for each input scenario.
Compare with Output Files:
Compare the output generated by your program with the provided output files enclosed within Confirm that the program's output matches the expected output for all input cases.
Iterate if Necessary:
If any discrepancies are found between the program's output and the expected output, revisit and refine the code accordingly. Repeat testing until the program consistently produces the correct output for all input files.
Source file Code:
import java.ioFile;
import java.ioFileNotFoundException;
import java.util.Scanner;
Students Add your import declarations here
public class A
Students Add your constants here
public static void mainString args
try
Do NOT make any changes to the following TWO lines
File file new Fileargs;
Scanner sc new Scannerfile; Do not make any other Scanners
NOTE
For this assignment, you are NOT allowed to use any member methods of
class java.util.Scanner except hasNextLine and nextLine.
For example, you CANNOT use any of hasNextInt, nextInt, hasNextFloat, nextFloat,
hasNextDouble and nextDouble for this assignment.
Students Your code and methods calls go here
scclose;
catch FileNotFoundException e
System.out.printlnERROR cannot open itxt
;
Students Add your method declarations here
Reference file:
Token ID Token Name Lexemes in Regular Expression
FLOATDCL f
INTDCL i
PRINT p
ID abcdeghjklmnoqrstuvwxyz
ASSIGN
PLUS
MINUS
INUM
FNUM
Input:
f b i a a b a p b
Input:
f b f a a b a p b p a
Input:
f
b
i
a a
b
a
p
b
Input:
fbiaapabapb
Input:
f b i a a b a p b
Output:
Next token is: Next lexeme is f
Next token is: Next lexeme is b
Next token is: Next lexeme is i
Next token is: Next lexeme is a
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is b
Next token is: Next lexeme is
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is p
Next token is: Next lexeme is b
Output:
Next token is: Next lexeme is f
Next token is: Next lexeme is b
Next token is: Next lexeme is f
Next token is: Next lexeme is a
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is b
Next token is: Next lexeme is
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is p
Next token is: Next lexeme is b
Next token is: Next lexeme is p
Next token is: Next lexeme is a
Output::
Next token is: Next lexeme is f
Next token is: Next lexeme is b
Next token is: Next lexeme is i
Next token is: Next lexeme is a
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is b
Next token is: Next lexeme is
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next token is: Next lexeme is p
Next token is: Next lexeme is b
Output:
Next token is: Next lexeme is f
Next token is: Next lexeme is b
Next token is: Next lexeme is i
Next token is: Next lexeme is a
Next token is: Next lexeme is a
Next token is: Next lexeme is
Next token is: Next lexeme is
Next t
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started