Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 10.4, Problem 29STQ
Program Plan Intro
Program plan:
- Import the required header files.
- Define the class “ReadFile”.
- Define the main method.
- Declare the string variable along with the value.
- Inside the “try” block, the “ObjectInputStream” is used to read a data from the binary files.
- The “inputStream” is the object of the “ObjectInputStream” stream class.
- The “FileOutputStream” is an output stream used for reading a data from a “File”.
- It allows to open a file “temperature.dat” for reading binary data and to establish the connection within it.
- Inside another “try” block, read the double values from the binary file and display it.
- This method reads only three numbers when it goes to next one the “EOFException” is thrown. The “EOFException” class can be used to test for the end of a file.
- The “FileNotFoundException” catch block is used to throw an error message, if the file was not found in the found.
- The “IOException” catch block is used to throw an error message, if the input/ output operation issues.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a java program that:
1. Create a file with the name "BankAccount.txt" and has the following
content (the account name, account number and balance of each account)
The file will look like this:
Amani Ali 12345432 500
Sarah Mohammad 456663343 4000
Omimah khalid 998787655 2000
Monirah Ahmad 55433424 10000
2. Read the file "BankAccount.txt" content one by one and increase the
balance by 50% for each account, then write the result in a new file with
the name "UpdatedAccount.txt". The new file content should have the
following structure:
Amani Ali 12345432 750
Sarah Mohammad 456663343 6000
Omimah khalid 998787655 3000
Monirah Ahmad 55433424 15000
3. Read an account number from the user and search the file
"UpdatedAccount.txt", then print all the information of this account if
exists, otherwise display a message "this account not found".
Note:-
Search google to find some of the built-in methods to help you in this
program, such as trim(), split(), equals(), Integer.parseInt().
Write a Java program that opens a file and counts the whitespace-separated words in that file. You may obtain the name of the input file either from the command line or via prompt and user input. Be sure to clearly document the method chosen.
You may test your program using any number of text files; however, you must be sure to test your program using the Sample Text File provided at the end (excerpt.txt).
Sample Text File
There was nothing so VERY remarkable in that; nor did Alice think it so VERY much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually TOOK A WATCH OUT OF ITS WAISTCOAT- POCKET, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to…
Write a Java program in a file called Box.java that outputs a box of stars (*) on the
screen. Prompt the user for how big (row x column) the box should be.
For example:
Please enter the size of the box (row column): 3 4
****
****
****
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 10.1 - Why would anybody write a program that sends its...Ch. 10.1 - When we discuss input, are we referring to data...Ch. 10.1 - What is the difference between a text file and a...Ch. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Prob. 5STQCh. 10.2 - Prob. 6STQCh. 10.2 - Prob. 7STQCh. 10.2 - Write some code that will create a stream named...Ch. 10.2 - Suppose you run a program that writes to the text...Ch. 10.2 - Prob. 10STQ
Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 12PP
Knowledge Booster
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
- Create a java program that search a specific word in a text file. Also, count how many times the word appears in the file.arrow_forwardIn Java Suppose you are given a text file that contains the names of people. Every name in the file consistsof a first name and a last name. Unfortunately, the programmer that created the file of names hada strange sense of humor and did not guarantee that each name was on a single line of the file.Write a program that reads this file of names and writes them to a new text file, one name per line.For example, if the input file (Names.txt) contains:Bob Jones FredCharles EdMarstonJeffWilliamsThe output file (RecoveredName.txt) should be:Bob JonesFred CharlesEd MarstonJeff WilliamsSample Output:Enter the name of the input file:Names.txtEnter the name of the output file: RecoveredName.txtFile processing completed.arrow_forwardWrite a Java program, GradeApp that reads a series of exam scores given as integers in the range 0 to 100. Display the total number of grades and the number of grades in each letter-grade category, followed class average (as a percentage with 2 decimal place): Use the value -1 as a sentinel value to indicate the end of the input. (The -1 value is used only to end the loop. Please do not use it in the calculations.)arrow_forward
- Write a program in Java that reads a stream of integers from a file and prints to the screen the range of integers in the file (i.e. [lowest, highest]). You should first prompt the user to provide the file name (nextLine()). You should then read all the integers from the file, keeping track of the lowest and highest values seen in the entire file, and only print out the range of values after the entire file has been read.arrow_forwardWrite a program in Java to perform the following: Using a BufferedReader class and related objects, read a string object consists of 60 words plus some special characters and numbers. Include double space between some words. Include a few $ and % signs in your text. Store that text into a file using proper classes and methods. Call that file fileon.doc which will be your input file then read the contents of that file and perform the following operations using java available methods: Add a new line at the beginning of the text to include your name and the class name (csc 202) Find the length of you text Change the first character of each line to upper case . Find the number and location of all $ sign and re place it with a space. Delete all double spaces Calculate the number of special characters Find the number of lines in your text. Remember each line is terminated by a “.”, find the number of vowel in the last line Count the number of digits in your text. Append a new line consist…arrow_forwardIn Java Suppose you are given a text file that contains the names of people. Every name inthe file consists of a first name and a last name. Unfortunately, the programmer thatcreated the file of names had a strange sense of humor and did not guarantee thateach name was on a single line of the file. Write a program that reads this file ofnames and writes them to the console, one name per line.For example, if the input file (Names.txt) contains:Bob Jones FredCharles EdMarstonJeffWilliamsThe output should be:Bob JonesFred CharlesEd MarstonJeff Williams Sample Output:Enter the name of the input file:Names.txtBob JonesFred CharlesEd MarstonJeff WilliamsFile processing completed.arrow_forward
- Write a Java program that allows the user to specify a file name on the command line and prints the number of characters, words, lines, average number of words per line, and average number of characters per word in that file. If the user does not specify any file name, then prompt the user for the name.arrow_forwardCreate a text file called randomWords.txt and a Java file calledalphabeticalWords.java. Inside, write a program that reads words fromthe text file and displays all the words (duplicates allowed) in ascendingalphabetical order. The words must start with a letterarrow_forwardWrite a program that reads a stream of integers from a file and prints to the screen the range of integers in the file (i.e. [lowest, highest]). You should first prompt the user to provide the file name. You should then read all the integers from the file, keeping track of the lowest and highest values seen in the entire file, and only print out the range of values after the entire file has been read. In Java.arrow_forward
- Create a java program that calculates the average test scores. Three employees in a company are ups for a special pay increase. You are given a file; ABCompany.txt, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee’s last name, first name. Current salary and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87 and the pay increase is 5%. Write a program that reads the data from the specified file and stores the output in the file ABCoutput.dat. For each employee, the data must be output in the following form: firstname lastname updated salary. Format the output of decimal numbers to two decimal places. Send a copy of the following: the java code Screenshot of the results screenshot of input file screenshot of output filearrow_forwardWrite a Java program that asks a user to input a text file name which contains no punctuations reads the text file prints out the occurrence of the distinct words in alphabetical orderarrow_forwardCreate a java program that calculates the average test scores. Three employees in a company are ups for a special pay increase. You are given a file; ABCompany.txt, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee’s last name, first name. Current salary and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87 and the pay increase is 5%. Write a program that reads the data from the specified file and stores the output in the file ABCoutput.dat. For each employee, the data must be output in the following form: firstname lastname updated salary. Format the output of decimal numbers to two decimal places. Send a copy of the following: the java code code Screenshot of the code screenshot of input file screenshot of output filearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education