Project #59663 - Java HW

Parenthesis Checker!

 

Objective:

 

Write a program that checks whether or not a string of characters that has parenthesis is well formed.  Write the method in the provided DRIVER.  Parenthesis are well formed if there is an open one ‘(‘ then there must be matching closing one ‘)’.  A stack is a good way to check.

 

  • Write in the method provided.  Return true if the string was well formed and return false if it wasn’t
  • If there are no parenthesis in the string then it is well formed
  • The method charAt may be something to look into
  • Use a stack to solve this
    • When a ‘(‘ is encountered push that one the stack
    • When a ‘)’ is encountered pop off the stack
    • If there is nothing to pop it is not well formed
    • If the stack isn’t empty at the end then it is not well formed

 

Example Dialog:

 

Test number 0 is well formed!

Test number 1 is well formed!

Test number 2 is well formed!

Test number 3 is wrong.  All wrong

Test number 4 is wrong.  All wrong

Test number 5 is well formed!

Test number 6 is well formed!

Finally:

Upload the .java file to the dropbox

 

 

 

DRIVER:

import java.util.*;

import java.io.*;

public class ParenthesisChecker {

 

        public static void main(String[] args) {

               // TODO Auto-generated method stub

               String[] testArray ={"(a)",

                               "((((()))))",

                               "(asdf)((ababa)(((bob))))",

                               "())",

                               "((NOPE)",

                               "This works I suppose",

                               ""};

               for(int i=0;i<testArray.length;i++)

               {

                       System.out.print("Test number "+i+" ");

                       if(parenthesisChecker(testArray[i]))

                       {

                               System.out.println("is well formed!");

                       }

                       else

                       {

                               System.out.println("is wrong.  All wrong");

                       }

               }

        }

        public static boolean parenthesisChecker(String aString)

        {

 

        }

 

 

}

Subject Computer
Due By (Pacific Time) 02/25/2015 01:00 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy