Question: Please create the following menu for the Ackermann project. This program allows you to call the Ackermann function. please choose a version of Ackermann's function.
Please create the following menu for the Ackermann project.
This program allows you to call the Ackermann function.
please choose a version of Ackermann's function.
1) Ackermann value
2) Ackermann trace
3) Ackermann table lookup
4) Quit Playing with the ackermann Function.
Please choose one of the 4 choices.
I already have the code for the first two, Ackermann value and Ackermann trace
/*@Author Netsanet
* @version 06/25/2017
*
*/
import java.util.Scanner;
public class AckermannInstructions { // defining a class
public static void main(String[] args) { // main method definition.
System.out.println("This program allows you to call the Ackermann function."); // displaying the text to the user
AckermannsFunction integers = new AckermannsFunction(); // creating an object variable of the class and allocating memory for it.
Scanner scnr = new Scanner(System.in); // creating an object variable keyboard for the scanner class to read input from the user.
int option; // declaring an integer variable.
int count = 0;
do{
printOptions(); // calling the method
option = scnr.nextInt(); // reading input into the option variable from the user.
scnr.nextLine();
if (option == 1){
System.out.print("Please enter a value for m: ");
int m = scnr.nextInt();
System.out.print("Please enter a value for n: ");
int n = scnr.nextInt();
System.out.println("Ackerman value - "+AckermannsFunction.Ackermann(m,n));
}else if (option == 2){
System.out.print("Please enter a value for m: ");
int m = scnr.nextInt();
System.out.print("Please enter a value for n: ");
int n = scnr.nextInt();
System.out.println("Ackerman value = "+AckermannsFunction.ackTrace(m,n));
}else if (option == 3){
}
} while(option != 4);
System.out.println("Quit!");
}
public static void printOptions(){
System.out.println(" Please choose a version of Ackermann's Function.");
System.out.println("\t1) Ackermann value.");
System.out.println("\t2) Ackermann trace");
System.out.println("\t3) Ackermann table lookup.");
System.out.println("\t4) Quit playing with the Ackermann Function.");
System.out.println("\tPlease choose one of the 4 choices.");
}
}
class AckermannsFunction {
public static int Ackermann(int m, int n){
//calculate if m = 0 and here it is modified to execute correctly and to give correct output.
if(m == 0){
return n + 1;
}
else if( n == 0){
return Ackermann(m - 1, 1);
}
else {
return Ackermann(m - 1, Ackermann(m, n - 1));
}
}
public static int ackTrace(int m, int n){
int count = 0;
count++;
System.out.println("count: " + count + " m = " + m + " n = " + n);
if(m==0){
return n+1;
}
else if(n==0){
return ackTrace(m - 1, 1);
}
else{
return ackTrace(m-1, ackTrace(m, n-1));
}
}
public static int lookup(int m,int n )
{
int hit=0;
int miss=0;
for(int i = 0;i { for(int j = 0;j { if(a[i][j]==a[m][n]) { return a[m][n]; } } } return 0; } public static void entrytable(int m,int n,int result1) { for(i=0;i { for(j=0;j { if(a[i][j]==result1) { System.out.println("for"+m+ "and" +n+"value =" +a[i][j]); } else { a[m][n]=result1; } } } } } Devise a table look-up method that shortens the process of computing the function value by storing intermediate rsults for Ackermann and using these values when they are available. Display the number of "hits" to the table look-up when doing the table look-up method. 2)create a graph of the values of Ackermann's function as the function is being run.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
