Concept explainers
Generics enable you to specify the exact type that will be stored in a collection and give you the benefits of compile-time type checking—the compiler issues error messages if you use inappropriate types in your collections. Once you specify the type stored in a generic collection, any reference you retrieve from the collection will have that type.
Instructions
Write a
The program must:
- sort the elements,
- then calculate the sum of the elements, and
- calculate the floating-point average of the elements.
For this assignments make sure that your screen shot(s) show your program running and that your runtime display shows your random list, sorted list, sum of the elements, and average of the elements. You only get credit for what you demonstrate. Below is a sample screen shot. Your output doesn’t have to look exactly like this but you should display the unsorted list, the sorted list, the sum, and the average to get full credit.
Introduction
Java programming:
Java is cross-platform, meaning it can run on any operating system, and is relatively easy to learn. It is a versatile language that has powerful tools for creating efficient and secure applications. It is used in a variety of applications, from desktop applications to web development, mobile development, and embedded systems. Java is popular for its scalability and support for a wide range of libraries and tools.
To find:
Program that inserts 25 random integers from 0 to 100.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Data Structure & Algorithm: Describe and show by fully java coded example how a hash table works. You should test this with various array sizes and run it several times and record the execution times. At least four array sizes are recommended. 10, 15, 20, 25. It is recommended you write the classes and then demonstrate/test them using another classarrow_forwardJAVA CODE Learning Objectives: Detailed understanding of the linked list and its implementation. Practice with inorder sorting. Practice with use of Java exceptions. Practice use of generics. You have been provided with java code for SomeList<T> class. This code is for a general linked list implementation where the elements are not ordered. For this assignment you will modify the code provided to create a SortedList<T> class that will maintain elements in a linked list in ascending order and allow the removal of objects from both the front and back. You will be required to add methods for inserting an object in order (InsertInorder) and removing an object from the front or back. You will write a test program, ListTest, that inserts 25 random integers, between 0 and 100, into the linked list resulting in an in-order list. Your code to remove an object must include the exception NoSuchElementException. Demonstrate your code by displaying the ordered linked list and…arrow_forwardData Structures/Algorithms in Javaarrow_forward
- What happens when a programmer attempts to access a node's data fields when the node variable refers to None? How do you guard against it? *PYTHONarrow_forwardFor any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a comma (no spaces). Ex: If the input is: 32 105 101 35 10 20 30 40 the output is: 20,30, 1 #include 2 3 int main(void) { const int SIZE_LIST = 4; int keysList[SIZE_LIST]; int itemsList[SIZE_LIST]; int i; 4 6 7 8 scanf("%d", &keysList[0]); scanf ("%d", &keysList[1]); scanf("%d", &keysList[2]); scanf("%d", &keysList[3]); 10 11 12 13 scanf ("%d", &itemsList[0]); scanf ("%d", &itemsList[1]); scanf("%d", &itemsList[2]); scanf ("%d", &itemsList[3]); 14 15 16 17 18 19 /* Your code goes here */ 20 21 printf("\n"); 22 23 return 0; 24 }arrow_forwardJava/Data Structures: The Java Class Library implementation of the interface list return null when an index is out of range. True or Falsearrow_forward
- Java - All objects in a sorted list must be objects that can be compared to each other. True or False?arrow_forwardSuppose a genetic algorithm uses chromosomes of the form x = abcdefghwith a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of individual x be calculated as: ?(?)=(?+?)−(?+?)−(?+?)−(?+ℎ) And let the population consist of fiveindividuals with the following chromosomes: ?1=12345678 ?2=23456781 ?3=45637281 ?4=53617284 ?5=23921285 a)Computethe fitness value for each individual and sort them in order with the fittest first and the least fit last. b)To create mating pool, roulette wheel selection is used. You will select the individuals. The random values to perform roulette wheel selection are 0.15, 0.56, 0.50, 0.68, and 0.95respectively. Please construct the mating pool step by step and write the selected individuals clearly. c)Perform thefollowing crossover operations in the mating pool: i)Cross the fittest two individuals using one–point crossover at the middle point. ii)Cross the second and third fittest individuals using a two–point crossover…arrow_forward#Steps: Create a Main class. Declare an ArrayList in the main() method and store the given values in it. Create an array called output of the size of the ArrayList. Iterate through for-loop to get each element from the array List and load it into the array using the get() method of the list. Print the array to see the loaded elements. import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<String> nameList = new ArrayList<String>(); nameList.add("Robert"); nameList.add("Samson"); nameList.add("Alex"); nameList.add("William"); System.out.println("Elements of List: " + nameList); // Create an array of the same size as nameList Hint: use size() method // Fetch the elements from the nameList and insert into newly created array // Hint: Use get() method to fetch the elements from…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education