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 complete Java program:
You have text file called "file.txt" read the contents of the text file and display them on the screen.
Write 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.)
need help with the following.
Do programming project P4.2 in Big Java: Early Objects 7th Edition. Edit the file Easter java.
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
- In Javaarrow_forwardThis is a prompt givento me by my proffesor. It is in java(we use netbeans) Use notepad to create a text file with weather information as below. Then write a program to read the weather information from file and find the highest temperature. Cloudy 51 Rainy 52 Sunny 56 Windy 47 Sunny 53arrow_forwardWrite a JAVA program to convert the temperature in Degree Centigrade to Fahrenheit. The main file should be named Fah.java. It should have import java.util.Scanner; with just one method and class called Fah. The program should take in a integer number with prompt: "Enter temp in Centigrade: “, and output a prompt "Temp in Fahrenheit is: “. The formula to convert Degree Centigrade to Fahrenheit is as follows: Conversion = ((9* Centigrade)/5)+32arrow_forward
- Write a Java Code for two files: PangramCheckerTest.java, PangramChecker.java Instructions: Determine if a sentence is a pangram. A pangram (Greek: παν γράμμα, pan gramma, "every letter") is a sentence using every letter of the alphabet at least once. The best known English pangram is: The quick brown fox jumps over the lazy dog. The alphabet used consists of ASCII letters a to z, inclusive, and is case insensitive. Input will not contain non-ASCII symbols.arrow_forwardDo you write java programs according to the conditions ?arrow_forwardWrite a program in Java Modify the program you wrote for Programming Challenge 2 (Distance Traveled) so itwrites the report to a file instead of the screen. Open the file in Notepad or another texteditor to confirm the output. Challenge 2 : The distance a vehicle travels can be calculated as follows:Distance = Speed * TimeFor example, if a train travels 40 miles-per-hour for three hours, the distance traveled is120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and thenumber of hours it has traveled. It should use a loop to display the distance a vehicle hastraveled for each hour of a time period specified by the user. For example, if a vehicle istraveling at 40 mph for a three-hour time period, it should display a report similar to theone that follows: "Photo in the attachments" Input Validation: Do not accept a negative number for speed and do not accept any valueless than 1 for time traveledarrow_forward
- Java. Please use the template in the picture, thank you!arrow_forwardYou are required to implement a preprocessor in Java. Your preprocessor should be able to Identifying loops and methods on an input file, which will be a Java source file. (please i need clean code) Examplearrow_forwardWrite a Java program that output to the file "poem.txt": your name today's date five lines of your favorite G-rated poemarrow_forward
- Write a Java Program The local Kids’ League coach keeps some of the baseball team statistics in a text fileorganized as follows: each line of the file contains the name of the player followedby a list of symbols indicating what happened on each at bat for the player. Theletter h indicates a hit, o an out, w a walk, and s a sacrifice fly. Each item on theline is separated by a comma. There are no blank spaces except in the player name.So, for example the file could look as follows:Willy Wonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,hSam Slugger,h,h,o,s,w,w,h,w,o,o,o,h,sIn this problem you will a create a program that reads raw data from a text file andprints properly formatted statistics. For instance, a sample output for the firstplayer in the example:Statistics for Willy Wonk:Hits: 4Outs: 11Walks: 1Sacrifices: 1Batting Average: 0.267.1. Create a text file “stats.txt” containing the data below:Willy Wonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,hShari Jones,h,o,o,s,s,h,o,o,o,h,o,o,o,oBarry…arrow_forwardWrite a method called stripComments that accepts a Scanner representing an input file containing a Java program as its parameter, reads that file, and then prints the file's text with all comments removed.A comment is any text on a line from // to the end of the line, and any text between /* and */ characters. For example, consider the following text: import java.util.*; /* My program by Suzy Student */ public class Program { public static void main(String[] args) { System.out.println("Hello, world!"); // a println } public static /* Hello there */ void foo() { System.out.println("Goodbye!"); // comment here } /* */ } If the file contained this text, your program should output the following text: import java.util.*; public class Program { public static void main(String[] args) { System.out.println("Hello, world!"); } public static void foo() { System.out.println("Goodbye!"); } }arrow_forwardIN JAVA Write a program that replaces each line of a file with its reverse. For example, if you run java Reverse HelloPrinter.java Create the output as HelloPrinterReverse.java. If the file HelloPrinter.java contains the text public class HelloPrinter { public static void main(String[] args) { // Display a greeting in the console window System.out.println("Hello, World!"); } } ?? then the contents are changed to retnirPolleH ssalc cilbup { )sgra ][gnirtS(niam diov citats cilbup { wodniw elosnoc eht ni gniteerg a yalpsiD // ;)"!dlroW ,olleH"(nltnirp.tuo.metsyS } } If there is a blank line in the input file, do not print it in the output file. If you run Reverse twice on the same file, you get back the original file. Create the output file as HelloPointerOriginal.java java Reverse HelloPrinterReverse.java If the input file doesn’t exist, throw the message “Input file not found. Please check an rerun the program”. Allow the user to enter the input file one more time. If the user enters an…arrow_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