Consider the following non-negative integer functions: a. s(i) - returns the suc
ID: 2246288 • Letter: C
Question
Consider the following non-negative integer functions: a. s(i) - returns the successor of i // implemented as ++i b. p(i) - returns the predecessor of i. // implemented as --i c. padd(i, j) = {i j = 0 padd(s(i), p(i)) j > 0} // This recursive function returns i+ j d. pmul(i, j) = {i j = 1 padd((i, pmul(i, p(j)) j > 1} // This recursive function returns i times j e. ppwr(i, j) = {i j = 1 pmul((i, ppwr(i, p(j)) j > 1} // This recursive function returns i^j Your task is to write a Java class referred to as Peano-Arithmetic. The class should have at least two private integer members (eg, int i: int j;) At the minimum, the class should include all the above operations ((a) to (e)) as methods where the methods corresponding to (a) and (b) are available only to member functions of the class. At the minimum, the class should have a constructor as well as a getter and a setter for its two private members (listed above). Test the class with a main function that sets an integer variable, m, to 2 and an integer variable, n, to 3. Next, the program calculates and outputs (to the screen) m^n using the Peano-Arithmetic class.Explanation / Answer
import java.io.*;
import java.util.*;
class PeanoAirthmatic {
private int i,j;
public PeanoAirthmatic(int a, int b){
i = a;
j = b;
}
private int s(int a){
return ++a;
}
private int p(int a){
return --a;
}
public int padd(int a, int b){
if (b == 0)
return a;
else
return(padd(s(a),p(b)));
}
public int pmul(int a, int b){
if (b == 1)
return a;
else
return(padd(a,pmul(a,p(b))));
}
public int ppwr(int a, int b){
if (b == 1)
return a;
else
return(pmul(a,ppwr(a,p(b))));
}
public void setI(int a){
i = a;
}
public void setJ(int a){
j = a;
}
public int getI(){
return i;
}
public int getJ(){
return j;
}
}
public class DemoPeanoAirthmatic {
public static void main(String[] args){
PeanoAirthmatic p = new PeanoAirthmatic(2,3);
System.out.println(p.ppwr(2,3));
}
}