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
Textbook Question
Chapter 10.4, Problem 25STQ
Does the class ObjectOutputStream have a constructor that accepts a file name as an argument?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a class FileConverter with a constructor that accepts a String file name as its argument. It should store filename as its attribute (with a accessor getFilename().
The class should have the following methods:
• createUpperCaseFile(): Accepts a String parameter targetFilename. It will open up both the file specified in class attribute filename and the method parameter targetFilename. Then it will convert
all lines of the class attribute filename to upper case and write it to target file, line by line.
• createRowCharCountFile(): Accepts a String parameter targetFilename. It will open up both the file specified in class attribute filename and the method parameter targetFilename. Then it will count
the number of chars in each line of the class attribute filename and write it to target file line by line.
The class must come with a main() method, which will create an object instance and generate two target files based on the source file, one all upper case, and another row char count.
Implement (in Java) a console application for writing data to a sequential text file with a formatter class in Java :
a. Implement createFile() method – To open/create a new file named as ‘mec.txt’ with explanations of the methods involved.
b. Implement writeRecord() method – User enter the employee name, employee id, gross salary, tax rate, income tax and net salary from the keyboard and write/add these values to the file ‘mec.txt’ with explanations of the methods involved. The input fields must be validated as necessary.
c. Implement closeFile() method – Close the file with explanations of the methods involved.
JAVA Problem – CycleFileOutput
Revisit the Cycle class. Modify your application such that the properties will be written to a text file called “Cycle.txt” instead of to the screen.
Directions
Examine your application for the class called Cycle.
Add an appropriate throws statement in the main method.
Create a reference to a File class with the appropriate name of a text file (Cycle.txt).
Use appropriate code to ensure that the text file exist.
Output the values of the variables to the text file.
Close the file.
Note: Verify the contents were written to the text file using notepad (or any word processor).
public class Cycle {
// Declear integer instance variable
private int numberOfWheels;
private int weight;
// Constructer declear class
public Cycle(int numberOfWheels, int weight ) {
this.numberOfWheels = numberOfWheels;
this.weight = weight;
}
// String method for output
public String toString() {
String wheel = String.valueOf(this.numberOfWheels);
String load =…
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
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Multiple Stock Sales Use the function that you wrote for Programming Challenge 13 (Stock Profit) in a program t...
Starting Out with C++: Early Objects (9th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Body Mass Index Write a program that calculates and displays a persons body mass index (BMI). The BMI is often ...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Which of the following are illegal variable names and why? x 99bottles july97 theSalesFigureForFisealYear98 rd ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
(Overloaded functions) int getValue() { int inputValue; cout "Enter an integer: "; cin inputValue; return inp...
Starting Out with C++ from Control Structures to Objects (9th Edition)
What are the attractive features or benefits of an inverter-based power supply?
Degarmo's Materials And Processes In Manufacturing
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
- Add an object/variable each of the six blue codes. Possible objects/variables to choose from are: Scanner, outFile, outputName, String, File, out, in, PrintWriter, inputName, inFilearrow_forwardIN JAVA, DO IT IN 30 MINUTES PLEASEarrow_forwardCan you please write in Scanner form and can you please make so i can copy and past it Write a class FileConverter with a constructor that accepts a String file name as its argument. It should store filename as its attribute (with a accessor getFilename()).The class should have the following methods:• createUpperCaseFile(): Accepts a String parameter targetFilename. It will open up both the file specified in class attribute filename and the method parameter targetFilename. Then it will convert all lines of the class attribute filename to upper case and write it to target file, line by line.• createRowCharCountFile(): Accepts a String parameter targetFilename. It will open up both the file specified in class attribute filename and the method parameter targetFilename. Then it will count the number of chars in each line of the class attribute filename and write it to target file line by line. The class must come with a main() method, which will create an object instance and generate…arrow_forward
- in C# Look at Figures 9-35 and 9-36 on page 392 of your book. There should be two blocks of code: A Book class and an AddBooks program. In your IDE, create a new .cs file called books.cs, then type this code (you can type both parts in books.cs), then compile it and run it. NOTE: There IS an error with the codearrow_forwardSuppose you define a class named YourClass in a file. What name shouldthe file have?arrow_forwardIn this assignment, you will create a Java program to read undergraduate and graduate students from an input file, sort them, and write them to an output file. This assignment is a follow up of assignment 5. Like assignment 5, your program will read from an input file and write to an output file. The input file name and the output file name are passed in as the first and second arguments at command line, respectively. Unlike assignment 5, the Student objects are sorted before they are written to the output file. • The program must implement a main class, three student classes (Student, UndergradStudent, GradStudent), and a Comparator class called StudentIDComparator. • The StudentIDComparator class must implement the java.util.Comparator interface, and override the compare() method. Since the Comparator interface is a generic interface, you must specify Student as the type parameter when defining the StudentIDComparator class, i.e., public class StudentIDComparator implements…arrow_forward
- For this exercise, you will create 2 classes: InputOutput class and AddNumbers class. ⦁ InputOutput Class: write a program that carries out the following tasks:⦁ Create an object of type PrintWriter and that writes into a file with the name greeting.txt.⦁ Print the message “Hello, world!” on the file.⦁ Close the file.⦁ Open the same file again.⦁ Read the message into a string variable (hint: use nextLine() method to read the text).⦁ Print the message on the screen. ⦁ AddNumbers Class: write a program that asks the user to input four floating-point numbers. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs. For example, the user might enter letters instead of numbers. In this case, use the exception handling mechanism to print a proper message. (hint: use InputMismatchException) Don’t forget to import java.util.*.arrow_forwardcreate a class named FileUtils. Add a method static void copyFile(String source, String destination) method that copies the source file to the destination location. For example, if called as copyFile(“a.txt”, “b.txt”) the contents of the file “a.txt” would be copied into the file “b.txt.”a. You must write the code to copy the file using java.io.* classes (e.g. File, FileInputStream, FileOutputStream, etc.).b. Do not assume that the files will contain only text.c. You should try to copy efficiently (i.e. not a single byte at a time).d. It is suggested that you test your method by copying the provided files from the input directory to the output directory in your project.e. The method should rethrow any exceptions that may occur.arrow_forwardExercise 2: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_forward
- Create a new Java Application project called lab_07 Part 1: 1. Copy the source file Square class you crated in Lab 03 and paste the source file in the default package (you may need to fix any problems related to package declaration). 2. Open Square class using NetBeans editor. 3. Modify the class implementation to throw IllegalArgumentException if the side’s length is negative. You should modify the implementation of the arguments constructor and setSide method to throw the IllegalArgumentException. Use the following constructor header as a start: /** * Construct a Square object with the specified side’s length * @param side the side’s length of a square * @throws IllegalArgumentException if the side’s length is negative */ public Square (double side) throws IllegalArgumentException { // implement it } Part 2: 1. Write a program that prompts the user to read two integers and displays their sum. Your program should prompt the user to enter the number again if the input is…arrow_forwardhello, I have errors in my code, and i'm not sure on how fix my some of my myethods. I have the outline for my code bellow, as well as the rubric: description: Write a java application that will open an input file and open an output file. The file names can be entered fromthe command line, if a command line parameter is included, it will be used as the input file name. If a second command line parameter is included, it will be used as the output file name. Any missing parameters will beprompted for and read by the program. When the input file does not exist the user will be prompted to re-enteran input file name. When nothing is entered for the input file name, on a prompt, the program will proceed tothe end of the program and terminate. When the output file exists the user will havea choice of entering a new output file name, backing up the existing output file first, overwriting the existingoutput file, or quitting the program without opening any files. Again, not entering a file…arrow_forwardJAVA Problem – CycleFileInput Revisit the Cycle class . Modify your application such that the properties will be read from a text file called “Cycle.txt”. Directions Examine your application for the class called Cycle. Add an appropriate throws statement in the main method. Create a reference to a File class with the appropriate name of a text file (Cycle.txt). Note: Cycle.txt was created in the previous assignment, CycleFileOutput. In your code, check that the text file does exist. Input the values from the file to memory. Close the file. public class Cycle { // Declear integer instance variable private int numberOfWheels; private int weight; // Constructer declear class public Cycle(int numberOfWheels, int weight ) { this.numberOfWheels = numberOfWheels; this.weight = weight; } // String method for output public String toString() { String wheel = String.valueOf(this.numberOfWheels); String load = String.valueOf(this.weight); return("No of wheels in cycle = " +…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Files & File Systems: Crash Course Computer Science #20; Author: CrashCourse;https://www.youtube.com/watch?v=KN8YgJnShPM;License: Standard YouTube License, CC-BY
UNIX Programming (Part - 10) The File System (Directories and Files Names); Author: ITUTEES;https://www.youtube.com/watch?v=K35faWBhzrw;License: Standard Youtube License