Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named PrintAverage.java The main method of the class should only contain a call to a void method named userInterface() which takes no

Write a class named PrintAverage.java

The main method of the class should only contain a call to a void method named userInterface() which takes no parameters. The userInterface() method must use a sentinel loop to repeatedly prompt the user for integers. If the user enters anything other than an integer, display a new prompt that says "Not an integer, try again: " (use a while loop and the Scanner hasNextInt() method for this).

Once the user types any negative number (sentinel), the method should display the average of all the non-negative numbers typed. Display the average as a double. Assume inputs do not contain spaces.

Here is a sample dialogue with the user:

csc$ java PrintAverage

Type an integer (negative number to quit): 4 Type an integer (negative number to quit): i Not an integer, try again: L Not an integer, try again: % Not an integer, try again: 7 Type an integer (negative number to quit): 16 Type an integer (negative number to quit): -8 Average was 9.0

csc$ If the first number that the user types is negative (count of non-negative integers entered is 0), do not print an average. Sample user dialog for this case:

csc$ java PrintAverage

Type an integer (negative number to quit): -2

csc$

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

Why has Negotiating Women, Inc. focused its attention on women?

Answered: 1 week ago