Exercise #2 Implement an instance method belonging to the IntArrayBag class that takes two input parameters, oldVal and newVal. The method replaces each oldVal element in the array with newVal. Make sure to include the method header.
Q: Write a méthód called changeQueue to be considered inside the ArrayQueue class and has one parameter…
A: The program is written in Java. Check the program screenshot for the correct indentation. Please…
Q: Write a method called changeQueue to be considered inside the ArrayQueue class and has one parameter…
A: Language: JAVA Specifications: Non-Empty Queue i.e. Length > 0 Even number of elements, hence…
Q: Implement the Comparable interface in the Laptop class. When you implement the compareTo() method…
A: Java is the programming languages that always refers to the object oriented programming languages.…
Q: **/ enable all the selectors that are still available in the scoresheet */ public void…
A: Here, we are going to build the methods to enable and disable the selectors for scores. Enable…
Q: Create a class called OurArrayList and implement the following methods. Do NOT create any auxiliary…
A: Object-oriented programming languages like Java make it easy for programmers to use ADTs each ADT…
Q: Challenge exercise What are examples of other methods that the Arrays class provides?
A: To give examples of Array methods in Java. The Arrays class was introduced in Java 1.2, and its…
Q: You are familiar with ArrayList and have used it in different capacities. The most prominent feature…
A: We will solve the given problem in Java language.
Q: For this exercise, we are going to revisit the Pie superclass that we saw as an example in the last…
A: Required: For this exercise, we are going to revisit the Pie superclass that we saw as an example…
Q: Write a method that returns the index of the smallest element in an array of doubles. The method…
A: C++ Code for above : int method(double arr[], int n){ int idx = 0; double smallest =…
Q: Need help with the parts that say TODO in images , This may be needed scoresheet code below package…
A: Comments are lines of text in code that start with a specific set of characters like “//” in…
Q: Create a data class named Automobile that implements the Comparable interface. Give the class data…
A: the java program is an given below :
Q: Consider a scenario of Contacts Database, in which all information of user contacts will be stored.…
A: We will solve the given problem in Java language.
Q: This is a partially implemented class called UnsortedMapOfLists, which extends UnsortedTableMap. The…
A: Brief Introduction: We have to write a code in Python that will make sure that the gcd of numbers…
Q: Create a class called MyArrayList and implement the methods below, in addition to a main method to…
A: Note: Since no programming language is mentioned. I am attempting this in python. if you need it in…
Q: Exercise 2: Add a method boolean contains (Object obj) that checks whether the LinkedList…
A: please upvote for my efforts ! answer: 2) code: package com.company;import java.util.*;public class…
Q: Write assignments to the library, cs101, and track variables (which you defined in the previous…
A: In this problem, we will discuss about how to create appropriate array list objects.
Q: Suppose we have a method with header: public ArrayList meth (ArrayList list, int n) Which of the…
A: Template Method is a behavioral design pattern that allows you to defines a skeleton of an algorithm…
Q: Please use java. In this assignment, you will implement a class calledCustomIntegerArrayList. This…
A: import java.util.*; class CustomIntegerArrayList{ private ArrayList<Integer> arr;…
Q: Write a method called changeQueue to be considered inside the ArrayQueue class and has one parameter…
A: class ArrayQueue{ public void changeQueue(int [] queue,int item){ int n=queue.length; for(int…
Q: Write the output produced by the method when it is passed this ArrayList: [5, 17, 23, -7, -3, 11,…
A: The required output and its code with a screenshot have been provided in the next step.
Q: 2. The class PetShop has a single field as defined below: private ArrayList petList; Define a…
A: Given that petList is an ArrayList that stores cat details. private ArrayList petList can be…
Q: What are wrapper classes and why are they useful for ArrayLists? In your answer, include examples of…
A: Actually, given question regarding wrapper classes ..
Q: hat is the best way to remove duplicates from an ArrayList?
A: What is the best way to remove duplicates from an ArrayList?
Q: Make the following class generic so that it can deal with an arbitrary class rather than only Dog…
A: Given: Make the following class generic so that it can deal with an arbitrary class rather than…
Q: Add a getUnsold method to the Auction class with the -following header: public ArrayList getUnsold()…
A: lots is a field in Auction class and also mentioned this Lot object will also have highestBid field…
Q: Write a method with the name "eraser" that will get two arguments: “maparr_plants" (Map array of…
A: Here we have to provide the key for containsKey and remove methods not the indices. So the updated…
Q: this code is in java. Explore the given classes. Implement a getter method on the WasteRobot class…
A: Answer
Q: Besides the ArrayList class in Java, do you think there are other classes that are implemented with…
A: Other classes that are implemented with an array :-
Q: // Use the above method, findExactString, as a helper method to implement addWithoutDuplication…
A: /******************************************************************************…
Q: also need help Write a second constructor that takes a String array of pages as input and sets the…
A: 1- Rules of the array: Array must be initialized at the time of declaration otherwise it will throw…
Q: AVA, PLEASE THE PROGRAM SHOULD USE THE INITIAL ARRAYLIST AND TO EDIT IT NOT TO CREATE A NEW ONE…
A: JAVA program is given below
Q: Design a generic method 'sum' that accepts an array of any type such as int, double or float and…
A: Approach Here, one generic method "sum" is invoked with an array of different types such as Integer,…
Q: For this exercise, we are going to revisit the Pie superclass that we saw as an example in the last…
A: CODE import java.util.ArrayList; public class PieTester { public static void main(String[]…
Q: Make the following class generic so that it can deal with an arbitrary class rather than only String…
A: Generics mean parameterized types. The idea is to allow type (Integer, String, … etc, and…
Q: Write the same splice method for an ArrayList with member variables called data and size and methods…
A: The method splice is used to modify the contents of an arraylist , this has the following parameters…
Q: Q1: Write the Java code corresponding to the following UML diagram. The class School implements the…
A: Algorithm: Start Implement an interface Building with methods computeArea() and toString() Create a…
Q: Make the following class generic so that it can deal with an arbitrary class rather than only Dog…
A: Java program to solve the given problem is below.
Q: Based on the information in the screenshots, please answer the following question below. The…
A: Answer is given below .
Q: Challenge exercise Create a class called SortingTest. In it, create a method that accepts an array…
A: Since programming language not mentioned, using C++.
Q: 4. Now examine the ArrayList methods in the above table, a) Which method retrieves elements from…
A: ArrayList is a re-sizable list used to store objects in java lets understand the methods given:…
Q: Write a Java class Course for dealing with courses. Your class must have the following features:…
A: Program Approach: 1- As per the assignment requirement, create all the classes as mentioned in the…
Q: Design and implement an insertSorted() method for the MyArrayList class. The method should receive a…
A: public class MyArrayList<E> { private int size; private E[] data;…
Q: Define a class StatePair with two generic types (Type1 and Type2), a constructor, mutators,…
A: I have mentioned code in step 2, please find in below
Q: Implement a Menu-Driven program of ArrayList class using the above scenario and perform the…
A: Answer
Q: You are being asked to create a (Comparable) data class Student that will be used to maintain…
A: The main function which actually takes the user input is placed under the StudentRecord Class.…
Q: Task-02: Implement the following UML class diagram and test the methods. GeometricObject…
A: Program: import java.util.Scanner; import java.lang.Math; public class AreaOfCircle…
Exercise #2
Implement an instance method belonging to the IntArrayBag class that takes two input parameters, oldVal and newVal. The method replaces each oldVal element in the array with newVal. Make sure to include the method header.
Logic:-
Define array elements .
Read oldVal and newVal
pass arrayName,oldVal and newVal to method instance.
In method definition, iterate from i=0 to i<arrayName.length
Check if arrayName[i]==oldVal
ArrayName[i]=newVal
End loop
In main display newArray elements.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- This lab was designed to reinforce programming concepts from this lab, you will practice: Declaring and initializing ArrayList. Add elements to the Arraylist. Display the content of the ArrayList. Write a class name PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and the appropriate accessor and mutator methods. Then write a program that creates at least 5 PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.Library class: Fields: books as arraylist to store all the books available in the library B3 B1 B2 В4 B5 Constructor: Library() } : No parameterized constructor to create the books object Methods: 1. addBook(Book bookobj): to add a new book to the arraylist; send the book object as a parameter to this method. 2. searchBook(String name): search a book by a given name in the arraylist. if exits print bookX found; otherwise print not found!!! 3. RemoveBook(String name): to delete a book object from arraylist by a given name: Hint: you need to use iterator class and remove method. Book class: Fileds: bookld, bookname. Constructor: two parameterized constructor that accepts name a parameter Book(int ID, String name) ..... Methods: 1. Accessor method to return the name of the book 2. Mutator method to change the id of the book. Use this Main method: in your program: public static void main(String args[]) { Library lib=new Library(); lib.addBook(new Book("b1")); lib.addBook(new Book("b2"));…JavaDriver Program Write a driver program that contains a main method and two other methods. Create an Array of Objects In the main method, create an array of Food that holds at least two foods and at least two vegetables. You can decide what data to use. Method: Print Write a method that prints the text representation of the foods in the array in reverse order (meaning from the end of the array to the beginning). Invoke this method from main. Method: Highest Sugar Food Write a method that takes an array of Food objects and finds the Food that has the most sugar. Note that the method is finding the Food, not the grams of sugar. Hint: in looping to find the food, keep track of both the current highest index and value. Invoke this method from main.
- Task 4. Utility classes Implement a Menu-Driven program of ArrayList class using the above scenario and perform the following operations. Create an object of ArrayList class based on the scenario with explanations of the method Create a method that will allow inserting an element to ArrayList Class based on the scenario. The input field must be validated as Create a method to delete specific elements in the ArrayList with explanations of the methodObserver pattern The PhoneModel class stores a phone number as a list of digits, and the Keypad class has this method: public void simulateKeyPresses(int numKeyPresses)(0 that allows the user to enter digits one at a time then save each digit in the list. The Screen wants to respond to each key being entered. Make the model notify the observers whenever a new digit is entered for the phone number. The first observer prints the newest digit out to the screen The second observer prints "Now dialing 12345678901.." out to the screen (where the number is the number the model has). Only the Screen class can print to the screen The model must be decoupled from the Other classes.Using java Hamburger ClassWrite a Hamburger class with the following six attributes:• bun - the type of bun the burger will be on• patties - the number of patties on the burger• cheese - whether or not the burger will have cheese• price - the price of the burger• toppings - an array of five toppings; it will need to start empty Write getters/setters for all attributesexcept the toppings array.Your constructor should create a single on white with no cheese and no toppings with a price of $2.99.Your class should include the following methods in this order, please: addCheese - this method has noparameters that adds cheese to the burger and increases the price by 75 centssuperSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.50addToppings - this method would present the user with at least five toppings (your choice) stored in an array of Stringobjects. If the user indicates the wants the item, store the String in the toppings array. There…
- 1. Square Roots Create a class with a method that, given an integer, returns an array of double-precision floating point numbers (known in Java as double), each of which is a square root of a number between 2 and the parameter to the method. For example, if the parameter is 5, the method should return an array of 4 doubles, with approximate values 1.4142135623, 1.7320508075, 2.0, and 2.2360679774. Your method should check the validity of the parameter, and take appropriate action if the parameter is invalid. 2. Reading Files Create a class with a method that, given a string representing a file name, returns an integer with the number of characters in the file. For example, if the file has 10 characters, your method must return the number 10. 3. Main Class Create a class HW1.java with a main method that does both of the following: calls the method from part 1 with a random integer between 0 and 10, and prints each of the numbers in the result. The numbers should all be printed on the…JAVA Include Code Comments create a public class named ArrayUtility In ArrayUtility class, create a public static method toString that receives an array of int's, a start string, a separator string and an end string. It returns a String starting with the start string, followed by the array elements separated by the separator and ending with the end string. create a public class named ArrayUtilityTest In ArrayUtilityTest class, create a public static method toStringTest that prints the results for the following 5 lengths of arrays, using different types of brackets and separators for each: empty, singleton, two elements, 5 elements and 20 elements. Call only this class in the main method and check the results. In ArrayUtility class, create a public static method equals that receives two arrays of int's and returns true if they have the same length and equal corresponding elements. In ArrayUtilityTest class, create a public static method equalsTest that prints the results for the…Code a called method that takes two parameters, an array of double as reference type and a double value. In the method, manipulate the argument by incrementing the value of the array. Note that you are not required to manipulate the entire array.
- Create a MagicalPotionShop class, this class needs a field called potions. The potions field should be an ArrayList of the type Potion. Create a MagicalPotion class, this class needs two fields one called name, the other called effect. Both of the fields should be Strings.Part-2: Write a program that includes in its MainClass the following methods: 1. A method called printArray that takes an array of double values and prints its elements in their original order on the same line with one space between each two elements. The method should print a new line after printing the array elements. 2. A method called greaterThan that takes a double value and an array of doubles as parameters and returns the number of array elements that are greater than or equal the passed double value. 3. A method called reverseArray that takes an array of doubles and reverses the order of the array elements. Note that this method must not create a new array, it must reverse the array in its place. For example, if the passed array is 6.1, 2.5, 5.3, 1.7, 8.3, after invoking the method the array must become: 8.3, 1.7, 5.3, 2.5, 6.1 4. A method called addNumbers that takes an array of doubles, and a variable length argument list of doubles. The method must return a new array that…Elevator simulation. I need help fixing this class The Simulation Class initializes and holds objects for Passengers, Elevators, and Floors. It reads and parses input files to create the necessary objects and sets the number of simulation iterations. The class also has methods to move the elevators up and down the building, as well as to pick up and drop off passengers. public class Simulation { private int numFloors; private ArrayList<Passenger> passengers; private ArrayList<Elevator> elevators; private ArrayList<Floor> floors; private int numIterations; public Simulation(String inputFile) throws FileNotFoundException { passengers = new ArrayList<>(); elevators = new ArrayList<>(); floors = new ArrayList<>(); // Read input file and initialize simulation parameters Scanner scanner = new Scanner(new File(inputFile)); while (scanner.hasNextLine()) { String line =…