Question: Write a command - line program that accepts two numbers and a string representing an arithmetic operation: plus, minus, times, and div in either upper

Write a command-line program that accepts two numbers and
a string representing an arithmetic operation: "plus", "minus", "times", and
"div" in either upper or lower case and evaluates the resulting expression.
Examples of running the program (source in Calc.java) several times:
74 Chapter 9 Immutable Objects
> java Calc
Usage: number plus|minus|times|div number
> java Calc 3 plus 4.5
7.5
> java Calc 7.5 div 2
3.75
> java Calc 6 MINUS 1.25
4.75
The point of this exercise is to make sure you understand the mechanism for passing objects as parameters.
For the following program, draw a stack diagram showing the local variables and parameters of main and riddle just before riddle returns. Use arrows to show which objects each variable references.
What is the output of the program?
Is the blank object mutable or immutable? How can you tell?
public static int riddle(int x, Point p){
x = x +7;
return x + p.x + p.y;
}
public static void main(String[] args){
int x =5;
Point blank = new Point(1,2);
System.out.println(riddle(x, blank));
System.out.println(x);
System.out.println(blank.x);
System.out.println(blank.y);
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!