Answer the following Java programming question about using stacks to solve a problem. Balance...
Question:
Answer the following Java programming question about using stacks to solve a problem.
Balance Expressions (applying a stack to solve a problem)
Consider an expression that contains grouping symbols. The grouping symbols are parentheses, { }, and [ ]. Expressions are considered to be balanced if their grouping symbols follow the following rules:
• Each symbol must be followed by a right symbol with some data in between (you can't have an empty pair like [ ].)
• If pairs are nested, one pair must be completely nested within another.
Here is an example of a balanced expression:
abc{de(fg){ijk}{l{m[n]}}o[p]}qr
Here is an example where the grouping symbols are not balanced:
abc{(def}}{ghij{kl}m]
Write a method with signature boolean isBalanced(String s) that returns true if the grouping symbols within the string are properly balanced. Use a stack in your solution. You may assume that each symbol is just one character and that there are no spaces, as in the examples above.
Stack:
The stack is a very known data structure. It is work on LIFO (last in first out)and FILO (first in last out)principle. In any programme, the stack will do operations with push and pop means to enter an element to stack and pop means removes the recent element.
Answer and Explanation: 1
Become a Study.com member to unlock this answer! Create your account
View this answer// Code starts here
public class CheckExpression
{
static class stack
{
int top=-1;
char items[] = new char[100];
void push(char x)
{
if (top == 99)
{
System...
See full answer below.
Ask a question
Our experts can answer your tough homework and study questions.
Ask a question Ask a questionSearch Answers
Learn more about this topic:
from
Chapter 6 / Lesson 4A method in a Java program provides a set of instructions to be executed. Explore the different components of a method, such as its parameters and ability to return a value, and learn how to create a method.
Related to this Question
- Write a java program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions {25 + (3 - 6)
- Implement a java program that will use a stack structure to check for correct placement of parentheses in an algebraic expression. Allow the use of ()[] {} characters as grouping symbols. Make sure
- In java: Implement a program that will use a stack structure to check for correct placement of parentheses in an algebraic expression. Allow the use of () [] {} characters as grouping symbols. Make su
- Write a program in JAVA that evaluates infix expressions of unsigned integers using two stacks. The program should consist of three classes. The main class should create a GUI that allows the user inp
- Java Question: Show the contents of two initially empty stacks after each of the following statements execute. Assume x, y, m, and q are objects. If you are writing the contents of your stack horizont
- Write a program in Java for the following: Given subsets A and B of a set with n elements, use bit strings to find A, A union B, A intersection B, A - B, and A xor B.
- Write a Java program that does the following: Initialize a counter to 0. Get input for the number of calculations to perform. (Calculations are to be performed in a looping structure.) Add 2 to the co
- Write a Java Program that searches a sorted list of n items by dividing it into three sublists of almost n/3 items. This algorithm finds the sublist that might contain the given item and divides it in
- How to programme in java to multiply two integers without using multiplication?
- Write a Java method duplicateStack that returns a new stack containing the same elements and in the same order as the stack specified in the parameter. The method should create a new stack and fill it
- Write a java code for 8 times multiplication table.
- Explain how to write pseudocode for A,B,C and the actual code for B,C. Consider the Homework Point Sum problem below. The problem states: Get all homework scores for one student, calculate and displ
- Find and solve the error in Java.
- Write a complete Java program to compute the total living cost for a semester at college. * The main method calls three methods to do this: 1. getTotalWeeks: requests from the user the total num
- Write an algorithm to solve the following problem and specify its runtime complexity using the most relevant terms. Given a nonnegative integer, what is the smallest value, k, such that n, 2n, 3n, ...
- Use Java programming language for each of the following. Write a complete program called Averager that declares and initializes an array of 5 doubles, populates this array with input from the user at
- Write a complete Java program to compute the total living cost for a semester at college. The main method calls three methods to do this: 1. getTotalWeeks: Requests from the user the total number of w
- At Google, a group of programmers are trying to solve a complicated problem that has 148 function points. They are planning to use Java for that problem. Arnold has been assigned to manage the project
- Is there an algorithm to solve every problem in computer science? Explain.
- JAVA HOMEWORK 1. The choice of algorithm is important, however, because it affects ( ? ) of the program. Select one: a. only the run time b. only the memory use c. the run time and the memory use d. n
- You are to write a program name calc.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits).
- write a program name calc.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) x (repre
- **In Java** Write a class Polynomial that stores a polynomial such as p(x) = 5x10 + 9x7 ? x ? 10 as a linked list of terms. A term contains the coefficient and the power of x. For example, you would s
- (Java) Suppose that we have numbers between 1 and 1000 in a binary search tree and want to search for the number 363. Which of the following sequences could not be the sequences of nodes examined? a.
- First, write out the pseudocode and then create a program to help you by accomplishing the following tasks (using NetBeans). Write TWO Java codes: 1 pseudocode and then 1 actual code that is derived f
- Write a program that uses a stack to reverse its inputs. Your stack must be generic and you must demonstrate that it accepts both String and Integer types. Your stack must implement the following me
- Use the operations push, pop, top, and isEmpty to construct pseudocode operations that do each of the following: a) Set num to the second element from the top of the stack, leaving the stack without i
- Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters number of dimes number of nickels number of pennies Include two constructors
- Create java program that outputs the multiplication table from 1 to 9 "for" loops. Your program must do the multiplication for each number in the table.
- MulticastSocket() MUST be used to solve this java problem for adding numbers sent by multiple clients. Question: Write a complete Java program by creating Multicast client-server classes(only by usi
- Write one Java statement to display the string "The average is xxx" to the console, where the xxx displays the value from the double variable sum divided by 3. Make sure the value is displayed with 3
- Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two cons
- Create a program that uses a stack to reverse its inputs. Your stack must be generic and you must demonstrate that it accepts both String and Integer types. Your stack must implement the following m
- The selection of an algorithm to solve a problem is greatly influenced by the way the input __________________ for that problem are organized. a) words. b) data. c) solutions. d) pseudocode.
- Write a Java program that performs the following mathematical tasks in the following order, using double values for all input and calculations and Math.PI when the value of pi is required. Ask the use
- The problem is in Java. For this problem we will simulate a bank. Our bank will track the balances in twenty different accounts. When the program begins, each of the accounts contains $1000. The progr
- Write JAVA code to perform the following functions in sequence (1) Prompt the user to enter five numbers, being five people's weights. (2) Store the numbers in an array of doubles. (3) Output the a
- Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem and then provide high-level pseudocode for the algorithm. Explain why this algorithm can benef
- Suppose the following BankAccount class has been created: public class BankAccount String name; double balance; public void deposit(double amount) balance = balance + amount; public void wi
- Imagine you have a stack of integers, S, and a queue of integers, Q. Draw a picture of S and Q after the following operations in the C language: 1. pushStack (S, 3) 2. pushStack (S, 12) 3. enqueue (Q,
- Covert the following pseudocode to Java code. Be sure to declare the appropriate variables: Store 172.5 in the force variable. Store 27.5 in the area variable Divide area by force and store the res
- Suppose the following operations are performed on a stack containing integers: Create an empty stack. Push 1 Push 2. Push 3. Pop Push 4 Push 5 Pop a.) Draw a sketch of of a linked-list based stack aft
- (Java Programming Question) Synopsis: Create a program that reads solar energy production data for the last week from a file, gets input for the cost of the system, and outputs production, savings, da
- How do you use arrays in java programming creation?
- Indicate whether a stack would be a suitable data structure for each of the following applications: a. A program to evaluate arithmetic expressions according to the specific order of operators. b. A b
- Using the Java Development Kit and jGrasp, develop a program in response to the following prompt. Write a program that prompts the user to input a decimal number and outputs the number rounded to the
- For this assignment, write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (these are two separate prompts for input
- Programming method for solving a problem by solving a smaller version of the same problem repeatedly a. Repetition b. Problem Solving c. Debugging d. Recursion
- Give the base case, reduced problem, and general solution of the recursive algorithm for outputting an array of characters, c, given the starting and ending indices.
- Give the base case, reduced problem, and general solution of the recursive algorithm for the following. Outputting an array of characters, c, given the starting and ending indices.
- Assume you have a stack called S with the following contents, and trace the following operations: 4 (top) 8 2 3 1 System.out.println(S.peek()); //a) What is printed? S.pop(); System.out.println
- Assume you have a stack called S with the following contents, and trace the following operations: 4 (top) 8 2 1 System.out.printlnS.peek a) What is printed? S.pop System.out.println S.peek (b)
- 1. Choose a problem that lends to an implementation that uses dynamic programming. Clearly state the problem and then provide high-level pseudocode for the algorithm. Explain why this algorithm can be
- Choose a problem that lends to an implementation that uses dynamic programming. i. Clearly state the problem and then provide high-level pseudocode for the algorithm. ii. Explain why this algorithm ca
- Create a Java program by doing the following: 1. Write a class named Card. It can be used to represent a single card from a deck of cards. The class should be able to store a card's suit and face valu
- Write a Java program that reads the subtotal and the gratuity rate from a user for a service. Your program should compute the gratuity and the total and then output the subtotal entered, the gratuity
- (java question) What is wrong with this code example? public class Question { public static int main(String[] args) { } }
- Ackermann's function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Using Java, write a method ackermann(m, n), which solves Ackermann's functio
- Complete Project 2 at the end of Chapter 5 in our textbook: Write a Java program that uses a stack to test whether an input string is a palindrome. Exercise 11 defines "palindrome" and asks you to des
- Write a complete Java program called CharCounter that gets two Strings called word and character from the user at the command line and then counts the occurrences of character in word. Check that char
- Write a Java class that implements the concept of Coins, assuming the following attributes (variables): number of quarters, number of dimes, number of nickels, and number of pennies. Include two const
- Java: You will use parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin' Jive coffee shop or it should
- Write a Java program that takes two ints as input from the keyboard that represent the number of hits and the number of at-bats for a batter. Then calculate the batter's hitting percentage, and check
- When considering the push() and pop() operations for a stack, how could a compiler program use a stack to implement delimiter matching. For example, matching delimiter strings could be: "{", "}", "(",
- Write the pseudocode for these two problems: 1. Kevin wants a program to total the votes each district in his state cast for the independent delegate running in a given election. There are 10 district
- 1. Create, using NetBeans, a complete Java program called GameControl according to the following guidelines. This program must use a do loop and a switch statement to provide the following interac on
- Write a C program that evaluates the equations provided below. The program must prompt the user for inputs to the equations and evaluate them based on the inputs. All variables on the right hand sides
- Jave Write a class encapsulating the concept of coins, assuming that coins have the following attributes: a number of quarters, a number of dimes, a numbers of nickels, and a number of pennies. Inclu
- Write a Java application that accomplishes the following tasks: Prompts users to enter the number of students and their names in this course. Displays the total number of students in the class and the
- Write a JAVA program to determine the coefficients of expanded form of (aX+bY+c)^n. A sample session: What are the coefficients of X and Y? // values of a & b 2 -1 //provided at run-time What are the
- Imagine you have a stack of integers, S, and a queue of integers, Q. Draw a picture of S and Q after the following operations: 1. pushStack(S, 12) 2. enqueue(Q, 8) 3. pushStack (S, 14) 4. pushSta
- Objective: This assignment will allow you to practice with for input/output and solve a problem using primitive variables. Overview: You are going to write a program to calculate roots of quadratic eq
- Write a complete MIPS-32 assembly language program including data declarations that corresponds to the following C code fragment. Make use of the fact that multiplication and division by powers of 2 c
- Write java codes to define three classes with the following functions and relationship among them: The class Thought contains a method message which implements to print out the message "I'm a teacher.
- Write a program that uses a stack to reverse its inputs. Your stack must be generic and you must demonstrate that it accepts both String and Integer types. Your stack must implement the following meth
- Pick one of the following programming languages: C, C++, Java, or Python. Implement the following three recursive functions. 1. The factorial function accepts a nonnegative integer as the argument n a
- (Java) Add each element in origList with the corresponding value in offsetAmount. Print each sum followed by a space. Use two print statements. Ex: If origList = 40, 50, 60, 70 and offsetAmount = 5,
- Analyze the recursive version of the Fibonacci series. Define the problem, write the algorithm and give the complexity analysis.
- Suppose that instead of doubling the size of an array-based stack when it becomes full, you increase the size of the array by some positive integer k . Implement and demonstrate such a stack, which al
- Implement a Stack computer in Javascript. This is a simple computer that keeps a stack, when a number is entered it goes onto the top of the stack. When an operation is entered, the previous 2 numbers
- Write a program in Java which would ask for the clerk to enter the total amount of the customer's order. The program will then calculate a seven percent (7%) sales tax. Commission is computed based o
- JAVA PROGRAMMING The below program uses an array salaryBase to hold the cutoffs for each salary level and a parallel array taxBase that has the corresponding tax rate. 1-Run the program and enter annu
- ****Java**** For this assignment, refer to the StaffMember class hierarchy Diagram, write the main program to perform the following tasks. (Staff, StaffMemeber, Executive, Hourly and Volunteer class f
- Write a java program that finds the max binary tree height.
- Write a C program that reads in two sets of numbers A and B and calculates and print their union (A \/ B) and intersection (A / B). A \/ B is the set of elements that appear in either A or B, and that
- Suppose the following operations are performed on a stack containing integers. 1. Create an empty stack. 2. Push 1 3. Push 2 4. Push 3 5. Pop 6. Push 4 7. Push 5 8. Pop
- Write a Java program that concatenates two linked list objects of characters. The ListConcatenate slass should include a method named concatenate that takes references to both lists objects as argumen
- In Java, write a program that finds the max binary tree height.
- Write pseudocode to represent the logic of a program that allows the user to enter values for a salesperson's base salary, total sales, and commission rate. The program computes and outputs the salesp
- How to write a pseudo code for the given problem?
- Use Java for this assignment. Write a complete program that draws a scatterplot by reading in points of data from a file and displaying them. The input data file consists of a pair of integers represe
- Write the code to implement the expression A = (B - C)*D on 3-, 2-, 1-, and 0-address machines. Do not rearrange the expression. In accordance with programming language practice, computing the express
- Java : Write a program that reads the amount of a monthly mortgage payment and the amount still owed "the outstanding balance" and then displays the amount of the payment that goes to interest and th
- Java (Evaluate expression) Modify Listing 20.9 EvaluateExpression.java to add operators ^ for exponent and % for modulus. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest pre
- Algorithms problem : a) Write pseudocode for a Boolean search function that performs a ternary search for an integer x in an integer array A (sorted in increasing order). The function returns true if
- Java Write a class encapsulating the concept of student grades on a test, assuming student grades are composed of a list of integers between 0 and 100. Write the following methods: --A constructor
- Write a pseudocode algorithm that uses the for-loop to display all the values in the following array: Constant Integer SIZE = 10 Declare Integer valuesSIZE = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Count the number of + operations done by this algorithm. Consider the following algorithm. x arrow 1 for i in1, 2, 3 do for j in1, 2, 3, 4 do x arrow x + x for k i
- Parallel Arrays (Java): You will use parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin' Jive coffee
- Create, using NetBeans, a complete Java program called CalcAvg according to the following guidelines. (This program requires the use of arrays.) The program prompts the user for five to ten numbers al