How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask LogicPro Your Own Question

LogicPro
LogicPro, Engineer
Category: Homework
Satisfied Customers: 9516
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
29751445
Type Your Homework Question Here...
LogicPro is online now
A new question is answered every 9 seconds

COSC 2006 –Data Structures I Assignment #4 Due: Friday, Nov

Resolved Question:

COSC 2006 –Data Structures I
Assignment #4 Due: Friday, Nov 22th, 2013
ADT Stack
 To gain understanding of how an implementation of an ADT is used by an application program.
 To learn how expressions can be evaluated at run-time.
 To become familiar with how infix expressions can be converted to postfix expressions.
Introduction
Your task is to design a program to implement a calculator. The calculator will take an infix expression convert it to a postfix expression and then evaluate it. In this draft, the infix expression will consist of operands that are single digits and the operators {+, -, *, /}. An example of such an expression is 2+3*4/6. This will translate to 234*6/+ and will then be evaluated as 4.0. To get a grade of 100 in this draft, your program must evaluate infix expressions containing parentheses such as (2+4)*(8-2)/(11-9).
Your project can be divided into two parts:
 A Converter class that will convert the input string to postfix.
 A Calculator class that will evaluate the postfix expression.
Normally we would use a stack of char to do the conversion and a stack of double to do the evaluation. Java, however, allows us to use a stack of Object for both (please check API). Unfortunately the primitive types, in our case double and char are not classes. However, we can use wrapper classes Character and Double to accomplish our goal. Since both of these are subclasses of Object, instances of both these types can be pushed on the stack. Its like assigning an instance of a smaller class to an instance of a wider class. For instance, when pushing ans make it a field of a Double instance variable and push that instance variable on the stack by using:
prim = new Double(ans); stack.push(prim );
Here the Double instance variable is prim.
Special consideration must be given to removing items from the stack. Since the Object class is wider than the Double class, writing
prim = stack.pop();
will cause an error since you cannnot assign an object of a wider class to an object of a narrower class
with out type casting. So you must write:
prim = (Double)stack.pop();
To get the primitive double value, use
System.out.println(
prim.doubleValue() );
where doubleValue() is the wrapper class method that extracts the double value from the object prim. For
the Character wrapper class don't use the charValue(). Use the toString()method implicitly.
In both the Converter and Calculator classes, use a StackADT that checks for an empty stack when popping and a full stack when pushing. You should write your own MTstackException and FullStackException classes to do this. As a consequence, you should do no stack checking in the driver program except when popping the stack converting from infix to postfix.
The Converter class
This uses the following methods
1. The boolean method isOperator(char ch)
2. The boolean method isOperand(char ch)
3. The booleanmethod precedence(String op1, char op2) which determines if the incoming token op2
has precedence over the top of the stack op1.
The Calculator class
This uses the following methods
1. The boolean method isOperator(char ch)
2. The boolean method isOperand(char ch)
3. The double method result(double op1, double op2, char op) which determines the value of the binary
operator op operating on the operands op1 and op2.
Strategy for writing the program
Here is a recommended way of writing the program. If you feel comfortable skipping some steps to get to the final result, then by all means do.
1. Write the Calculator class using a stack of Object.
2. Write the Converter class using a stack of Object and instead of it printing the final postfix string, it
should return a String.
3. Have the Calculator class call the Converter class in order to get a postfix expression as input.
For this draft, write your program so that there are three files. That way it is easier to compile (one file at a time). Here are the steps:
1. A Converter class written so that the main method is rewritten as a method that returns a string. Let's call it toPostfix() with the signature: public String toPostfix()
2. A Calculator class that instantiates the Converter class so that it can access method toPostfix().
3. A StackADT class and the exception classes in one file.
Sample input
 3+4*5/6
 (3+2)*(4-2)/(8+7)
 (4+8)*(6-5)/((3-2)*(2+2))
Your output should show the converted postfix string and the result of the calculation. For instance the last sample input will produce the following in the output window:
type your infix expression (4+8)*(6-5)/((3-2)*(2+2))
converted string is 48+65-*32-22+*/ answer is 3.0
Submitted: 10 months ago.
Category: Homework
Expert:  LogicPro replied 10 months ago.
Hi,
Welcome here.
My name is XXXXX XXXXX I will help you.
Is it Java or JavaScript, please confirm?
What is the deadline?
Customer: replied 10 months ago.

hi..


 


its java, and the deadline is Friday, Nov 22th, 2013


 


Thanks

Expert:  LogicPro replied 10 months ago.
If you have any file(s). Zip, upload the file to http://wikisend.com or http://ge.tt and post download link here.
Customer: replied 10 months ago.

http://www.mediafire.com/?zw2gbwxelao0bsy

Expert:  LogicPro replied 10 months ago.
thank you.
Please check back in few hours.
Customer: replied 10 months ago.

okay


i wanna ask about the answer you will send it to me by e-mail or i have to download it from here


thank you very much i'm waiting you


 

Expert:  LogicPro replied 10 months ago.
My apologies. We are not allowed to email. I will provide you answer here only.
Customer: replied 10 months ago.

okay

Expert:  LogicPro replied 10 months ago.
ok
Expert:  LogicPro replied 10 months ago.
THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.
LogicPro, Engineer
Category: Homework
Satisfied Customers: 9516
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
LogicPro and 14 other Homework Specialists are ready to help you
Expert:  LogicPro replied 10 months ago.
Hi Tariq,
Just following up with you to see how everything is going and if you have more questions for me.
You can ask me again using "For LogicPro only" at the start of your questions like you do to get instant answers.
It will ensure that question is for me.
Please bookmark my profile page:
http://www.justanswer.com/homework/expert-logicpro/
so you can come back and ask me a question anytime.
If you need any additional information on this answer, please don't hesitate to ask by clicking on 'Reply to Expert', and I will reply as soon as possible.
I hope you found the information in my answer helpful, and if so, please let me know, here. Thank you!
Thanks very much for using Just Answer!
Best wishes
LogicPro

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience
 
 
 

Related Homework Questions