public class ReduceTheCode { //Each method must perform the same action as it cu
ID: 3621458 • Letter: P
Question
public class ReduceTheCode {
//Each method must perform the same action as it currently does
//You are free to change the way in which it does it
//You can delete these comments and the extra blank lines
private int foo;
private int bar;
private int [][] tao;
public ReduceTheCode(){
foo = 5;
bar = foo * 5;
tao = new int[foo][];
for (int i = 0; i < foo; i++){
tao[i] = new int[bar];
for (int j = 0; j < bar; j++){
tao[i][j] = foo+bar;
}
}
}
public int getFoo(){
tao = new int[foo][];
for (int i = 0; i < foo; i++){
tao[i] = new int[bar];
for (int j = 0; j < bar; j++){
tao[i][j] = foo+bar;
}
}
return foo;
}
public void setVariables(int a){
foo = a;
bar = foo * 5;
tao = new int[foo][];
for (int i = 0; i < foo; i++){
tao[i] = new int[bar];
for (int j = 0; j < bar; j++){
tao[i][j] = foo+bar;
}
}
}
public static int a(int i){
if(i == 0){
return 12;
}
else if(i == 1){
return 13;
}
else if(i == 2){
return 14;
}
else if(i == 3){
return 15;
}
else if(i == 4){
return 16;
}
else if(i == 5){
return 17;
}
else if(i == 6){
return 18;
}
else if(i == 7){
return 19;
}
else if(i == 8){
return 20;
}
else if(i == 9){
return 21;
}
else if(i == 10){
return 22;
}
else if(i == 11){
return 23;
}
else if(i == 12){
return 24;
}
else if(i == 13){
return 25;
}
else if(i == 14){
return 26;
}
else if(i == 15){
return 27;
}
else if(i == 16){
return 28;
}
else if(i == 17){
return 29;
}
else if(i == 18){
return 30;
}
else if(i == 19){
return 31;
}
else if(i == 20){
return 32;
}
else{
return -1;
}
}
public static int b(int i){
if(i == 0){
return 3493;
}
else if(i == 1){
return 3011;
}
else if(i == 2){
return 6881;
}
else if(i == 3){
return 5413;
}
else if(i == 4){
return 2144;
}
else if(i == 5){
return 1728;
}
else if(i == 6){
return 8383;
}
else if(i == 7){
return 2970;
}
else if(i == 8){
return 8226;
}
else if(i == 9){
return 2396;
}
else if(i == 10){
return 4106;
}
else if(i == 11){
return 9201;
}
else if(i == 12){
return 9582;
}
else if(i == 13){
return 7412;
}
else if(i == 14){
return 4091;
}
else if(i == 15){
return 7291;
}
else if(i == 16){
return 1747;
}
else if(i == 17){
return 9922;
}
else if(i == 18){
return 4647;
}
else if(i == 19){
return 6070;
}
else if(i == 20){
return 9946;
}
else{
return -1;
}
}
public static void c(int i){
if(i == 0){
i += 7221;
}
else if(i == 1){
i += 5084;
}
else if(i == 2){
i += 9790;
}
else if(i == 3){
i += 7601;
}
else if(i == 4){
i += 2951;
}
else if(i == 5){
i += 1854;
}
else if(i == 6){
i += 1372;
}
else if(i == 7){
i += 5874;
}
else if(i == 8){
i += 2996;
}
else if(i == 9){
i += 5345;
}
else if(i == 10){
i += 5358;
}
else if(i == 11){
i += 4542;
}
else if(i == 12){
i += 3103;
}
else if(i == 13){
i += 2730;
}
else if(i == 14){
i += 1972;
}
else if(i == 15){
i += 2703;
}
else if(i == 16){
i += 1661;
}
else if(i == 17){
i += 6783;
}
else if(i == 18){
i += 4094;
}
else if(i == 19){
i += 3128;
}
else{
i = -1;
}
}
}
Explanation / Answer
public class ReduceTheCode {
private int foo;
private int [][] tao;
public ReduceTheCode(){
setVariables(5);
}
public int getFoo(){
return foo;
}
public void setVariables(int a){
foo = a;
tao = new int[a][a*5];
for (int i = 0; i < foo; i++){
for (int j = 0; j < bar; j++)
tao[i][j] = foo+bar;
}
public static int a(int i){
return (i >=0 && i <=20)? i+12 : -1;
}
final int[] B = {3493, 3011, 6881, 5413, 2144, 1728, 8383, 2970, 8226, 2396, 4106, 9201, 9582, 7412, 4091, 7291, 1747, 9921, 4547, 6070, 9946};
public static int b(int i){
return (i >=0 && i <=20)? B[i] : -1;
}
public static void c(int i){}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.