Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this java problem ( TODO parts ) : package ps 1 ; / * * Cons is a simple cons cell
I need help with this java problemTODO parts:
package ps;
Cons is a simple cons cell record type.
class Cons
RatPoly head;
Cons tail;
ConsRatPoly h Cons t head h; tail t;
RatPolyStack is a mutable finite sequence of RatPoly objects.
Each RatPolyStack can be described by p p where is
an empty stack, p is a one element stack containing the Poly
p and so on RatPolyStacks can also be described
constructively, with the append operation, : such that p:S
is the result of putting p at the front of the RatPolyStack S
A finite sequence has an associated size, corresponding to the
number of elements in the sequence. Thus the size of is the
size of p is the size of p p is and so on
Note that RatPolyStack is similar to lists like @link
java.util.ArrayList with respect to its abstract state a finite
sequence but is quite different in terms of intended usage. A
stack typically only needs to support operations around its top
efficiently, while a vector is expected to be able to retrieve
objects at any index in amortized constant time. Thus it is
acceptable for a stack to require On time to retrieve an element
at some arbitrary depth, but pushing and popping elements should
be O time.
public class RatPolyStack
private Cons polys; head of list
private int size; redundantlystored list length
public void div
TODO: Fill in this method, then remove the RuntimeException
throw new RuntimeExceptionRatPolyStackdiv unimplemented!
;
Integrates the top element of this, placing the result on top
of the stack.
@requires this.size
@modifies this
@effects If this p:S
then thispost p:S
where p indefinite integral of p with integration constant
public void integrate
TODO: Fill in this method, then remove the RuntimeException
throw new RuntimeExceptionRatPolyStackintegrate unimplemented!
;
Differentiates the top element of this, placing the result on top
of the stack.
@requires this.size
@modifies this
@effects If this p:S
then thispost p:S
where p derivative of p
public void differentiate
TODO: Fill in this method, then remove the RuntimeException
throw new RuntimeExceptionRatPolyStackdifferentiate unimplemented!
;
Returns the number of RayPolys in this RatPolyStack.
@return the size of this sequence.
public int size
TODO: Fill in this method, then remove the RuntimeException
throw new RuntimeExceptionRatPolyStacksize unimplemented!
;
Checks to see if the representation invariant is being violated and if so throws RuntimeException
@throws RuntimeException if representation invariant is violated
private void checkRep throws RuntimeException
ifpolys null
ifsize
throw new RuntimeExceptionsize field should be equal to zero when polys is null sine stack is empty";
else
int countResult ;
RatPoly headPoly polys.head;
Cons nextCons polys;
ifheadPoly null
for int i ;; i
ifnextCons null
countResult i;
nextCons nextCons.tail;
else
break;
ifcountResult size
throw new RuntimeExceptionsize field is not equal to Countspolys Size constant is size Cons cells have length countResult;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started