SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 6 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 04 Nov 2017 My Price 10.00

A stack is a data structure where data is accessed

Please Answer correctly this question the balanced class which must complete is attached bellow. balanced file is

 

A stack is a data structure where data is accessed using the LIFO (last in first out) principle. In this problem, use a stack to check whether a string has balanced parentheses (, ) and brackets {, }, [, ], or not.

A string that has balanced parentheses and brackets will be said to be balanced. Any character that is not one of (, ), [, ], {, or } is not important when deciding if a string is balanced and can be ignored.

We will define balanced as follows. A string str is balanced

  • if str does not contain a parenthesis or bracket symbol, or
  • str consists of a balanced string surrounded by opening and closing parentheses or matching brackets. That is, str is (b), {b} or [b], where b is any balanced string, or
  • if str is the concatenation of any two balanced strings. That is, str is bc, where b and c are any balanced strings.

You will complete the provided Balanced class that has two static methods isBalanced(String) and numberOfBalancedStrings(String[]).

Your isBalanced method must use the java.util.Stack class (in a way that solves the problem) to receive any grades for this problem.

http://docs.oracle.com/javase/8/docs/api/java/util/Stack.html

 

Examples

The following strings have balanced parentheses

  • (), ()()
  • cat, c(at), (hello)(kitty)
  • if( ((x-y) < 4) || (x > 12))
  • ()(((s)))()()()()(x()((y))(x))()(ccccc(w))ssss()

The following strings do not have balances parentheses

  • ), )(a), )a(

The following strings have balanced parentheses and brackets

  • a, [], {}, [()], []{}({}),
  • for(int i=0; i<12; i+=1){x[i]+=f(1);}

The following strings do not have balanced parentheses and brackets

  • (], {), [}, [}, (], ({)}h, [(]())
  • for(int i=0; i<12; i+=1){import java.util.Stack;

    public class Balanced{
     
     
      /**
         Checks if a string is balanced or not.
         
       @param s is a non-null string
       @return true of the input <code>s</code> is balanced and false otherwise.
      **/
      public static boolean isBalanced(String s){
        return false;
      }
     
      /**
         Counts the number of balanced strings in the input array.
        
         @param in is a non-null array of strings
       @return the number of strings in the input <code>in</code> that are balanced.
      **/
      public static int numberOfBalancedStrings(String[] in){
        return -1;
      }
     
     
    }

Note: You will receive partial marks if you code only works for parentheses (and not brackets).

Answers

(5)
Status NEW Posted 04 Nov 2017 07:11 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)