Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:20, kimmmmmmy333
Octothorpe is another name for what common computer keyboard symbol?
Answers: 1
image
Computers and Technology, 23.06.2019 01:10, kristofwr3444
Are special combinations of keys that tell a computer to perform a command. keypads multi-keys combinations shortcuts
Answers: 1
image
Computers and Technology, 23.06.2019 07:00, schvox
1. you have a small business that is divided into 3 departments: accounting, sales, and administration. these departments have the following number of devices (computers, printers, etc.): accounting-31, sales-28, and administration-13. using a class c private network, subnet the network so that each department will have their own subnet. you must show/explain how you arrived at your conclusion and also show the following: all available device addresses for each department, the broadcast address for each department, and the network address for each department. also, determine how many "wasted" (not usable) addresses resulted from your subnetting (enumerate them).
Answers: 3
image
Computers and Technology, 24.06.2019 06:30, chloeholt123
For which utilities, if any, does the landlord pay?
Answers: 2
Do you know the correct answer?
This project deals with EOF-based loops, using the while construct where we do not know the exact nu...

Questions in other subjects: