In: Computer Science
The following program is written to calculate the addition for two numbers (9,3). Unfortunately, the program has Compile-time and Run-time errors that prevent the program from running and producing the correct result. Using the Table 2.1 below, allocate the error(s) on each program line.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Below are the errors:
Demonstration :
Here a new java program with name
"Calculation.java" is created, which contains
following code.
Calculation.java
:
// define new class
public class Calculation {
private int result_add;
// define add method to add two numbers
public void add(int first_number, int second_number)
{
int number1 = first_number;
int number2 = second_number;
result_add = number1+
number2;
}
//return the value
public int getvalue() {
return result_add;
}
//entry point of program ,main method
public static void main(String[] args) {
// define new object with name summation
Calculation summation = new
Calculation();
summation.add(9, 3);
int result =
summation.getvalue();
System.out.println(result);
}
}
======================================================
Output : Compile and Run Calculation.java to get the screen as shown below
Screen 1 :Calculation.java
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.