1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
k0ka [10]
2 years ago
8

Build three classes that conform to the following interfaces. Use arrays in creating your classes (e.g., do not use the built-in

ArrayList class when creating the ArrayList-like interface). Extend the sample driver below to completely test the FIFO nature of a Queue, the LIFO nature of a stack and the arbitrary inserts and removes in an ArrayList-like structure.
Computers and Technology
1 answer:
daser333 [38]2 years ago
6 0

Explanation:

public class ArrayList {

private Object[] array = new Object[1];

/**

 * Places new element at location

 * @param c, element to be inserted

 * @param i, location it is to be placed

 */

public void insert(char c, int i) {

 if(i>this.size()){

  System.out.println("Index "+i +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 int count = 0;

 try {

  Object[] other = new Object[this.array.length+1];

  switch(i){

     case 0:{

      other[0] = c;

      for(int j=1;j<this.array.length;j++)

       other[j] = this.array[j-1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<i;j++)

       other[j] = this.array[j];

      other[i] = c;

      for(int k=i+1;k<this.array.length;k++)

       other[k] = this.array[k-1];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

}

 

/**

 * Places new element at location

 * @param object, element to be inserted

 * @param index, location it is to be placed

 */

void insert(Object object, int index){

 if(index>this.size()){

  System.out.println("Index "+index +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 int count = 0;

 try {

  Object[] other = new Object[this.array.length+1];

  switch(index){

     case 0:{

      other[0] = object;

      for(int j=1;j<this.array.length;j++)

       other[j] = this.array[j-1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<index;j++)

       other[j] = this.array[j];

      other[index] = object;

      for(int k=index+1;k<this.array.length;k++)

       other[k] = this.array[k];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

}

 

/**

 * Removes element at index

 * @param index, location to remove

 * @return temp, object removed

 */

Object remove(int index){

 if(index>this.size()){

  System.out.println("Index "+index +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 Object temp = this.array[index];

 int count = 0;

 try {

  Object[] other = new Object[this.array.length-1];

  switch(index){

     case 0:{

      other[0] = this.array[1];

      for(int j=1;j<this.size();j++)

       other[j] = this.array[j+1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<index;j++)

       other[j] = this.array[j];

      for(int k=index;k<this.size();k++)

       other[k] = this.array[k+1];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

 return temp;

}

 

/**

 * Copies the array to a new array twice the size.

 */

public void largerArray(){

 Object[] other = new Object[this.array.length*2];

 System.arraycopy(this.array, 0, other, 0, this.array.length);

 this.array = other;

}

 

/**

 * @return true if there are null elements

 */

public boolean isEmpty() {

 boolean bool = true;

 for (Object element : this.array) {

  if(element!=null){

   bool = false;

   break;

  }

  else{

   bool = true;

   break;

 }

 }

 return bool;

}

 

/**

 * Determines the real length of the array

 * @return length of non-null elements

 */

public int size(){

 int count = 0;

 for(int i=0;i<this.array.length;i++){

  if(this.array[i]==null)

   continue;

  else

   count++;

 }

 return count;

}

 

/**

 * Converts array to string.

 * @return the Array as a string

 */

public String toString(){

 String string = "";

 for(int i=0;i<this.size();i++){

  if(i<this.size()-1)

   string += this.array[i]+", ";

  else

   string += this.array[i];

 }

 return string;

}

 

/**

 * Similar to get, imput the character, retrieve index.

 * @param object, what we're looking for

 * @return index

 */

int indexOf(Object object){

 int index = -1;

 for(int i=0;i<this.array.length;i++){

  if(this.array[i]==(object))

   index = i;

  else continue;

 }

 return index;

}

 

/**

 * @param object, Arraylist tyoe

 * @return true, if the elements of the arrays are equivalent.

 */

public boolean equals(ArrayList object){

 boolean bool = false;

 int thisLength = this.array.length;

 int objectLength = object.array.length;

 if(thisLength > objectLength){

  for(int i=0;i<this.array.length;i++)

   if(this.array[i] == object.array[i])

    bool = true;

   else{

    bool = false;

    break;

   }

 }

 else{

  for(int i=0;i<object.array.length;i++)

   if(this.array[i] == object.array[i])

    bool = true;

   else{

    bool = false;

    break;

   }

 }

 return bool;

}

 

/**

 * Getter to check what is at an index

 * @param index, location

 * @return the character at this position

 */

Object get(int index){

 return this.array[index];

}

}

You might be interested in
Can someone that been helping me answer one more question for please and thx
Gnom [1K]

Answer:

D

Explanation:

Federal Tax, not state

5 0
3 years ago
1. Which of the following options will allow you to insert a quick table? (1 point) Insert ribbon &gt; Shapes drop-down menu
emmasim [6.3K]
Quick tables are tables<span> that are stored in galleries as building blocks and can be reused and accessed at any time.</span>
The following option will allow you to insert a quick table:
Insert ribbon -> Table drop-down menu

Yous should click on the ribbon (tab) Insert and then from the Table drop-down in the Tables group, select Quick Tables.
5 0
3 years ago
Read 2 more answers
Rachel typed two paragraphs and then realized she was in the wrong document. What steps should Rachel follow to quickly move the
igomit [66]
It would be A. I hope that this helps!
6 0
2 years ago
Read 2 more answers
Match the steps with the actions that are involved when an internal host with IP address 192.168.10.10 attempts to send a packet
Anna35 [415]

Answer:

Following are the steps with actions that are involved in required to perform a packet transfer.

Explanation:

  • Step 1: The host sends a connection request to server which is at IP address 209.165.200.254
  • Step 2: R1 check the configuration of NAT to inquire weather the packet should be translated or not.
  • Step 3: If there is no entry found for translation of given IP address, It is assumed that the IP address 192.168.10.10  will be translated already.
  • Step 4: R1 selects a global address  from the dynamic address pool that is available to it.
  • Step 5: R1 replaces the given IP address 192.168.10.10  with the translated inside global address.

i hope it will help you!

5 0
2 years ago
The following program is supposed to display a message indicating if the integer entered by the user is even or odd. What is wro
Lapatulllka [165]

Answer:

A. The function definition must appear before the function is called

Explanation:

Given

The above lines of code

Required

Determine the error in the program

In python, functions has be defined before they are called but in this case (of the given program), the function is called before it was defined and this will definitely result in an error;

<em>Hence, option A answers the question</em>

The correct sequence of the program is as follows:

<em>def evenOdd(n): </em>

<em>      if n % 2 == 0: </em>

<em>            return "even" </em>

<em>      return "odd" </em>

<em>num = int(input("Enter an integer: ")) </em>

<em>print("The integer is", evenOdd(num)) </em>

<em />

6 0
2 years ago
Other questions:
  • All of the following statements correctly describe an advantage or disadvantage associated with the use of Monte Carlo Analysis
    9·1 answer
  • You can pin applications to which two areas?
    11·1 answer
  • Which of the following is a social news-sharing service?
    10·2 answers
  • What component of effective feedback is demonstrated by giving examples of what an employee is doing right instead of just prais
    14·2 answers
  • Mobile phones that function as credit cards are called _____.
    11·1 answer
  • Give an O(log m + log n)-time algorithm that takes two sorted lists of sizes m and n, respectively, as input and returns the ith
    7·1 answer
  • Interactive television with video-on-demand capabilities changes how people watch television and how consumers access the Intern
    8·1 answer
  • What is software piracy?
    11·1 answer
  • Which 1947 Invention paved the way for the Digital Revolution?
    12·2 answers
  • You're doing desktop support and the company policy is that you can only help with company equipment. A user walks in:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!