Question
Create a new Java class called: GetNumbers For this assignment, you will be creating a small main program and a method which will be used
Create a new Java class called: GetNumbers For this assignment, you will be creating a small main program and a method which will be used later in the project. Write a method named getNums: Write a method named getNums which will fill an array with positive integers (including zero). The array which is to be filled should be passed to the method as a parameter. Your method should expect that the array would have already been created in the main program, and so the method does not have to create or initialize the array. The method should read integers from the keyboard and place them into the array. The method should continue doing this until the array has been completely filled, or until the user enters a negative number (whichever happens first). The method should be able to handle an array of any size. When the method finishes, it should return the number of integers that were actually stored in the array. Write the main program: Write a program that will read in a list of up to 8 positive integers (including zero) and store them into an array. After getting the numbers, the main method should display the number of items that were actually stored into the array. Basically, the main program should create an array of size 8, call on the getNums method to fill the array, then print out a message stating how many numbers were stored into the array. If the array is completely filled, the main program should also display a message stating that the maximum size of the list has been reached. You should also create a class constant (global constant) named MAXSIZE and initialize it to 8. Use this constant when printing your prompt to the user and also when initializing the array -- so that the number 8 is not used more than one time in your program. The following is an example of what your MIGHT see on the screen when your program runs. The exact output depends on what values that the user types in while the program runs. The user's values are shown below in italics: Enter a list of up to 8 positive integers. Enter a negative value to stop. 14 96 32 8 17 56 30 17 The maximum size of the list has been reached. The count of items entered is: 8 Here is another example: Enter a list of up to 8 positive integers. Enter a negative value to stop. 14 96 -1 The count of items entered is: 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started