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, Problem 3E
Write some code that asks the user to enter either of the words append or new. According to the user response, open either an existing text file to which data cart be appended or a new, empty text file to which data can be written. In either case, the file’s name is a string given by the variable fileName.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Python - Next Birthdate
In this task, we will write a program that reads birthdate data from a given CSV file, and given the current date, determines which person's birthday will be celebrated next.
Create a function with the following signature:
nextBirthdate(filename, date)
filename: parameter, which represents the CSV filename.
date: parameter, which represents the current date.
The function should open the CSV file, read the birthdate data, and determine which person's birthday will be celebrated next, given the current date. The name of the person should be returned. In other words, given a date, find the person whose birthday is next.
Sample Run
birthdates.csv
Draven Brock, 01/21/1952
Easton Mclean, 09/02/1954
Destiny Pacheco, 10/10/1958
Ariella Wood, 12/20/1961
Keely Sanders, 08/03/1985
Bryan Sloan,04/06/1986
Shannon Brewer, 05/11/1986
Julianne Farrell,01/29/2000
Makhi Weeks, 03/20/2000
Lucian Fields, 08/02/2018
Function Call
nextBirthdate("birthdates.csv", "01/01/2022")
Output…
PROGRAM NEEDS TO MATCH EXAMPLE PHOTO
Write a program ( lab6.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character ‘\n’.
Hints:- You need to look at each character as it is read to see if it is…
The File class contains file input and output operations. In other words, you can
use the File class to read and write content from and to files.
True
False
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
The current source in the circuit shown generates the current pulse
Find (a) v (0); (b) the instant of time gr...
Electric Circuits. (11th Edition)
The 50-mm-diameter cylinder is made from Am 1004-T61 magnesium and is placed in the clamp when the temperature ...
Mechanics of Materials (10th Edition)
How do you look for a partial string match when searching an array of strings for a value?
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
TestScores Class Design a TestScores class that has fields to hold three test scores. The class should have a c...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th Edition)
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
- The python function get_second_line takes one parameter, fname, the name of a text file. The function should open the file for reading, determine the second line of the file, close the file, and return the second line (a string). NOTE: You may assume the file will have at least two lines.arrow_forwardQuestion 4: Quote Filename: quote.py Write a program that reads in an integer representing the number of sentences in the quote. For each sentence in the quote, the program should prompt for the length of the sentence and then read in that number of words from the keyboard. At the end of each sentence add a period ("") and go to the next line. After all of the words in the quote are read, then print the quote to the screen. For example: Number of sentences: 4 Enter length: 3 Roses are red. > Violets are blue. > There is no try. > Just do not or do.arrow_forwardin pythonarrow_forward
- Slide Type Slide • Exercise # 4 A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: • The name of the client, the service sold (such as Dinner, Conference, Lodging, and so on), • The amount of the sale, and the date of that event. • Write a program that reads such a file and displays the total amount for each service category. Display an error if the file does not exit or the format of the record is incorrect. No need to display anything else in this regard. Note that you can assume that the dates are entered correctly (no need to validate them). You may also assume that the name of the input text file is inputex4.txt. • Make sure you use a dictionary in your solution. • Sample run is included below for the given input file inputex4.txt Summary of total sales according to services Dinner 634.75 Conference 1133.25 Lodging Dinner and Lodging 550.25 625.14 Slide Tyne Fragment varrow_forwardB3 Write a program that reads a file and find out the total uppercase, lowercase, whitespaces and digits occurred in the file.arrow_forwardWrite code that opens an output file with the filename number_list.txt, but does not erase the file’s contents if it already exists.arrow_forward
- Why doesn’t the following pseudocode module work as indicated in the comments? // The readFile method accepts a string containing a filename as // an argument. It reads and displays all the items in the file. Module readFile(String filename) // Declare an input file. Declare InputFile file // A variable to hold an item that is read from the file. Declare String item // Open the file using the filename. Open file filename // Read all the items in the file and display them. While eof(file) Read file item Display item End While End Modulearrow_forwardThe function file_first_chars in python takes one parameter, fname, the name of a text file, and returns a string made up of the first character from each line in the file. You may assume there are no blank lines in the file. Hint: Use a for loop to iterate over the lines of the file and accumulate the string of first characters. NOTE: Return the function, don't print For example: Test Result print(file_first_chars("wordlist1.txt")) hsaemarrow_forwardCan you help with problem number 7.arrow_forward
- What is the most effective method for updating a string that is already present in a file?arrow_forwardInside Files (Use Python) Write a program that accepts an integer input, opens a file, and analyzes what and how many types of words are there in a line within the opened file. PROGRAM DESIGNThe program should be able to accept an integer input. This program should be able to open and read a file called tweets2.txt. The integer input represents the order of the line (from 1st to 5th line), within the tweets2.txt file. The program should be able to count how many stopwords, common words, unique words, and overall words are there in the line number input. In Natural Language Processing (NLP), stopwords are defined to be words with no meaning when left alone and with no context. For this activity, stopwords are words that are at most, 3 characters in length, with common words having more than 3 characters. Unique words are words, within the line, that don’t have any duplicates. Whereas overall words are the over all count of all words within the line. The program should also be able to…arrow_forward1. Write a program that opens an output file with the filename my_name.txt, writes your name to the file, then closes the file. 2. Write a program that opens the my_name.txt file that was created by the program in problem 1, reads your name from the file, displays the name on the screen, then closes the file. Write code that does the following: opens an output file with the filename number_list.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C - File I/O; Author: Tutorials Point (India) Ltd.;https://www.youtube.com/watch?v=cEfuwpbGi1k;License: Standard YouTube License, CC-BY
file handling functions in c | fprintf, fscanf, fread, fwrite |; Author: Education 4u;https://www.youtube.com/watch?v=aqeXS1bJihA;License: Standard Youtube License