
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
HELP WITH EXAMPLES OF THE METHODS, IN THE TODO
package integerarraylist;
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
class CustomIntegerArrayListTest {
@Test
void testGetArrayList() {
//create a new empty CustomIntegerArrayList
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(0, 5);
arr1.add(1, 5);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(0, 5);
lst1.add(1, 5);
assertEquals(lst1, arr1.getArrayList());
ArrayList<Integer> arr4Elements = new ArrayList<Integer>();
arr4Elements.add(100);
arr4Elements.add(200);
arr4Elements.add(500);
//create a new CustomIntegerArrayList with the elements in the given ArrayList
CustomIntegerArrayList arr4 = new CustomIntegerArrayList(arr4Elements);
ArrayList<Integer> lst4 = new ArrayList<Integer>();
lst4.add(100);
lst4.add(200);
lst4.add(500);
assertEquals(lst4, arr4.getArrayList());
// TODO write at least 3 additional test cases
}
@Test
void testGet() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(0, 5);
arr1.add(1, 5);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(0, 5);
lst1.add(1, 5);
assertEquals(lst1.get(0), arr1.get(0));
assertEquals(lst1.get(1), arr1.get(1));
assertEquals(lst1.get(2), arr1.get(2));
// TODO write at least 3 additional test cases
}
@Test
void testAddInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(3);
arr1.add(4);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(3);
lst1.add(4);
assertEquals(lst1.get(0), arr1.get(0));
assertEquals(lst1.get(1), arr1.get(1));
assertEquals(lst1.get(2), arr1.get(2));
// TODO write at least 3 additional test cases
}
@Test
void testAddIntInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(0, 2);
arr1.add(0, 3);
arr1.add(0, 4);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(0, 2);
lst1.add(0, 3);
lst1.add(0, 4);
assertEquals(lst1.get(0), arr1.get(0));
assertEquals(lst1.get(1), arr1.get(1));
assertEquals(lst1.get(2), arr1.get(2));
// TODO write at least 3 additional test cases
}
@Test
void testRemoveInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(0, 2);
arr1.add(0, 3);
arr1.add(0, 4);
arr1.remove(0);
arr1.remove(1);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(0, 2);
lst1.add(0, 3);
lst1.add(0, 4);
lst1.remove(0);
lst1.remove(1);
assertEquals(lst1.get(0), arr1.get(0));
// TODO write at least 3 additional test cases
}
@Test
void testRemoveIntInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(0, 2);
arr1.add(0, 3);
arr1.add(0, 3);
arr1.add(0, 3);
arr1.add(0, 3);
arr1.add(0, 4);
arr1.remove(3, 3);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(0, 2);
lst1.add(0, 3);
lst1.add(0, 4);
assertEquals(lst1, arr1.getArrayList());
// TODO write at least 3 additional test cases
}
@Test
void testSpliceIntInt() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(3);
arr1.add(4);
arr1.add(5);
arr1.add(6);
arr1.splice(3, 2);
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(3);
lst1.add(4);
assertEquals(lst1.get(0), arr1.get(0));
assertEquals(lst1.get(1), arr1.get(1));
assertEquals(lst1.get(2), arr1.get(2));
// TODO write at least 3 additional test cases
}
@Test
void testSpliceIntIntIntArray() {
CustomIntegerArrayList arr1 = new CustomIntegerArrayList();
arr1.add(2);
arr1.add(3);
arr1.add(4);
arr1.add(5);
arr1.add(6);
arr1.splice(3, 1, new int[] { 4, 5 });
ArrayList<Integer> lst1 = new ArrayList<Integer>();
lst1.add(2);
lst1.add(3);
lst1.add(4);
lst1.add(4);
lst1.add(5);
lst1.add(6);
assertEquals(lst1, arr1.getArrayList());
// TODO write at least 3 additional test cases
}
}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 6 images

Knowledge Booster
Similar questions
- Add the method below to the parking office.java class. Method getParkingCharges(Customer) : Money Parkingoffice.java public class ParkingOffice {String name;String address;String phone; List<Customer> customers;List<Car> cars;List<ParkingLot> lots;List<ParkingCharge> charges; public ParkingOffice(){customers = new ArrayList<>();cars = new ArrayList<>();lots = new ArrayList<>();charges = new ArrayList<>();}public Customer register() {Customer cust = new Customer(name,address,phone);customers.add(cust);return cust;}public Car register(Customer c,String licence, CarType t) {Car car = new Car(c,licence,t);cars.add(car);return car;}public Customer getCustomer(String name) {for(Customer cust : customers)if(cust.getName().equals(name))return cust;return null;}public double addCharge(ParkingCharge p) {charges.add(p);return p.amount;} public String[] getCustomerIds(){String[] stringArray1 = new String[2];for(int i=0;i<2;i++){stringArray1[i]…arrow_forwardpackage edu.umsl.iterator;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Iterator;public class Main {public static void main(String[] args) {String[] cities = {"New York", "Atlanta", "Dallas", "Madison"};Collection<String> stringCollection = new ArrayList<>(Arrays.asList(cities));Iterator<String> iterator = stringCollection.iterator();while (iterator.hasNext()) {System.out.println(/* Fill in here */);}}} Rewrite the while loop to print out the collection using an iterator. Group of answer choices iterator.toString() iterator.getClass(java.lang.String) iterator.remove() iterator.next()arrow_forwardjavaarrow_forward
- import java.util.HashSet; import java.util.Set; // Define a class named LinearSearchSet public class LinearSearchSet { // Define a method named linearSearch that takes in a Set and an integer target // as parameters public static boolean linearSearch(Set<Integer> set, int target) { // Iterate over all elements in the Set for () { // Check if the current value is equal to the target if () { // If so, return true } } // If the target was not found, return false } // Define the main method public static void main(String[] args) { // Create a HashSet of integers and populate integer values Set<Integer> numbers = new HashSet<>(); // Define the target to search for numbers.add(3); numbers.add(6); numbers.add(2); numbers.add(9); numbers.add(11); // Call the linearSearch method with the set…arrow_forwardThe implementations of the methods addAll, removeAll, retainAll, retainAll, containsAll(), and toArray(T[]) are omitted in the MyList interface. Implement these methods. Use the template at https://liveexample.pearsoncmg.com/test/Exercise24_01_13e.txt to implement these methods this the code i have for the write your own code part import java.util.Iterator; interface MyList<E> extends java.util.Collection<E> { void add(int index, E e); boolean contains(Object e); E get(int index); int indexOf(Object e); int lastIndexOf(E e); E remove(int index); E set(int index, E e); void clear(); boolean isEmpty(); Iterator<E> iterator(); boolean containsAll(java.util.Collection<?> c); boolean addAll(java.util.Collection<? extends E> c); boolean removeAll(java.util.Collection<?> c); boolean retainAll(java.util.Collection<?> c); Object[] toArray(); <T> T[] toArray(T[] a); int size();} and its…arrow_forwardpublic class PokerAnalysis implements PokerAnalyzer { privateList<Card>cards; privateint[]rankCounts; privateint[]suitCounts; /** * The constructor has been partially implemented for you. cards is the * ArrayList where you'll be adding all the cards you're given. In addition, * there are two arrays. You don't necessarily need to use them, but using them * will be extremely helpful. * * The rankCounts array is of the same length as the number of Ranks. At * position i of the array, keep a count of the number of cards whose * rank.ordinal() equals i. Repeat the same with Suits for suitCounts. For * example, if your Cards are (Clubs 4, Clubs 10, Spades 2), your suitCounts * array would be {2, 0, 0, 1}. * * @param cards * the list of cards to be added */ publicPokerAnalysis(List<Card>cards){ this.cards=newArrayList<Card>(); this.rankCounts=newint[Rank.values().length]; this.suitCounts=newint[Suit.values().length];…arrow_forward
- Java this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…arrow_forwardGiven an array of numbers, and an integer, find the last index that that integer appears in the array. If the number is not found, return -1. import java.util.ArrayList;public class LastIndexFound{public static int solution(ArrayList<Integer> nums, int numToFind){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;}}arrow_forwardQuestion 16 What is output? import java.util.ArrayList; public class SimpleCar { @Override public String toString(){ return "I drive fast"; } public static void main(String[] args) { ArrayList myStuff; myStuff = new ArrayList(); myStuff.add(new String("Greetings")); myStuff.add(new Object()); myStuff.add(new SimpleCar()); for(Object item : myStuff) { System.out.println(item.toString()); } String Object SimpleCar java.lang.Object@19cc java.lang.Object@23fb java.lang.Object@ab79 java.lang.String@169b java.lang.Object@23fb java.lang.SimpleCar@a42b Greetings java.lang.Object@169b I drive fast }arrow_forward
- Please use the template provided below and make sure the output matches exactly. import java.util.Scanner;import java.util.ArrayList; public class PhotoLineups { // TODO: Write method to create and output all permutations of the list of names. public static void printAllPermutations(ArrayList<String> permList, ArrayList<String> nameList) { } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> nameList = new ArrayList<String>(); ArrayList<String> permList = new ArrayList<String>(); String name; // TODO: Read in a list of names; stop when -1 is read. Then call recursive method. }}arrow_forwardimport javax.swing.*; import java.util.ArrayList; import java.util.Collections; import java.util.Random; import java.awt.*; import java.awt.event.*; public class memory extends JFrame implements ActionListener { private JButton[] cards; private ImageIcon[] icons; private int[] iconIDs; private JButton firstButton; private ImageIcon firstIcon; private int numMatches; public memory() { setTitle("Memory Matching Game"); setSize(800, 600); setLayout(new BorderLayout()); JPanel boardPanel = new JPanel(new GridLayout(4, 4)); add(boardPanel, BorderLayout.CENTER); icons = new ImageIcon[8]; for (int i = 1; i <= 8; i++) { icons[i-1] = new ImageIcon("image" + i + ".png"); } iconIDs = new int[16]; for (int i = 0; i < 8; i++) { iconIDs[2*i] = i; iconIDs[2*i+1] = i; } Random rand = new Random(); for (int i = 0; i < 16;…arrow_forwardNeed help with menu loop pleasearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY