Google Answers Logo
View Question
 
Q: Equation code, need help ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: Equation code, need help
Category: Computers
Asked by: unlimitedxp-ga
List Price: $50.00
Posted: 05 Nov 2004 22:53 PST
Expires: 05 Dec 2004 22:53 PST
Question ID: 425157
For this programming project it will create a calculator to represent
the polynomials using linked lists, where each node of the linked list
will contain the information of a term: a coefficient and the exponent
of the variable. For example to represent a polynomial 5 - 3x^4 + 2x^2
+ 5x^3, the first node will have a coefficient 5 and exponent 0, the
second node will have a coefficient 3 and exponent 4, and so forth.
Combine like terms: combining like terms is to add the coeffcient of
those terms with the same exponent For example, combining the like
terms of x^2 + x^2 + 3x results in 2x^2 + 3x.
Addition adding two polynomials is simple to add like terms of both
polynomials. For example(x^2 + x^3 + 1) + (x + 2x^2 + 2) is equal to x
+ 3x^2 + x3 + 3. Substraction: to substract two polynomials you
substract the coefficient of a term of the second polynomial to the
coefficient of the like term of the first polynomial. For example(x^2
+ x^3 + 1) - (x + 2x^2 + 2) is equal to -x -x^2 + x3 - 1. Input will
be taken from the user. The calculator will prompt the user for an
input and the user can enter two kind of inputs: commands or
polynomials. If the user enters a command, your calculator should pop
the requiered number of operands from the stack, perform the opeation,
and push the result of the operation into the stack such as "c":
should combine the terms of the polynomial at the top of the stack, +:
should add the two polynomials at the top of the stack, -: should
substract the second to top polynomial minus the polynomial at the top
of the stack *: should multiply the two polynomials at the top of the
stack. When entering polynomials, the user should use the following
format, each term should be separetad by + or -, the coeffcient should
be separated from the variable by a space, the variable and exponent
should be connected by ^ and x is the only valid variable. The
following polynomial must be such like 2 x^3 + 3 x^1 + 4 x^0. The
classes must be Term: Objects of this class can be used to store the
information of a term, each term needs two values; a coefficient and
the exponent of the variable, LinkedList: objects of this class will
be used to cantain the terms of your polynomials linked list objects
are responsible for the standard linked list operation: insert, find
and delete. This class must be generic data structe, you will be able
to insert any objects. Polynomials: objects of this class are
responsible for storing a polynomials information using a linked list.
It is not a requierement for a polynomials term to be ordered by
degree. Also Polynomial objects should be able to perfor operations
add, substract and multiply given another polynomial object. Stack:
Objects of this class will contain the operands of your calculator.
Stack objects are responsible for the standard stack operations, push,
pop, peek, isEmpty and isFull and it also must be a generic data
structure anf for last is the PolynomialCalculator: objects of this
class should use a stack to store the operands and will perform the
operations requested by the user. Therefore, objects of this class are
responsible for the calculators operations: combine, add, substract,
multiply, and add operands. The main class will be in charge of
receiving input from the user, interpreting the input, and sending the
appropriate commands to the calculator. The application should also
display the output back to the user.
I will need it on Saturday November 6 or Sunday November 7.
Can you please send me the answer to my email unlimitedxp1@yahoo.com,
not post the answer.

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 07:22 PST
Dear probonopublico
I did not, that posting was against the rules, sorry for that. If you
want, you can post the solution, I would really appreciate the
solution by today.

Request for Question Clarification by endo-ga on 06 Nov 2004 08:21 PST
Hi,

What programming language do you want to use?
This sounds a lot like homework, would you rather someone helps you
start off a solution, rather than write it all for you?

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 09:39 PST
Dear endo-ga 
Its in java language. I am almost finished with the code, but there is
some problems with my code. I just want another code to compare with
in order to be able to figure it out what is wrong with mines. I
really dont have time to start off again, I gotta turn in it by today,
if you want I can send you my code and then you can also help me to
figure it out what is wrong with it? or if you a code already done,
you can also post it to see it.
Thanks unlimitedxp

Request for Question Clarification by endo-ga on 06 Nov 2004 11:05 PST
Hi,

I think I can help. I will look at your code and try and fix it.
Post links to your code here, if you can upload them to a web server I
can download them.
If you don't have access to a webserver, please upload your files to:

host: ftp.membres.lycos.fr
username: dbky
password: googleanswers

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 12:28 PST
Dear endo-ga
I already uploaded the files to your ftp in word format, you just have
to copy and paste them in your computer, or you can also open a
notepad to save them in there as .cmd to compile them from there,
either way. Please tell me if you already got them in order for you te
be able to give it a look. Thank you for your help.

Request for Question Clarification by endo-ga on 06 Nov 2004 12:37 PST
Hi,

Thanks, got them, trying to figure out what is what.
If you can give a short explanation that would make things easier.

Thanks.
endo

Request for Question Clarification by endo-ga on 06 Nov 2004 12:43 PST
Hi,

Also, please tell me what the problems are and where you think they are.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 13:31 PST
Dear endo
I ve got a problem at the moment of reading the numbers from the
stack, because I did some tests in the main class to see what would be
printing and the output waited for me, but as you can see in the
output is completely different from the numbers that you are trying to
compute with the contents of the stack. I think the problem could be
with the main class that is not doing exactly what is created for.
Then I also checked the values from t and f in the calculator class
and it showed as a double and int, but the Tokenizer does not seems to
go through the entire equation. There must be something wrong at the
moment of reading an input. I ve got these results from these two
System print out System.out.println(stacky);
 System.out.println(t +" " + f); . There is also a mistake in the
polynomial class at line 95, there is a null value that is showing at
the moment of running the main. Do not mind the last mistake a line
134 from calculator.
Please enter the numbers that you need to compute: 4 x^ 5 + 6 x^ 2
 +4.0*x^4
4.0 4
 +4.0*x^4 +5.0*x^5
5.0 5
Exception in thread "main" java.lang.ClassCastException
        at Polynomial.add(Polynomial.java:95)
        at Calculator.main(Calculator.java:134)

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 13:32 PST
If I can help you with anyquestions or concern please feel free to ask
me.Thank you.
unlimitedxp

Request for Question Clarification by endo-ga on 06 Nov 2004 13:57 PST
Hi,

The files you sent are a bit confusing, there are several classes that
are repeated several times. Could you please reupload the .java files
as you are using them to compile and run the latest version you have.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 14:27 PST
Did you get my java files yet? If you do then I will try explain it.
Look, the last three java link lists are just one implemented linked
list, but I did it in different way trying to have a better access to
the stack. I ve got those numbers from trying to compile the
calculator class and running it by writing java Calculator in the
command prompt. You can also do any modifications that you think it
would be necessary to do in order to make the program works correctly.
Feel free to write me again for any regards or question. Thank you

Request for Question Clarification by endo-ga on 06 Nov 2004 15:00 PST
Hi,

I got the Java files, thanks. I'll work on it soon.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 15:24 PST
Dear endo
Thanks to you

Request for Question Clarification by endo-ga on 06 Nov 2004 16:46 PST
Hi,

Are you sure you sent me the latest versions of the files? 
There seems to be problems with the Stack and Polynomial classes,
there are mising functions or incorrect calls to functions there. I
can't compile them at the moment, they're missing code, otherwise it
doesn't make any sense.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 23:08 PST
I did some changes to the Polynomial classes, working withouth stacks,
but the polynomial class is now working. I already update the files in
your ftp, if you want it to check it out now. That was my actual
version, because the stack class is created into the polynomial class
without any callings, but there was a misunderstanding in my part to
call an extra stack, but I saw in the assignment is necessary just to
hold the operands of the calculator and the linked list is responsible
to contain the terms of your polynomials. How can you mixed them up at
the time of calling them into the polynomial class, anyways, but i
could not really implement that part into code, I think all the
calling is in the polynomial class. If you have something new about
the code please tell me or if you have some other concerns or
questions.

Request for Question Clarification by endo-ga on 06 Nov 2004 23:15 PST
Thanks, it compiles ok now. Is it if I work on this on Sunday? It's
7am now, and I haven't gone to sleep yet.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 23:29 PST
Dear endo
Thats all right, I mean i really appreaciate what you are doing to
help me. Tomorrow is fine. Meanwhile, I will keep working on it,
becuase in here is 12:28am.
Thanks you

Clarification of Question by unlimitedxp-ga on 06 Nov 2004 23:49 PST
I will add an extra List Price to this assignment.

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 00:40 PST
Dear probonopublico-ga
Do you have a different way to solve it, because i did it in a way
that I am still stuck, and I cannot figure it out, what is wrong with
mines version. Do you already figured out.

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 00:45 PST
I needed it really bad as fast as I can, not just to score some points
in the grade, but to pass the class, becuase the due to turn in the
project was on november 2. I have not finish it yet and they requiered
me to turn in every single project and I am getting behind from the
others at this time. I have to turn in the next one on tuesday, I
would really appreaciate any help that you can give me probonopublico.
Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 11:02 PST
Hi,

I think I've got addition working.
I've uploaded a new version of Calculator.java.

I changed lines 105-116 in Calculator.java.

The logic for reading the tokens was wrong, so you were casting a "+"
sign into a Polynomial, hence the error. I'll have a look at
multiplication now.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 11:16 PST
Dear Endo
That's really great!!! I am redoing the whole thing again in order to
be able to search for a new  perspectives. I was really lost, so I
decided to start from the beginning in order to be able to think way
ahead before to codify. If you want I can also upload all the new
classes that I am doing for you to have a better perspective about
what is going on. Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 11:20 PST
Hi,

If you're starting over again, then I'll stop working on the old code.

Let me know when you get stuck with your new code and I'll help you
out. If you have a problem that you can't solve, upload the files
again and I'll look. You can delete the old ones from the FTP too, to
avoid any confusion. Let me know how it goes.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 12:10 PST
I already uploaded all new files that I have now. You can give it a
look and see if this version is better than the old version, because
if is better is more convenient keep working on this version, but If
you feel more comfortable working with the old version is also fine,
either way. I think that in the new version I have a more complete
linked list, but I am still having a problem the calculator method as
you said before in the lines 105 to 116. There is also the problem
that I don?t know how to implement the stack and the linked list
together in the main calculator class. If you have any clues to fix
them up, I would appreciate your assistance. Did you get the new
version yet?

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 12:28 PST
The only significant change that I did was on the linked list classes
in order to be able to mix them up with the Term class, but I am still
stuck with the two last classes Polynomial and Calculator. As you said
before, there must be a mistake in reading the numbers at the final
class. I also cannot see how to implement the stack class to contain
the operands of the calculator and I also don?t know how to implement
the linked list at the calculator class. If you can figure these
problems out that would means that we are getting close to finish this
project.

Request for Question Clarification by endo-ga on 07 Nov 2004 12:35 PST
Hi,

I downloaded the new files, but it's not a good idea for us to work on
them at the same time. Keep on coding the new version, and tell me
when you get stuck and I'll  try and help you out.
In the meantime, I'll try and fix the old version.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 12:59 PST
Dear Endo
Please enter the numbers that you need to compute: 4 x^3 + 5 x^6
 +4*x^4
4 4
 +3*x^3 +4*x^4
3 3
Exception in thread "main" java.lang.ClassCastException
        at Polynomial.add(Polynomial.java:88)
        at Calculator.main(Calculator.java:136)
As you can see, I am still having almost the same problems with the
new version than I did with the old one. If you can help me to fix
this problem and the questions that I already mention before. I think
we will be so close to solve it by today.Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 13:07 PST
Hi,

Are you referring to new code you just uploaded?

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 13:15 PST
Dear endo
Yes I am, I am referring to the new code. Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 13:31 PST
Hi,

I uploaded Calculator.java again. It works for addition. You need to
respect the syntax exactly though. E.g. the position of the spaces.

Try:

1 x^2 + 3 x^5 + 5 x^2

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 13:39 PST
Dear Endo
Can you upload the calculator class again?, because I have missed the
last one that you already uploaded. Sorry and Thank you ahh and please
tell me the location of the new one.

Request for Question Clarification by endo-ga on 07 Nov 2004 13:57 PST
Hi,

I uploaded it again. It's in newjavaclasses.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 14:03 PST
Dear Endo
You are absolutely right, I could perform the addition operation. We
are almost done!!!!! I am so happy!! :) Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 14:29 PST
Hi,

That's good. Let me know if you get stuck again.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 15:38 PST
Dear Endo
I am still working on Polynomial class with the multiplication and
substraction methods. Do you have something new? Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 15:41 PST
Hi,

Multiplication should almost work. Upload any changes you made, and
I'll have a look at multiplication.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 16:00 PST
Please enter the numbers that you need to compute: 1 x^2 * 3 x^5 * 5 x^2
Exception in thread "main" java.lang.ClassCastException
        at Polynomial.multiply(Polynomial.java:113)
        at Calculator.main(Calculator.java:183)
There is a mistake at line 113 from Polynomial class, but I did an if
statment to make sure that line does not give me an empty value. It
looks like it is working fine.Then I looked up at the main calculator
class to see if I need an extra code in there, but I did not see
anything wrong. Do you know what is causing that exception?.Meanwhile,
I will keep working on it

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 16:07 PST
I also did some changes in the main, but the multiplication is still
adding instead of multiplying. I will also upload the main class and
one input and ouput.
Please enter the numbers that you need to compute: 4 x^2 * 3 x^5 * 5 x^2
Answer  +9*x^2 +3*x^5

Request for Question Clarification by endo-ga on 07 Nov 2004 17:11 PST
Hi,

I've uploaded new files. Multiplication works now.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 17:40 PST
r

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 17:43 PST
Dear endo
the multiplitacion is working now!!!! For the substraction must be the
same as the addition. I mean do i have to create a new substraction
method in the polynomial class, or I can still substracting with the
add method. In order to be able to read the substraction method, Can I
do the same thing as you did with the multiplication, just changing
instead of stacky =  stacky.multiply(stacky); a stacky = 
stacky.add(stacky); for the substracting operation.
What do you recommend me to do?

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 17:50 PST
Dear Endo
Please help to finish the last requierements of this assignment endo,
because I have not slept that well, so I am having problems to
concentrate and trying to figure it out the last part. I would add an
extra price list.Thank you

Request for Question Clarification by endo-ga on 07 Nov 2004 17:50 PST
Hi,

For subtraction I recommend you try and do the same thing as multiplication.
Let me know if you get stuck. I'm going to have to sleep soon.

Thanks.
endo

Request for Question Clarification by endo-ga on 07 Nov 2004 17:51 PST
Hi,

What's left? You want me to finish with subtraction? If you're really
happy with the answer you can tip me, once I've posted something in
the answer box.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 17:55 PST
Is this the output is supposed to give me for substraction?
Please enter the numbers that you need to compute: 4 x^2 - 3 x^5 - 5 x^2
Answer  +0*x^4 +0*x^6 +0*x^8 +0*x^9 +0*x^11 +0*x^12 +0*x^14 +0*x^17 +0*x^20

Request for Question Clarification by endo-ga on 07 Nov 2004 18:01 PST
Hi,

No, that's incorrect.
For: 4 x^2 - 3 x^5 - 5 x^2
You should get:
-1 x^2 - 3 x^5

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 18:16 PST
I think that I am getting close, this is the answer that is giving me
the substract method.
Please enter the numbers that you need to compute: 4 x^2 - 3 x^5 - 5 x^2
Answer  +7*x^2 +-7*x^5
What could be gone wrong?

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 18:19 PST
Please enter the numbers that you need to compute: 4 x^2 - 3 x^5 - 5 x^2
Answer  +0*x^2 +0*x^5
This is my next output,This one is not computing exactly the operations.

Request for Question Clarification by endo-ga on 07 Nov 2004 18:21 PST
Hi,

That's still wrong.
If you try and do it the same way as the multiplication, it should work.

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 18:26 PST
Dear endo
I am going to upload the substraction method, to see if you could see
it and tell me what is wrong with it, before you go to bed. Thank you

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 18:30 PST
Did you get them yet?

Request for Question Clarification by endo-ga on 07 Nov 2004 18:31 PST
Hi,

That's ok, I'll get back to you soon and post that as an answer, ok?

Thanks.
endo

Clarification of Question by unlimitedxp-ga on 07 Nov 2004 18:36 PST
Dear endo
sure thats fine!!! Thanks a lot
Answer  
Subject: Re: Equation code, need help
Answered By: endo-ga on 07 Nov 2004 19:26 PST
Rated:5 out of 5 stars
 
Hi,

I figured out why addition was working, it's because you do the
addition automatically in insertTerm.

So I did subtraction as a mix of addition and multiplication and added
a new function called insertNegTerm.

I also had to rewrite multiplication because it somehow got lost in
the uploading/downloading.

I uploaded the new versions of Calculator and Polynomial. It works now
for addition, multiplication and subtraction.

If you need any more help, please let me know. But I'll be going to sleep soon.

Thanks.
endo

Request for Answer Clarification by unlimitedxp-ga on 07 Nov 2004 19:48 PST
Just one more clarification, before you go to bed. "c" should combine
the terms of the polynomial at the top of the stack. Does that means
that I must enter one polynomial equation then a c and after that I
will enter the last polynomial equation to add both and get a single
result.

Clarification of Answer by endo-ga on 07 Nov 2004 19:59 PST
Hi,

You already combine the terms of the polynomial automatically when you
do insertTerm. It means that if the polynomial is: 5 x^2 + 3 x^2, you
rewrite it as 8 x^2.

Thanks.
endo

Clarification of Answer by endo-ga on 08 Nov 2004 05:20 PST
Thank you for the great rating, very generous tip and kind comment!
Good luck with your work!
unlimitedxp-ga rated this answer:5 out of 5 stars and gave an additional tip of: $50.00
He is really helpful, he was always on time to respond my questions
with a properly feedback. As you well noted, there were a lot of
communication between us during this assignment. I will definetely
will work with him again. I really appreaciate what he did for me. I
was really having troubles to try to figure it out this problem,
because I was in a hurry and I lost a lot of time trying to reach
someone at the work. Thanks a lot Endo

Comments  
Subject: Re: Equation code, need help
From: probonopublico-ga on 05 Nov 2004 23:11 PST
 
Oops ... I have just whizzed my through this little exercise and I was
about to post the solution when I noticed that you require it to be
emailed to you ...

Sorry but that is strictly against the GA Rules!
Subject: Re: Equation code, need help
From: probonopublico-ga on 07 Nov 2004 00:31 PST
 
As endo-ga is now on the case, I will step aside because I am sure
that he will sort it out for you.

Good luck!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy