
Question 4. Given the following Java
public class Example
{
static int n = 3;
public static void main(String[] args) {
int k;
k = n;
Controller control = new Controller(k);
control.compute();
}
}
class Controller
{
int n;
Controller(int n) {this.n = n;}
void compute() {
int i, m;
int sum = 0;
String message;
Functor func;
for(i = n; i > 0; i--) {
func = new Functor();
m = func.calculate(i);
sum = sum + m;
}
message = “The sum of factorials from 1 to “ + n + “ is “ + sum;
System.out.println(message);
}
}
class Functor
{
int calculate(int n) {
int temp;
temp = n – 1;
if (n > 0) { return n * calculate(temp); }
else {return 1;}
}
}
*List all static variables, stack-dynamic variables, explicit heap-dynamic variables, and
implicit heap-dynamic variables.
![public class Example
{
static int n = 3;
public static void main(String[] args) {
int k;
k= n;
Controller control = new Controller(k);
control.compute();
}
}
class Controller
{
int n;
Controller(int n) {this.n = n;}
void compute() {
int i, m;
int sum = 0;
String message;
Functor func;
for(i = n; i>0; i--) {
func = new Functor();
m = func.calculate(i);
sum = sum + m;
}
message = "The sum of factorials from 1 to “ +n + “is “+ sum;
System.out.println(message);
}
}
class Functor
{
int calculate(int n) {
int temp;
temp = n – 1;](https://content.bartleby.com/qna-images/question/cbd96f76-54ea-4973-af6d-49f980c91b19/ebf627b4-166a-49c3-b9f4-8d5b7bb2cc69/maloo0a_thumbnail.png)


Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- c) Draw a UML Diagram for the following source code. (CLO1, CLO2) public class MyCircle { double MyRadius= 0.0; MyCircle() { } MyÇircle(double newRadius) { MyRadius = newRadius; } double getArea() { return MyRadius * MyRadius * 3.14159;} public static void main(String[] args) { MyCircle C1 = new MyCircle(); C1 MyRadius = 2.0; MyCircle C2 = new MyCircle(); C2.MyRadius = 4.0; System.out.println(C1.getArea()); System.out println(C2,getArea(); } }arrow_forwardConsider the following skeletal C program: void fun1(void); /* prototype */void fun2(void); /* prototype */void fun3(void); /* prototype */void main() { int a, b, c; . . .}void fun1(void) { int b, c, d; . . .}void fun2(void) { int c, d, e; . . .}void fun3(void) { int d, e, f; . . .}Given the following calling sequences and assuming that dynamic scoping is used, whatvariables are visible during the execution of the last function? Include with each visible variablethe name of the function in which it was defined.a. main calls fun1; fun1 calls fun2; fun2 calls fun3.b. main calls fun1; fun1 calls fun3.c. main calls fun2; fun2 calls fun3; fun3 calls fun1.d. main calls fun3; fun3 calls fun1.e. main calls fun1; fun1 calls fun3; fun3 calls fun2. Consider the following program, written in JavaScript-like syntax: // main programvar x, y, z;function sub1() {var a, y, z;. . .}function sub2() { var a, b, z; . . .}function sub3() { var a, x, w; . . .}Given the following calling sequences and…arrow_forwardQ) Distinguish between abstract class and interface in java languagearrow_forward
- Assignment 16: Iteration Control Structure - Hands on practice Hint: Consider numbers 1 to 10, for each number find the odd multiples. Example, for 1, it should be 1, 3, 5, 7, 9 Objective: Given a real world problem, implement the logic and solve the problem using appropriate constructs (sequen- tial, selection, iteration) using an object oriented program- ming language (Java) for 2, it should be 2, 6, 10, 14, 18 Estimated time: 50 minutes Summary of this assignment: In this assignment, you have learnt the implementation of iteration control structures. Problem Description: Write simple java programs to implement the following prob- lems. 1.Find the sum of first 5 numbers (1 to 5) using for loop End of document statement 2.Find the product of first 5 numbers (1 to 5) using while loop statement 3. Generate the multiplication table of 10 upto multiple value 500 4.Calculate the square of first 5 numbers (1 to 5) using do..while statement 5.Find the odd multiples among the first 10…arrow_forwardDefine and use an instance methodarrow_forwardRemaining Time: 31 minutes, 51 seconds. ¥ Question Completion Status: What is the error in the below code? Provide your explanation. #include using namespace std; class parent{ private: int i, j; public: parent (int i, int j) class child: public parent { public void show(){ cout<<" i = "<arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





