You are to develop a Java program that checks Java code fragments for balanced symbols (), [], {}. The program will ask
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
You are to develop a Java program that checks Java code fragments for balanced symbols (), [], {}. The program will ask
You will provide two JUnit classes: StackTest to test your Stack class, and a SymbolCheckerTest to test the individual functions of your program. The Stack Class You will begin by writing a Stack class that stores chars and uses a singly linked list representation. The Stack class will have a Node inner class with data that is a single char. The Stack will have one instance variable of type Node which will reference the head of the list (or top of the stack). The Stack class must have exactly the following public methods. isEmpty() which will return a boolean • push(char item) ● ● pop() top () which will return a char. a correct override of the equals method which will be true if and only if the parameter is a Stack with exactly the same contents as the calling object. clear() which will pop all items off the stack. your The pop and top methods may assume that the stack does have data (which means that program will have to check for an empty stack before calling them).
The SymbolChecker Class SymbolChecker variables: ● will manage the process of checking a file. It will have the following instance You must have at least the following methods: ● a default constructor which will create the Stack object a setup method which will accept a String parameter and open the corresponding file. a runChecker method that will manage the checking process (reading through the file and calling other methods) a cleanup method that closes the Scanner. additional methods that handle pieces of the checking process. This is your opportunity to think about some program design: what are some individual tasks that could be placed in methods? ● A Stack A Scanner that will be attached to the file being checked An int that will be used to keep track of the current line number
a main method that will create a SymbolChecker object and call the setup, runChecker, and cleanup methods in turn. Sample files have been provided for you that demonstrate each of the cases. We are putting the code we are checking in .txt files for convenience (and reduced confusion). Remember that your program must work correctly on the provided sample data to get a B or better (as well as meeting other requirements for an A or B). JUnit Testing: Create a JUnit test class StackTest that thoroughly tests each of your Stack methods. Also create a SymbolCheckTest class that tests the methods that handle pieces of the checking process.