1. Design and implement a program that reads a series of integers from the user and...

60.1K

Verified Solution

Question

Programming

1. Design and implement a program that reads a series ofintegers from the user and continually prints their average afterevery reading. The input stops when the user enters “stop” as theinput value. Read each input value as a string, then check if it is“stop” or not. If the string is not “stop”, then, attempt toconvert it to an integer using the Integer.parseInt method. If thisprocess throws a NumberFormatException, meaning that the input isnot a valid integer, display an appropriate error message andprompt for the number again. Continue reading values until thestring “stop” has been entered.

2. Suppose a library is processing an input file containing thetitles of books in order to identify duplicates. Write a programthat reads all of the titles from an input file calledbookTitles.inp and writes them to an output file calledduplicateTitles.out. When complete, the output file should containall titles that are duplicated in the input file. Note that theduplicate titles should be written once, even though the input filemay contain same titles multiple times. If there are not duplicatetitles in the input file, the output file should be empty. Createthe input file using Notepad or another text editor, with one titleper line. Make sure you have a number of duplicates, including somewith three or more copies.

Answer & Explanation Solved by verified expert
3.8 Ratings (724 Votes)
1 FindAveragejavaimport javautilScannerpublic class FindAverage public static void mainString args Scanner scanner new ScannerSystemin String str int counter 1 int sum 0 int average do SystemoutprintlnEnter a number or to type stop to end program str scannernextLine try ifstrequalsIgnoreCasestop int n IntegerparseIntstr sum sum n average sum counter SystemoutprintlnAverage is average counter catch NumberFormatException ex SystemoutprintlnInvalid number please try againnn while strequalsIgnoreCasestop SystemoutprintlnGood Bye Output2 RemoveDuplicateTitlesjava import javaioFileimport javaioIOExceptionimport javaniofileFilesimport javaniofilePathimport    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students