Java Code,

follow instructions

Java Code, follow instructions
LAB4 PART 1 – REQUIREMENT DATA TYPE CLASS: Using the class FABook provided from eCampus then add to your project with the name as FA2022_Book_yourLastName for the node to work with the data structure DRIVER CLASS For this lab, the data structure is GenericStack or GenericQueue. The data type of nodes is FA2022_Book_yourLastName Provide the pseudo_code and the code of an application to implement GenericStack or GenericQueue that we learned from Chapter 24. The project must create at least 3 user-defined functions beside the function main(). First, the application show Menu to allow users to select the type of data structure to work on. After finishing with one data structure type, redisplay the menu to allow users to select other until users select EXIT to terminate the program FA2022_FA2022_DemoGenericStackAndGenericQueue_Smith.java MENU OF DATA STRUCTURE – JAMES SMITH ———————————————————— 1. Generic Stack 2. Generic Queue 0. Exit Type 1 or 2 to select a Data Structure type or 0 to exit. For each selected data structure type, do the following: Notes: use the following function to pause the output before each action static void pause(Scanner keyboard) { System.out.println(“Press any key to continue…”); keyboard.nextLine(); } INSERT 3 BOOKS TO THE STRUCTURE (either GenericStack OR GenericQueue) Display the message to ask and read the information of a Book from the keyboard. Create the object of Book then insert to the data structure. After finishing, display all the book in the following format: FA2022_DemoGenericStackAndGenericQueue_Smith.java THREE BOOKS ARE INSERTED – JAMES SMITH —————————————————— Generic Stack: ISBN: 978-1-337-10208-7 Book Title: C++ Programming – From Problem Analysis to Program Design Writer D.S Malik Publisher: Cengage , ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage , ISBN: 978-0-136-52015-3 Book Title: Introduction to Java Programming and Data Structures Writer Daniel Liang Publisher: Pearson OR FA2022_DemoGenericStackAndGenericQueue_Smith.java THREE BOOKS ARE INSERTED – JAMES SMITH —————————————————— Generic Queue: ISBN: 978-1-337-10208-7 Book Title: C++ Programming – From Problem Analysis to Program Design Writer D.S Malik Publisher: Cengage , ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage , ISBN: 978-0-136-52015-3 Book Title: Introduction to Java Programming and Data Structures Writer Daniel Liang Publisher: Pearson DELETE ONE BOOK Remove a book at the top of the stack OR remove a book at the rear or the queue in the following format: If the stack (or queue) is empty, display the following: FA2022_DemoGenericStackAndGenericQueue_Smith.java DELETE ONE BOOK – JAMES SMITH ————————————————————- The stack is empty OR FA2022_DemoGenericStackAndGenericQueue_Smith.java DELETE ONE BOOK FROM QUEUE– JAMES SMITH ————————————————————- The queue is empty If the stack or queue is NOT empty, display the book: FA2022_DemoGenericStackAndGenericQueue_Smith.java DELETE ONE BOOK – JAMES SMITH —————————————————– ISBN: 978-0-136-52015-3 Book Title: Introduction to Java Programming and Data Structures Writer Daniel Liang Publisher: Pearson OR FA2022_DemoGenericStackAndGenericQueue_Smith.java DELETE ONE BOOK – JAMES SMITH ———————————————————- ISBN: 978-1-337-10208-7 Book Title: C++ Programming – From Problem Analysis to Program Design Writer D.S Malik Publisher: Cengage DISPLAY THE BOOK AT THE TOP (Stack) / AT THE FRONT (Queue) If the stack or queue is empty, display the following: FA2022_DemoGenericStackAndGenericQueue_Smith.java BOOK AT TOP OF STACK – JAMES SMITH ——————————————- The stack is empty OR FA2022_DemoGenericStackAndGenericQueue_Smith.java BOOK IN FRONT OF QUEUE – JAMES SMITH ——————————————————- The queue is empty If the stack or queue is NOT empty, display the book: FA2022_DemoGenericStackAndGenericQueue_Smith.java BOOK AT TOP OF STACK – JAMES SMITH —————————————————- ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage OR FA2022_DemoGenericStackAndGenericQueue_Smith.java BOOK IN FRONT OF QUEUE – JAMES SMITH ——————————————- ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage SHOW ALL BOOKS Display all the BOOKS currently stored in the data structure: If the stack or queue is empty, display the following: FA2022_FA2022_BookWithGenericStackAndGenericQueue_Smith.java SHOW ALL BOOKS IN STACK – JAMES SMITH ——————————————- The stack is empty OR FA2022_FA2022_BookWithGenericStackAndGenericQueue_Smith.java SHOW ALL BOOKS IN QUEUE – JAMES SMITH ——————————————- The queue is empty If the stack or queue is NOT empty, display the book: FA2022_FA2022_BookWithGenericStackAndGenericQueue_Smith.java SHOW ALL BOOKS IN STACK – JAMES SMITH ——————————————- stack: ISBN: 978-1-337-10208-7 Book Title: C++ Programming – From Problem Analysis to Program Design Writer D.S Malik Publisher: Cengage , ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage OR FA2022_FA2022_BookWithGenericStackAndGenericQueue_Smith.java SHOW ALL BOOKS IN QUEUE – JAMES SMITH ——————————————- Queue: ISBN: 978-1-111-82595-9 Book Title: Just Enough Programming Logic and Design Writer Joyce Publisher: Cengage , ISBN: 978-0-136-52015-3 Book Title: Introduction to Java Programming and Data Structures Writer Daniel Liang Publisher: Pearson LAB4 PART 2 – REQUIREMENT You can use the following function as a user-defined function in your Driver class that calculates the result on one operator: void processOneOperator(YOU SHOULD PASS PARAMETER LIST NEEDED FOR YOUR FUNCTION) { char op = operatorStack.pop(); int number2 = stackForOperand.pop(); int number1 = stackForOperand.pop(); int result; switch (op) { case ‘+’: result = number1 + number2; case ‘-‘: result = number 1 – number2; case ‘*’: result = number1 * number2; case ‘/’: result = number1 / number2; } stackForOperand.push(result); } Provide the pseudo-code and the code for the application that helps users to evaluate the infixed expressions. First, display the menu to allow users to type a number 1 or 2 to select where the input comes from. FA2022_EvaluationExpresions_Smith.java MENU TO SELECT INPUT – JAMES SMITH —————————————— 1. Read one Expression from the keyboard 2. Read expressions from an input file 0. Exit CASE 1: //input from the keyboard THIS PROCESS WORKS FOR ONE EXPRESSION Create two data structures of GenericStack type: *one GenericStack to store Integer numbers (operands) *one GgenericStack to store Characters (operators includes add (+), minus(-), multiply (*), divide (/), open parenthesis “(“, and close parenthesis “)” ) 1.Display message and read one expression from the keyboard as a string 2.Split the input expression (String) into tokens: tokens of numbers and tokens of operators (read the topic How to split a String into tokens by using StringTokenizer in HOW TO DO LAB) Expression = result PHASE1: Read each token of the expression from left to right and insert it to the above created stacks either Operand Stack (Integer) and Operator Stack (Character) by applying the following rules: –if the token is a NUMBER, push it to the stack for Operands (Integer). Read the topic “How to recognize a String is a numeric string in HOW TO DO LAB. –if the token is an OPEN PARENTHESIS ”(“, push it to the stack for Operators (Character) –if the token is a CLOSE PARENTHESIS “)”, do the following: Create a loop, read each operator in the stack of operators: For each operator in the stack of operators call function processOneOperator to pop one operator and pop two numbers to calculate the result based on the operator, then push the result to the stack of numbers Continue to call the method processOneOperator until reaching “(”, then pop it off –if the token is one of 2 operators + or – , do the following: if the Operator Stack is not empty: check if the top of Operator Stack is one of 4 operators “ + – * / “, call function processOneOperator to calculate with the top operator continue to call function processOneOperator if the top of Operator Stack still has one of 4 operators “ + – * / “ push the operator + or – in –if the token is one of 2 operators * or /, do the following: if the Operator Stack is not empty: check if the top of Operator Stack is one of two operators, “ * or / ”, call function processOneOperator to calculate with the top operator push the operator * or / in PHASE 2: Empty the Operator Stack: Create a loop to call function processOneOperator until Operator Stack empty DISPLAY THE RESULT The format of the output result as below, the expression is the input string and the result is the last number that is popped from the Operand Stack. For example: input expression is (25 + 63 – 12) * 20 – (8 * 12) has the output FA2022_ExpresionEvaluationWithStack_Smith.java EXPRESSION FROM THE KEYBOARD – JAMES SMITH ——————————————– (25 + 63 – 12) * 20 – (8 * 12) = 1424 CASE 2 //input from the INPUT FILE Display the message to ask and read the name of input file. Check if file does not exist display “File not found” then loop back to display the main menu Open input file to read until finishing the last line of the file. For each line, read one line (one expression) as a string; do exact as the PROCESS WORKS FOR ONE EXPRESSION from the keyboard. The output should be: FA2022_ExpresionEvaluationWithStack_Smith.java EXPRESSION FROM THE INPUT FILE – JAMES SMITH ——————————————– 23 + 28 = 51 64 * 25 = 1600 14 + 25 – 12 = 27 36 * 14 / 42 = 12 25 + (12 + 34 * 23) = 819 (25 + 63 – 12) * 20 – (8 * 12) = 1424 HOW TO TURN IN THE LAB Pseudo-code with the output picture of Part1 and Part2 UML of class Book ABook.java GenericStack.java GenericQueue.java FA2022_FA2022_BookWithGenericStackAndGenericQueue_yourLastName.java FA2022_ExpresionEvaluationWithStack_yourLastName.java FABook.class GenericStack.class GenericQueue.class FA2022_FA2022_BookWithGenericStackAndGenericQueue_yourLastName.class FA2022_ExpresionEvaluationWithStack_yourLastName.class HOW TO GRADE THE LAB HOW TO GRADE THE LAB Score Turn in on time 3 PART1: class GenericStack, class GenericQueue, class Book FA2022_FA2022_BookWithGenericStackAndGenericQueue_yourLastName: handle menu in loop 0.25 • declare GenericStack, insert nodes, remove nodes, display top, showAll 2.5 • declare Queue, insert nodes, remove nodes, display front, showAll 2.5 compile success, do all the requirement 2 Output in correct format 1 Comments, file name at top 1 PART2 Class GenericStack Class FA2022_ExpresionEvaluationWithStack_yourLastName Declare the stack of operators – Declare the stack of operands 1 Menu handle to allow users select keyboard or file or exit 0.25 Read expression from keyboard 0.5 Open file, check exist, Read expression from the file – read all lines – close file 1 split the expression to tokens 1 At least 3 User-Defined Function 1.5 phase 1 7 phase 2 0.5 Display the result as required format 1 Compile successfully 3 comments , file name at top 1 LAB 4 SCORES 30 POINTS