Write a method to read numbers from the keyboard into an array. Stop reading when the user enters the sentinel value -999. Return the number of values that were read. Do not put the sentinel in the array and do not include it in the number of values entered. Print an error message and stop reading if the user tries to enter more values than the array can hold.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a method to read numbers from the keyboard into an array. Stop reading when the user enters the sentinel value -999. Return the number of values that were read. Do not put the sentinel in the array and do not include it in the number of values entered. Print an error message and stop reading if the user tries to enter more values than the array can hold.
Write a method to print out the numbers in the array. Make sure the method only prints the array positions that were filled with the user's input. Print one number on each line.
Write a method called zeros to return the number of entries in the array which contain zero.
Write a method called replace which includes the parameters before and after, which are both integers. The method will change every array entry that contains the value before to contain the value after. For example, if the array contains {10,20,30,40,20,50}, before is 20 and after is 1, the array should be changed to {10,1,30,40,1,50}.
Write a method called positive which will return true if all the numbers in the array are positive (greater than zero) and will return false if any number in the array is not positive (less than or equal to zero).
Write a method called rotate which will rotate the array one position to the right. To rotate, move each element one position to the right except for the last element, which is moved to the beginning. For example, if the array contains {10,20,30,40,50}, after rotation it contains {50,10,20,30,40}.
The array is a parameter for all of the methods described above.

Your main method should do the following:

Create an array of 30 integers.
Call the method to read numbers into the array.
Call the method to print the array.
Call the method zero, then print the number of zeros with an appropriate message.
Prompt the user to enter before and after, call replace, then call the method to print the array.
Call positive, then print a message telling whether or not all array entries are positive.
Call rotate, then call the method to print the array.     Write a program that processes an array using methods. This is a java program.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education