Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write an Array toolbox using Java. All the methods should be implemen

ID: 3917558 • Letter: Y

Question

You are to write an Array toolbox using Java. All the methods should be implemented in your program, don’t use any method from Java API’s. program will have a main menu, where the user can select which function he/she will like to run. The program will have two main classes:

1- Array_1: which is a one dimension array. This class will have the following methods a. Construct an array (with a specific size) b. Double the size of an existing array c. Initialize an array based on its size by reading its elements from user d. Add two arrays of the same size, the result will be stored in a third array e. Get the sum of all elements of an array f. Find the maximum, minimum and the average of all elements in the array. g. Find a specific element in an array. h. Sort an array (ascending order) i. Print the array elements

2- Array_2: which is a two-dimension array. This class will have the following methods: a. Construct an array (with a specific size (number of rows and Columns)) b. Initialize an array by reading input from user. c. Get the sum of all elements of an array d. Find the maximum, minimum and the average of all elements in the array. e. Find a specific element in an array. f. Print the array elements

Explanation / Answer

here is your class : ------->>>>>>>

import java.util.Scanner;


public class Array_1{
public int[] array;

public Array_1(int size){
  createArray(size);
}

public Array_1(){
  array = null;
}

public void createArray(int size){
  array = new int[size];
}

public void doubleArraySize(){
  if(array == null){
   return;
  }
  int[] temp = new int[array.length*2];
  for(int i = 0;i<array.length;i++){
   temp[i] = array[i];
  }
  array = temp;
}

public void initialize(Scanner sc1){
  System.out.println("Enter The Array Element : ");
  for(int i = 0;i<array.length;i++){
   System.out.print(" "+i+" : ");
   array[i] = sc1.nextInt();
  }
}

public Array_1 add(Array_1 arr){
  if(arr.array.length == array.length){
   Array_1 temp = new Array_1(arr.array.length);
   for(int i = 0;i<array.length;i++){
    temp.array[i] = array[i] + arr.array[i];
   }
   return temp;
  }
  return null;
}

public void sort(){
  if(array == null){
   return;
  }
  int temp;
  for(int i = 0;i<array.length;i++){
   for(int j = i+1;j<array.length;j++){
    if(array[i] > array[j]){
     temp = array[i];
     array[i] = array[j];
     array[j] = temp;
    }
   }
  }
}

public int maximum(){
  if(array == null){
   return 0;
  }
  int max = array[0];
  for(int i = 0;i<array.length;i++){
   if(max < array[i]){
    max = array[i];
   }
  }

  return max;
}

public int minimum(){
  if(array == null){
   return 0;
  }
  int min = array[0];
  for(int i = 0;i<array.length;i++){
   if(min > array[i]){
    min = array[i];
   }
  }

  return min;
}

public boolean find(int item){
  if(array == null){
   return false;
  }

  for(int i = 0;i<array.length;i++){
   if(array[i] == item){
    return true;
   }
  }

  return false;
}

public int average(){
  if(array == null){
   return 0;
  }
  int avg = 0;
  for(int i = 0;i<array.length;i++){
   avg += array[i];
  }

  return avg/array.length;
}

public int getSum(){
  if(array == null){
   return 0;
  }
  int sum = 0;
  for(int i = 0;i<array.length;i++){
   sum += array[i];
  }

  return sum;
}

public void print(){
  if(array == null){
   return;
  }
  System.out.println("");
  for(int i = 0;i<array.length;i++){
   System.out.print(array[i]+" ");
  }
  System.out.println("");
}

public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  Array_1 arr = new Array_1();
  Array_1 arr1 = new Array_1();
  Array_1 arr2 = new Array_1();
  String choice = "";
  while(true){
   System.out.println("1- Create An Array ");
   System.out.println("2- Double an Array ");
   System.out.println("3- Sum the array");
   System.out.println("4- Add Two Array ");
   System.out.println("5- sort an array");
   System.out.println("6- Find maximum, minimum, average");
   System.out.println("7- Exit");
   sc.reset();
   choice = sc.next();
   char ch = choice.charAt(0);
   if(ch == '1'){
    int size;
    System.out.println("Enter a size : ");
    size = sc.nextInt();
    arr.createArray(size);
    arr.initialize(sc);
    arr.print();
   }else if(ch == '2'){
    arr.doubleArraySize();
   }else if(ch == '3'){
    int sum = arr.getSum();
    System.out.println("sum = "+sum);
   }else if(ch == '4'){
    int size;
    System.out.println("Enter a size : ");
    size = sc.nextInt();
    arr.createArray(size);
    arr1.createArray(size);
    System.out.println("Array 1 : ");
    arr.initialize(sc);
    System.out.println("Array 2 : ");
    arr1.initialize(sc);
    arr2 = arr.add(arr1);
    System.out.println("After Addition : ");
    arr2.print();
   }else if(ch == '5'){
    arr.sort();
    arr.print();
   }else if(ch == '6'){
    int max = arr.maximum();
    int min = arr.minimum();
    int avg = arr.average();
    System.out.println("Maximum = "+max+" Minimum = "+min+" Average = "+avg);
   }else if(ch == '7'){
    break;
   }
  }
  sc.close();
}


}

import java.util.Scanner;


public class Array_2{
public int[][] array;

public Array_2(int row,int col){
  createArray(row,col);
}

public Array_2(){
  array = null;
}

public void createArray(int row,int col){
  array = new int[row][col];
}

public void initialize(Scanner sc1){
  System.out.println("Enter The Array Element : ");
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    System.out.print(" "+i+" "+j+" : ");
    array[i][j] = sc1.nextInt();
   }
  }
}

public int maximum(){
  if(array == null){
   return 0;
  }
  int max = array[0][0];
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    if(max < array[i][j]){
     max = array[i][j];
    }
   }
  }

  return max;
}

public int minimum(){
  if(array == null){
   return 0;
  }
  int min = array[0][0];
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    if(min > array[i][j]){
     min = array[i][j];
    }
   }
  }

  return min;
}

public boolean find(int item){
  if(array == null){
   return false;
  }

  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    if(array[i][j] == item){
     return true;
    }
   }
  }

  return false;
}

public int average(){
  if(array == null){
   return 0;
  }
  int avg = 0;
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    avg += array[i][j];
   }
  }

  return avg/(array.length*array[0].length);
}

public int getSum(){
  if(array == null){
   return 0;
  }
  int sum = 0;
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    sum += array[i][j];
   }
  }

  return sum;
}

public void print(){
  if(array == null){
   return;
  }
  System.out.println("");
  for(int i = 0;i<array.length;i++){
   for(int j = 0;j<array[0].length;j++){
    System.out.print(array[i][j]+" ");
   }
   System.out.println("");
  }
  System.out.println("");
}

public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  Array_2 arr = new Array_2();
  String choice = "";
  while(true){
   System.out.println("1- Create An Array ");
   System.out.println("2- Print the Array ");
   System.out.println("3- Sum the array");
   System.out.println("4- Initialize the array ");
   System.out.println("5- Find maximum, minimum, average");
   System.out.println("6- Exit");
   sc.reset();
   choice = sc.next();
   char ch = choice.charAt(0);
   if(ch == '1'){
    int row,col;
    System.out.println("Enter a size(row,col) : ");
    row = sc.nextInt();
    col = sc.nextInt();
    arr.createArray(row,col);
   }else if(ch == '2'){
    arr.print();
   }else if(ch == '3'){
    int sum = arr.getSum();
    System.out.println("sum = "+sum);
   }else if(ch == '4'){
    arr.initialize(sc);
   }else if(ch == '5'){
    int max = arr.maximum();
    int min = arr.minimum();
    int avg = arr.average();
    System.out.println("Maximum = "+max+" Minimum = "+min+" Average = "+avg);
   }else if(ch == '6'){
    break;
   }
  }
  sc.close();
}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote