102k views
3 votes
Define stubs for the functions called by the below main(). Each stub should print "FIXME: Finish FunctionName()" followed by a newline, and should return -1.

User RxRead
by
5.9k points

2 Answers

4 votes

Final answer:

To define stubs for the functions called by the main() function, create empty functions that mimic the intended functionality with a print statement and a return statement of -1.

Step-by-step explanation:

To define stubs for the functions called by the main() function, you need to create empty functions that mimic the intended functionality of those functions. Here's one way to do it:

Create a function with the same name as the function called by the main() function.

In the function body, use the print() function to print the message 'FIXME: Finish FunctionName()' followed by a newline.

Return -1.

For example, if the main() function calls a function called calculate(), the stub for that function would look like this:

def calculate():

print('FIXME: Finish calculate()')

return -1

User Lorenz Pfisterer
by
5.1k points
3 votes

Answer:

A stub method or merely a stub in software development is a code piece that performs various other programming functionality. It can copy the existing code behavior like a procedure on a remote machine like methods are quite frequently known as mocks or for a while working for a code that has not yet been developed.

Please check the explanation for more details.

Step-by-step explanation:

A method stub in this intelligence is a method with no factual material, i.e. it's not deed what it is intended to do. Your getUserNum() method must return a user's unique ID, but in its place, you're indispensable a stub that merely returns -1 on every request.

Through the main method, you should define these methods:

Num1=getUserNum();

Num2=getUserNum();

avgResult = computeAvg(Num1, Num2);

Hence, define them. And below is how the above stub function should be like:

public static int getUserNum(){

System.out.println("FIXMR:Finish getUserNum()");

return -1;

And the whole program should look like:

import java.util.Scanner;

public class Main {

public static int getUserNum ()

{

System.out.println("FIXME: Finish getUserNum()");

return -1;

}

public static int computeAvg(int Num1, int Num2)

{

int avgResult = (Num1 + Num2)/2;

System.out.println("FIXME: Finish computeAvg()"); return -1;

}

public static void main(String[] args)

{

int Num1 = 0;

int Num2 = 0;

int avgResult = 0;

Num1 = getUserNum(); Num2 = getUserNum();

avgResult = computeAvg(Num1, Num2);

System.out.println("Avg: " + avgResult);

return;

}

}

User Johannes Barop
by
5.0k points