Given is the implementation of the class IntegeArray what we did for Assignment 5. This implementation has only one data member or attribute
private int[] arr;
If the length of the array is also added as an attribute or data member of the class as shown below, please rewrite the whole IntegerArray class implementation to reflect this new added data member of len. Complete the code given below (and submit based on the given code). No main needs to be added. Just rewrite of IntegerArray class implementation is what is needed.
public class IntegerArray {
private int[] arr;
private int len;
........
}
Here is the implementation of what we did for Assignment 5.
public class IntegerArray {
private int[] arr;
//constructor
IntegerArray(int length)
{
arr = new int [length];
}
//constructor
IntegerArray(int[] array)
{
arr = array;
}
//functions
public void printliteral()
{
System.out.print("{")
for(int k = 0 ; k < arr.length ; k++)
{
if (k>0){
System.out.print(",");
}
System.out.print(arr[k] + " ");
}
Here is code:
// Here is the implementation of what we did for Assignment 5.
public class IntegerArray {
private int[] arr;
private int len;
// constructor
IntegerArray(int length) {
this.arr = new int[length];
this.len = length;
}
// constructor
IntegerArray(int[] array) {
this.arr = array;
this.len = array.length;
}
// functions
public void printliteral() {
System.out.print("{");
for (int k = 0; k < this.len; k++) {
if (k > 0) {
System.out.print(", ");
}
System.out.print(this.arr[k]);
}
System.out.println("}");
}
}
Sample code to test:
public class IntegerArrayTest {
public static void main(String[] args) {
int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
IntegerArray i = new IntegerArray(array);
i.printliteral();
}
}
Output:

Given is the implementation of the class IntegeArray what we did for Assignment 5. This implementation...
I'm writing this class called CharArrayProject_3 that removes repeating elements from an array of chars. However, when I run the driver class, it just outputs two sets of dashed lines. What am I getting wrong? Is it the deleteRepeats() method?: public class CharArrayProject_3 { private char[] array; privateint length; privateintnumberOfRepeats; public CharArrayProject_3( char[] arr ) { length = arr.length; array = new char[ length ]; numberOfRepeats = 0; for( int k = 0; k < arr.length; k++ ) { array[k]...
I'm trying to find out what is wrong with my code? package DriverClass; public class DriveClass { public static void main(String[] args) { int a[] = {3, 2, 5, 6, 1}; InsertionSortClass insertion = new InsertionSortClass(); System.out.print("The original list : "); System.out.println(); insertion.printArray(a); System.out.println(); System.out.println("The list after insertionSort : "); System.out.println(); insertion.insertionSort(a); } } package DriverClass; public interface SortADTInterface { public void insertionSort(int arr[]); public void printArray(int arr[]); } package DriverClass; public class InsertionSortClass implements SortADTInterface{ public void insertionSort(int[] arr)...
Create an ArrayListReview class with one generic type to do the following • Creates an array list filled with the generic type of the ArrayListReview class, and inserts new elements into the specified location index-i in the list. (5 points) • Create a method inside the class to implement the calculation of Fibonacci numbers. Use System.nanoTime to find out how much time it takes to get fab(50). Create a method inside the class to check if an array list is...
C++ computer science Given the partial class HardDrive implementation below, implement all of the following: 1: default constructor that initialized the attributes with proper default data of your choice. 2: destructor() method, that releases all the dynamically allocated memory. 3: copy constructor() method: That properly manages the dynamic array when the object is passed by value to a function as a parameter. 4: overload the assignment operator: To properly handle copying the dynamic array when one object is assigned to...
Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...
Introduction In this lab we will look at the information given by thrown exceptions. In particular, we will see that a given design does not give the most useful information that it could. We will explore how to fix it. The Program We have three classes in the project. StringArray is similar to the class in the homework, with much functionality removed. Names is meant to be a collection of names that has a StringArray used to store them. It...
c++ Please write an implementation of the copy constructor. Please write an implementation of the assignment operator. Problem #3: The implementation below will CRASH because it’s missing a copy constructor and an assignment operator. #include <iostream> using namespace std; class Triangle { public: Triangle() { p = new Point[3]; } Triangle(int x1,int y1,int x2, int y2,int x3,int y3) { p = new Point[3]; p[0].x = x1; p[0].y = y1; p[1].x = x2; p[1].y = y2; p[2].x = x3; p[2].y =...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...
Problem Definition: Problem: Given an array of integers find all pairs of integers, a and b, where a – b is equal to a given number. For example, consider the following array and suppose we want to find all pairs of integers a and b where a – b = 3 A = [10, 4, 6, 16, 1, 6, 12, 13] Then your method should return the following pairs: 4, 1 15, 12 13, 10 A poor solution: There are...
must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...