Answered step by step
Verified Expert Solution
Link Copied!

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 5 different input txt and 5 different output txt file for my given text. Please do not use other scanner except given scanner in the code
1. 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.
2. 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.
3. 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.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
// Students -- Add your import declarations here
public class A1{
// Students -- Add your constants here
public static void main(String[] args){
try {
// Do NOT make any changes to the following TWO lines
File file = new File(args[0]);
Scanner sc = new Scanner(file); //*** 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
sc.close();
} catch (FileNotFoundException e){
System.out.println("ERROR - cannot open i?.txt
");
}
}
// Students -- Add your method declarations here
}
Reference file:
Token ID- Token Name- Lexemes in Regular Expression
0- FLOATDCL -"f"
1- INTDCL -"i"
2- PRINT -"p"
3- ID -"a+b+c+d+e+g+h+j+k+l+m+n+o+q+r+s+t+u+v+w+x+y+z"
4- ASSIGN-"="
5- PLUS-"+"
6- MINUS-"-"
7- INUM-"(0+1+2+3+4+5+6+7+8+9)+"
8- FNUM-"(0+1+2+3+4+5+6+7+8+9)+.(0+1+2+3+4+5+6+7+8+9)+"
Input1:
f b i a a =5 b = a +3.2 p b
Input2:
f b f a a =45.123 b = a +43.21 p b p a
Input3:
f
b
i
a a =5
b =
a +
3.2 p
b
Input4:
fbiaa=54pab=43.21+apb
Input5:
f b i a a =5 b = a +3..2 p b
Output1:
Next token is: 0, Next lexeme is f
Next token is: 3, Next lexeme is b
Next token is: 1, Next lexeme is i
Next token is: 3, Next lexeme is a
Next token is: 3, Next lexeme is a
Next token is: 4, Next lexeme is =
Next token is: 7, Next lexeme is 5
Next token is: 3, Next lexeme is b
Next token is: 4, Next lexeme is =
Next token is: 3, Next lexeme is a
Next token is: 5, Next lexeme is +
Next token is: 8, Next lexeme is 3.2
Next token is: 2, Next lexeme is p
Next token is: 3, Next lexeme is b
Output2:
Next token is: 0, Next lexeme is f
Next token is: 3, Next lexeme is b
Next token is: 0, Next lexeme is f
Next token is: 3, Next lexeme is a
Next token is: 3, Next lexeme is a
Next token is: 4, Next lexeme is =
Next token is: 8, Next lexeme is 45.123
Next token is: 3, Next lexeme is b
Next token is: 4, Next lexeme is =
Next token is: 3, Next lexeme is a
Next token is: 5, Next lexeme is +
Next token is: 8, Next lexeme is 43.21
Next token is: 2, Next lexeme is p
Next token is: 3, Next lexeme is b
Next token is: 2, Next lexeme is p
Next token is: 3, Next lexeme is a
Output:3:
Next token is: 0, Next lexeme is f
Next token is: 3, Next lexeme is b
Next token is: 1, Next lexeme is i
Next token is: 3, Next lexeme is a
Next token is: 3, Next lexeme is a
Next token is: 4, Next lexeme is =
Next token is: 7, Next lexeme is 5
Next token is: 3, Next lexeme is b
Next token is: 4, Next lexeme is =
Next token is: 3, Next lexeme is a
Next token is: 5, Next lexeme is +
Next token is: 8, Next lexeme is 3.2
Next token is: 2, Next lexeme is p
Next token is: 3, Next lexeme is b
Output4:
Next token is: 0, Next lexeme is f
Next token is: 3, Next lexeme is b
Next token is: 1, Next lexeme is i
Next token is: 3, Next lexeme is a
Next token is: 3, Next lexeme is a
Next token is: 4, Next lexeme is =
Next token is: 7, Next lexeme is 54
Next t

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

More Books

Students also viewed these Databases questions

Question

Comment on the pH value of lattice solutions of salts.

Answered: 1 week ago

Question

5. Identify and describe nine social and cultural identities.

Answered: 1 week ago

Question

2. Define identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago