subject

This project deals with EOF-based loops, using the while construct where we do not know the exact number of times a loop will iterate (perform the associated block of code). We will continue to build on our knowledge of if/else constructs.

Use the variables given below to solve the problem. You should need no other variables to complete this project.

// number entered and the running total

int inputNum, sum = 0;

// count of valid and invalid numbers seen

int numValid = 0, numInvalid = 0;

double average;

Using your knowledge of Java and using inputNum as your input variable, write a while loop to read positive integers from the user until the user enters the EOF character. This is the sentinel value indicating that the user has finished entering data.

You can use hasNext() to determine if the EOF has occurred. The user must use CTRL-D (DrJava) to terminate the program since these are the appropriate EOF characters.

Numbers will be separated into two categories. Valid numbers are considered to be the range of positive integers including zero. Invalid numbers are the range of negative integers.

As you are reading in the values you should be keeping track of how many positive values (numValid) have been read while simultaneously keeping a running total (sum).

You should not include negative values in the running total. Instead you should increment the count of invalid numbers (numInvalid) entered by the user.

You will report to the user the number of valid values they entered, the number of invalid values, the sum and average of the valid values. The average should be displayed as a floating point value to two decimal places using the printf() method.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:20
This os integrated the processing power of windows nt with the easy-to-use gui of windows 98. windows 2000 windows 3.11 windows for workgroups windowa millennium edition
Answers: 1
question
Computers and Technology, 23.06.2019 20:30
If an appliance consumes 500 w of power and is left on for 5 hours, how much energy is used over this time period? a. 2.5 kwh b. 25 kwh c. 250 kwh d. 2500 kwh
Answers: 1
question
Computers and Technology, 24.06.2019 14:00
Which describes careers that have similar education requirements but different qualifications? product safety engineers and materials engineers industrial safety engineers and industrial health engineers quality control systems managers and inspectors industrial safety and health engineers and hand packers
Answers: 3
question
Computers and Technology, 24.06.2019 17:00
The length of time that a slide appears before automatically advancing to the next slide can be set in the timing group under the transitions tab. transition to this slide group under the transitions tab. timing group in the master slide view. transition to this slide group in the master slide view.
Answers: 1
You know the right answer?
This project deals with EOF-based loops, using the while construct where we do not know the exact nu...
Questions
question
Mathematics, 19.02.2020 02:33
question
English, 19.02.2020 02:33
question
History, 19.02.2020 02:33
question
Mathematics, 19.02.2020 02:34
question
Computers and Technology, 19.02.2020 02:34
Questions on the website: 13722362