Given the following code and assuming ArrayStackis a generic class: bool ArrayStack::doSomething() { bool result false ; if (!isEmpty()) { top--; result true ; } return result; } What method is this? pop() peek() virtual destructor default constructor
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: Write a generic class that stores two elements of the same type and can tell the user which one is…
A: Programs: The programs contain certain lines of code, that is the instructions given to the computer…
Q: Select the best code to utilize generics so that the class implements the Comparable interface…
A: Answer :
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: 1. Write a generic method selectionSort.
A: Hello student Greetings Hope you are doing great As per our policy guidelines, in case of multiple…
Q: Using generics appropriately, write a static method which will count the number of times an element…
A: Put Below Code In Your Count.java file Code class Count{ public static < E > int count(…
Q: Write a method called swapltems to be considered within the SingleLinkedList class that takes two…
A: PROGRAM INTRODUCTION: Import the required libraries. Create the variable of type linked list that…
Q: Write the following two generic methods using merge sort.The first method sorts the elements using…
A: Comparable interface:A comparable object allows comparison with another object. The class should…
Q: Write the following two generic methods using bubblesort. The first method sorts the elements using…
A: Programming Approach: Importing the package java.util.Comparator Defining the class Bubble_sort…
Q: Provide a static method that reverses the elements of a generic array list, without modifying the…
A: import java.util.ArrayList;class ArrayListUtil {public static ArrayList<String>…
Q: 7. Given an integer array of size Score CAPACITY, override the method getNext () and hasMore ().…
A: PROGRAM CODE: ArrayList.java package arrays; import java.util.AbstractList; /*** This defines the…
Q: Write the following two generic methods using quick sort.The first method sorts the elements using…
A: PROGRAM: //Importing the required header file import java.util.Comparator; //Defining the class…
Q: Write a method called sumMaxmin to be included in the class ArrayQueue that accepts a parameter q2…
A: To find the sum of minimum element of current class array and maximum element of the ArrayQueue…
Q: Write a method called swapltems to be considered within the SingleLinkedList class that takes two…
A: size() : to find the size of LinkedList get(index) : to get the element/value at particular position…
Q: Select the best code to utilize generics so that the class implements the Comparable interface…
A: Java Comparable interface is used to order the objects of the user-defined class. The interface is…
Q: public class FinalHashMap { 1 private final Map map = new HashMap(); 2 public static void…
A: public class FinalHashMap { 1 private final Map map = new HashMap(); 2 public static void…
Q: Provide a static method that checks whether a generic array list is a palindrome; that is, whether…
A: Program code: import java.util.*;import java.lang.*;import java.io.*;//define the class…
Q: mplement a static generic method named problem4_1s Decreasing thá eneric list and returns true if it…
A: In this question, we are asked to write a generic program that checks whether a list is in…
Q: Write a static method named negListFromQueue that takes two parameters: an array-based unbounded…
A: Given that, Write a static method named negListFromQueue that takes two parameters: an array-based…
Q: We have been working on a software where we use a class which can hold collections of valus of…
A: Answer: I have done code and also I have attached code.
Q: If a method given an ArrayList as a parameter calls a second method giving it the same ArrayList,…
A: The answer is given below.
Q: public GenericCollection cut(int k) { //this method cuts the current //GenericCollection object such…
A: Program Plan: The value of count is initialized to 0 Initialize a temporary node (i,e) temp1 to…
Q: Given a generic Bucket class, select each of the following that are possible (e.g., exhibit correct…
A: Answer: ii and iii public void setField1( T field1 ){ ... } and public T getField1(){ ... }
Q: We have been working on a software where we use a class whih can hold collections of data types, and…
A: The answer is given below:-
Q: Write Java code to create a generic class that stores two generic objects. Create an instance of…
A: Answer is given below-
Q: reate a class called RemoveDuplicates that takes a LinkedList of colors (represented using Strings)…
A: Use a variable called duplicateCount and set it when removeDuplicates is called
Q: Write a method called swapltems to be considered within the SingleLinkedList class that takes two…
A: Java code to perform the given question is detailed in below with comments and output screenshot.
Q: Java Problem: Write a generic isEqualTo that compares its two arguments/paramaters with the equals…
A: Answer: Java Source Code: Method 1 (Generic Method): import java.util.*;public class Main{ public…
Q: // Use the above method, findExactString, as a helper method to implement addWithoutDuplication…
A: /******************************************************************************…
Q: Write a method called swapltems to be considered within the SingleLinkedList class that takes two…
A: NOTE: Since you have not provided the code for singleLinkedList class so i will assume the code…
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: JAVA PROGRAMMING Write a generic isEqualTo that compares its two arguments/paramaters with the…
A: import java.util.*;public class Main{ public static boolean isEqual(String str1, String…
Q: Write a method called SwapMaxMin to be included in the class SingleLinkedList that accepts a…
A: Required: Write a method called SwapMaxMin to be included in the class SingleLinkedList that…
Q: A bill is characterized by number(unique), date, sum, issuer. In main method add 3 bills to a…
A: ANSWER: Program 1:
Q: Write a generic method to perform linearSearch on array of objects. Name the file…
A: Linear search algorithm traverses through the given list sequentially and checks every element of…
Q: Implement a static generic method named problem3_reverse that takes as a parameter a generic list,…
A: In this question, we are asked to write a generic method in java so that it returns Given Partially…
Q: Consider a declaration of a generic method compute: public static > void compute(T[] data) { .. }
A: Generic Generic is referred to as the parameterized type. This is to allow data type(string, float,…
Q: Now create a generic class PersonSet that has one attribute that is a TeeSet of generic type T. Your…
A: Java used to answer this question
Q: Write a non-generic method findAndRemoveLargest (StackClass myStack) that finds and removes the…
A: output should be -373 if my stack is empty.
Q: Make this generic, instead of a Stack of Pancake. public class Stack { private ArrayList…
A: Stack in java programing
Q: Write the following two generic methods using insertionsort. The first method sorts the elements…
A: PROGRAM: //import the required packages import java.util.Arrays; import java.util.Comparator;…
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: Write a method called swapItems to be considered within the SingleLinkedList class that takes two…
A: NOTE: Here you have not provided the singlelinkedlist class hence i am creating it on my own and…
Q: following proced Iist passed as a paramet public static void foo( List myList) { int theSize =…
A: Here in this question we have given a code segment and we have asked to find the running time…
Q: Assume the following tester code (see Figure 1) is in the main class that produces the output shown…
A: import java.util.*;public class Main{ public static void present(Object [] arr){ // print the data…
Q: Revise Heap , using a genericparameter and a Comparator for comparing objects. Define the class as…
A: Program Approach: Import the necessary package, in this , import .comparator . Declare main method…
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- import java.util.ArrayList; public class Bus { privateStringname; privateintsize; privateintbasePrice; privateArrayList<Trip>approvedTrips; privateintlevel;// 1,2,3 for low,medium, high repectively; privateintid; privatestaticintnextId=0; privateMinistrymny; protectedStringtripTypes; privateintgetNextId(){ returnnextId++; } publicBus(){ approvedTrips=newArrayList<Trip>(); } publicBus(Stringname,intsize,intbasePrice,intlev,Ministrymny){ approvedTrips=newArrayList<Trip>(); this.name=name; this.size=size; this.basePrice=basePrice; this.level=lev; this.id=getNextId(); this.mny=mny; tripTypes="BASICTRANSPORT"; } publicbooleanavailable(Datedate){ booleanretval=true; for(Tript:approvedTrips) if(t.getDate().getDay()==date.getDay()) retval=false; returnretval; } publicintgetBasePrice(){ returnbasePrice; } publicintgetId(){ returnid; } publicStringgetName(){ returnname; } publicdoublegetSize(){ returnsize; } publicStringtoString(){ returnname; }…Create a SameItem Interface: The SameItem interface will be a generic interface.SameItem will have a single method: isSameAs(T) that returns a booleanThis class stores an ArrayList of Tile objects, sorts them, and returns them via .toString() import java.util.ArrayList; class Rack{ private ArrayList<Tile> tiles; public Rack() { tiles = new ArrayList<Tile>(); } public void addTile(Tile t) { tiles.add(t); } DO NOT CHANGE THE CODE ABOVE. ADD THE FOLLOWING METHODS: .toString() .sortHighToLow() You may also add any helper methods you want, such as swapvalues. Make sure to write the Selection Sort algorithm like in the class example, but using the Tile object's .compareTo method.
- import java.util.ArrayList; class Rack { privateArrayList<Tile>tiles; publicRack() { tiles=newArrayList<Tile>(); } publicvoidaddTile(Tilet) { tiles.add(t); } /* DO NOT CHANGE THE ABOVE CODE. YOUR JOB IS TO ADD THE FOLLOWING METHODS: .toString() .sortHighToLow() You may also add any helper methods you want, such as swapValues. Note that we want to sort Tiles from highest value to lowest */public interface Rational { /** Determines whether this Rational object represents a value less than one. * @return true if this Rational is less than 1, false else public boolean islessThanOne (); } Write the class Goo that implements this interface. Goo must use an array. Your answer must include all necessary fields and any additional private methods as needed for your implementation. You may not use ArrayList, or any similar class.NOTE: DO NOT COPY FROM ANOTHER QUESTION Directions: 1. Show the ArrayStackADT interface 2. Create the ArrayStackDataStrucClass<T> with the following methods: default constructor, overloaded constructor, copy constructor, initializeStack, isEmptyStack, isFullStack, push, peek, void pop 3. Create the PrimeFactorizationDemoClass: instantiate an ArrayStackDataStrucClass<Integer> object with 50 elements. Use a try-catch block in the main( ) using pushes/pops. 4. Exception classes: StackException, StackUnderflowException, StackOverflowException5. Show the 4 outputs for the following: 3,960 1,234 222,22213,780
- Java Programming Class Car Attributes (all private): vin: String (5 digits) make: String model: String year: int price: double Methods: Parameterized constructor for initializing a new Car instance Getters for all attributes toString method to display a Car's attributes Executable Class Create an array of at least ten Car objects. Be sure to use many with identical last years and different prices. Create an ArrayList from the array. Shuffle the ArrayList. Sort the ArrayList first by year and then by price. See page 790-791. Using the forEach method and a lambda expression, print all cars sorted as above. Create a LinkedList from the ArrayList. Create an iterator capable of cycling both forward and backward through the LinkedList. Iterate forward through the entire LinkedList but without generating any output. Then iterate backwards through the LinkedList to print the cars data.Assume Student and GradeBook classes are defined as follows: public class Student { int id; double testsMarks[]; public double getAverage(){ double sum = 0; for(double marks : testsMarks) { sum+=marks; } return sum/testsMarks.length; } } import java.util.ArrayList; public class GradeBook { String subject; ArrayList<Student> students; public Student getStudentWithMinAverage(){ } } Define the body of getStudentWithMinAverage method that shall return the student object from students ArrayList who got minimum average marks in the class. (Please write minimum code and make use of provided code, making no change in classes' structure)public class MyGenClass { private T1 name; private T2 stulD; private T3 CGPA; public void setStuData( ){ I/ parameters name = n; stulD = d: CGPA = g; } public void printAsString() { System.out.println( } ); I/ print all information as string public static void main(String args||) { Il Create an object stu by parameters String, Integer, Double Il Call setStuData() with any values you like /l Call printAsString() } }
- The interface Range is defined below:public interface Range{ void setLimits(int x, int y); int getNumber();}Implementations of Range should exhibit the following behaviour:• The setLimits method should store its parameter values somewhere to serve as the lower and upper limits of the range appropriately.• A call to getValue should return an integer that is always greater than or equal to the lower limit and less than or equal to the upper limit.The class RandomInteger is an implementation of the interface Range. It also has the following features:• It has two fields of int type, low and high, to record the lower and upper limits of the range, respectively.• It has single constructor method that takes two integers and stores them in the appropriate fields. Note: You should make use of the setLimits method.• A call to the method getNumber should return a random number that is always within the range, i.e. greater than or equal to the lower limit and less than or equal to the upper limit.…public class MyGenClass { private T1 name; private T2 stulD; private T3 CGPA; public void setStuData( ){ l parameters name = n; stulD = d: CGPA = g; public void printAsString() { System.out.printin( '): # print all Information as string public static void main(String args||) { Il Create an object stu by parameters String, Integer, Double II Call setStuData() with any values you like Il Call printAsString()public static ArrayList findExactString(String s, ArrayList myArray) { return null; } // Use the above method, findExactString, as a helper method to implement addWithoutDuplication method. The addWithoutDuplication method has the following properties: 1- It takes two arguments, a string s and an ArrayList myArray of type string. 2- It returns an integer which represents the number of occurrences of the string s in myArray while attempting to add it. 3- If myArray is null, it returns -1 4- If adds the string s to the end of the ArrayList myArray if the string s is not already there. public static int addwithout Duplication(String s, ArrayList myArray) { return -1;