Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This question involves computing an integer based on two input strings. You will write the compute method of the following Operator class. public class Operator
This question involves computing an integer based on two input strings. You will write the compute method
of the following Operator class.
public class Operator
Returns an integer value based on the input string
public static int transformString str
implementation not shown
Returns an integer based on two input strings, as described in part
a
Precondition Precondition: input and op are not null.
The length of input is even.
op is either $$ or ##
public static int computeString input, String op
to be implemented in part a
There may be variables and methods that are not shown.
a Write the compute method of the Operator class. The method calculates an integer value based on an
input string with even length. The first half and the second half of input are transformed into numeric values
by calls to transform. The numeric values are then used in a calculation based on the mathematical operation
represented by the string, op The method returns the calculated result.
The helper method transform has been provided. The method returns an integer value based on its String
parameter. For example, the method call transformpear might return the int value
The mathematical operations represented by op are described in the following table. Assume that value is
the numeric value obtained by calling transform on the first half of input and value is the numeric
value obtained by calling transform on the second half of input.
Test Booklet
Mock Exam Part
Page of AP Computer Science A
Value of op Mathematical Operation Description
$$ Addition value plus value
Multiplication value times value
## Subtraction value minus value
For example, assume that calls to transform are made from the Operator class and that
transformorang returns and transformepear returns Then the method call
Operator.computeorangepear$$ should return
As another example, the method call Operator.computeorangepear## should return
Complete method compute. You must use transform appropriately to receive full credit.
Returns an integer based on two input strings, as described in part
a
Precondition Precondition: input and op are not null.
The length of input is even.
op is either $$ or ##
public static int computeString input, String op
b A programmer wants to modify the Operator class so that the compute method has a single String
parameter containing both input and op
Write a description of how you would change the Operator class in order to support this modification. Do not
write the program code for this change.
Make sure to include the following in your response.
Identify any new or modified variables or methods.
Describe, for each new or revised variable or method, how it would change or be implemented, including
visibility and type.
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