Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.AbstractList; import java.util.List; import java.util.RandomAccess; import java.lang.RuntimeException; import java.util.Arrays; public class Vector extends AbstractList implements List , RandomAccess { protected Object[] data; protected int

import java.util.AbstractList; import java.util.List; import java.util.RandomAccess; import java.lang.RuntimeException; import java.util.Arrays;

public class Vector extends AbstractList implements List, RandomAccess { protected Object[] data; protected int size;

public int size() { return size; } private void rangeCheck(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(""); } @SuppressWarnings("unchecked") private E data(int index) { return (E) data[index]; } private void grow() { int newCapacity = data.length*2; data = Arrays.copyOf(data, newCapacity); } public Vector() { this(10); } public Vector(int initialCapacity) { data = new Object[initialCapacity]; size = 0; } public E get(int index) { rangeCheck(index); return data(index); } public E set(int index, E element) { rangeCheck(index); E oldValue = data(index); data[index] = element; return oldValue; } public boolean add(E element) { if (size == data.length) grow(); data[size++] = element; return true; } public void add(int index, E element) { // Add element at index. } public E remove(int index) {

// Remove the element at index. Make sure there are no gaps // Return the removed element } public int indexOf(Object o) {

// Returns the index of the first occurrence of the specified element // in this list, or -1 if this list does not contain the element. } public static void main(String[] args) { Vector intlist = new Vector(); Vector stringlist = new Vector(); Vector> intveclist = new Vector>();

for (Integer i = 0; i < 10; i++) { intlist.add(i); }

System.out.println(intlist.indexOf(7)); System.out.println(intlist.indexOf("seven")); } }

PLEASE EDIT THIS CODE IN THE COMMENTS OF LAST 3 METHODS. COMMENTS TELL YOU WHAT TO DO. IT'S IN JAVA PROGRAMMING LANGUAGE.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

Why do nonverbal communication systems vary across cultures?

Answered: 1 week ago

Question

Write short notes on Interviews.

Answered: 1 week ago