ArrayAdd JAVA

To complete this program you will need to be able to use arrays in Java and loop over them to perform some calculations.Arrays in Java cannot be changed. So when you want to add elements to an existing array but you have reached the bounds of the array, you must make a new array that is larger and move all the items into it. This can be done using loops. Here is an example…String[] originalArray = {“A”, “B”, “C”};// Make a new array that is one element bigger than the original array.
String[] updatedArray = new String[originalArray.length + 1];// Loop over the original array. Place each element into the same position in the updated array.
for (int i = 0; i < originalArray.length; i++) { updatedArray[i] = originalArray[i]; }updatedArray[updatedArray.length - 1] = "D"; You can view and experiment with the code in this live environment (Links to an external site.). Spend time with this. Make sure you understand how it works and everything that is happening.Now you are going to write a program to collect scores (they range from 0 to 100) and then provide some statistics about the set of data. Write a program in Java that asks the user to enter a score. You will store this score into an array. This will happen over and over again until the user enters enter -1 to stop (provide instructions in the program to this effect). Since you don't know how long this will go on, you must continue to resize the array to meet the amount of data entered in the program. When user has finished entering all the scores, the program should iterate over the array and find the number of scores entered, the sum of the scores, the mean, the lowest and the highest score. It should display this information to the user.You may only use simple arrays. You cannot import any new classes aside from the scanner which will be required to capture the user input. Use of outside classes not earn any points.

×
New Download