Starting from:
$30

$24

Programming Assignment 1 Solution

In this PA, you need to implement a Java project in Eclipse to check whether an input string has a balanced number of “(“s and “)”s, based on the slides of 9/11. Here are the interfaces you need to implement:

interface IStringToBeHandled {

void get_Input_String(); //get input string to make sure it has only “(“ and “)” character. If not, report an error. Otherwise, call the object of type ICheckBalancedString to check whether the input string has a balanced “(“s and “)”s. So, make sure the setter method is called before this method is called

void set_CheckBalancedString(ICheckBalancedString check); // set a check object. This method should be called before get_Input_String() is called.





String print_Input_String(); /print the input String in the console

}





interface ICheckBalancedString{

void setStringTobeChecked(String s); // set the string to be checked.

boolean checkBalancedParenthesis(); // check whether the string has a balanced number of “(“s and “)”s. This method should be called after setStringTobeChecked is called. Return true if the string has a balanced number of “(“s and “)”s.

void set_Stack(IStack stack); // set a stack object. This method should be called before CheckBalancedParethesis() is called





String get_Checked_String(); //return the checked string

}

interface IStack {

void push(char c); // push a char c onto a stack

char pop(); // pop a stack from a stack

int size(); // return the number of elements on the stack

}





For interface IStringToBeHandled, you need to implement a class that takes the input string from a console and the class is called StringToBeHandled. Class CheckBalancedString implements interface ICheckBalancedString. Also, you need to use an ArrayList to implement IStack interface. You cannot use the Java Stack class in the implementation for IStack.

Once you are done, you should have the following the Application class to run.

class Application {

public static void main(){

IStringToBeHandled handler = new StringToBeHandled();

ICheckBalancedString checker = new CheckBalancedString();

IStack s = new Stack();

// connect the objects together via using the setter method appropriately, check the input string, and print out the result in the console;

……………
}





Requirements for PA1,

You must use the Eclipse IDE to create a Java project.
You must follow the instruction to submit your Java project (http://www.cs.wmich.edu/~wwshen/cs1120_Fall2012/documents/HowtoSubmitPAinEclipse.pdf).








More products