Concept explainers
Write some code that will create a stream named outStream that is an object of the class PrintWriter and that connects this stream to a text file named sam.txt so that your
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Digital Fundamentals (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
C++ How to Program (10th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
- Write a program that writes 100 integers created randomly into a file. Integers are separatedby a space in the file. Read the data back from the file and display the sorted data. Yourprogram should prompt the user to enter a file- name. If the file already exists, do not overrideit.arrow_forwardCreate a text file of names, (3 names per line, 5 lines in total) followed by an age for each name. Go through the file and sum the ages. Create an output file with each persons name followed by age and then a line at the end of the output file that says “sum of all ages is: x”. Simple Java programming. Should include things like bufferedReader, fileReader, printWriter, fileWriter, file close, try-with-resources, Scanner, catch/try, etc. Include Java file and txt file. Thank you.arrow_forwardCreate a program that reads three lines from a text file. Each line should be read one at a time. For each word on a line, the user should be asked to specify how many syllables are in that word. The program should then inform the user if the file contains a valid Hiku using the function below: def isHiku (firstLine, secondLine, thirdLine):if (firstLine == 5 and secondLine == 7 and thirdLine == 5): return True return False print("The file contains a Hiku:", isHiku(5,7,5))Note: You must replace the values in the function with the numbers counted by your program.arrow_forward
- Write a program that writes user input to a text file and then reads the contents from that file. You will need to perform the following steps. Prompt the user for the name of a file to append to and then another prompt for them to enter a sentence. Open the file they requested in append mode and write the user_sentence to this file. Don't forget to close the file when you are done writing to it (explicitly or implicitly). Open the file you just wrote to in read mode and read the contents of the file. Print the complete file contents to the console/shell. Provide comments in your code to explain the logic used. Ensure your program works as expected by testing it with different sentences.arrow_forwardWrite a program that will ask the user for their grocery list, one item at a time, and will write it to a file called groceries.txt. The program should create a new file called groceries.txt that will contain all of the user’s groceries when opened.arrow_forwardIN JAVA ONLY PLEASE. POSITIVE REVIEW WILL BE LEFT FOR CORRECT LANGUAGE ONLY AND NOT COPY PASTE FROM INCORRECT ANSWER A photographer is organizing a photo collection about the national parks in the US and would like to annotate the information about each of the photos into a separate set of files. Write a program that reads the name of a text file containing a list of photo file names. The program then reads the photo file names from the text file, replaces the "_photo.jpg" portion of the file names with "_info.txt", and outputs the modified file names. Assume the unchanged portion of the photo file names contains only letters and numbers, and the text file stores one photo file name per line. If the text file is empty, the program produces no output. Ex: If the input of the program is: ParkPhotos.txt and the contents of ParkPhotos.txt are: Acadia2003_photo.jpg AmericanSamoa1989_photo.jpg BlackCanyonoftheGunnison1983_photo.jpg CarlsbadCaverns2010_photo.jpg CraterLake1996_photo.jpg…arrow_forward
- Write a program, and store it in a file called Travel Expenses.xlsm, that does the following: (a) It asks for a person’s first name and stores it in firstName; (b) it asks for a person’s last name and stores it in lastName; (c) it asks for the number of miles the person traveled on a recent trip and stores it in nMiles; (d) it asks for the average miles per gallon the person got on the trip and stores it in milesPer- Gallon; (e) it asks for the average price per gallon paid for gas on the trip and stores it in avgPrice; (f) it calculates the cost of the trip and stores it in tripCost; and (g) it displays a message such as "Bob Jones traveled 800 miles, got 31.3 miles per gallon on average, paid $3.49 per gallon on average, and paid a total of $89.20 for gas." Make sure there is an Option Explicit line at the top of the module and that you declare all of your variables appropriately.arrow_forwardWrite a program that opens a file me.txt and write your first name followed by a space followed by your last name, then your major on the second line. If the file does not exist, create it. If the file exists, have the file's contents be erased before writing your name. Be sure to close the file after. Example: Barack Obama Political Science Majorarrow_forwardWrite a program that gives and takes advice on program writing. The pro- gram 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'.arrow_forward
- Last lab, we modified the inventory program to write a file. This lab, we’ll modify it to read a file. First, take your program from the last lab. Add one more feature: at the end, just before you close the file, write the word “END” all by itself on a line. Run that program once to create a file of items with “END”. Now, copy that program to a new file cp lab7.cpp lab8.cpp so you can use it as a basis for this lab. Modify lab8 so instead of reading from cin and writing to a file, you read from your file and write to cout. The only tricky part is deciding when to stop reading. In lab7, you stopped reading when the user said they didn’t want to continue. For lab8, keep reading until you read “END” for the name of the produce. You can use “==” on strings, so if (product name == ”END”) will tell you that you can stop reading. PHOTO OF WHAT IT SHOULD LOOK LIKE INCLUDED My code for last lab: #include <iostream>#include <string>#include <fstream>using namespace std; int…arrow_forwardExercise #3: Write a program that finds all students who score the highest and lowest average marks of the first two homework in CS (). Your program should read the data from a file called "hw2.dat" and displays the output to another file called "hw2.out" and on the screen. The first line of the input file contains the number of students, N. The next N lines contain information about the students. Each data line contains student name and his/her marks. The output should display all student names, marks, and grades. In addition, you should output the highest and lowest marks and those who earned them along with the average and the grade of the class. If your input file contains: 20 Ali Al-Shikeli Noora Al-Wardi Aisha Al-Rabani 80 81 70 78 60 70 70 63 Rugaya Al-Mogbali Kartma Al-Rawas Manal Al-Styabi Khalsa Al-Sairi Iman Al-Zadjali Farha Al-Waheibi Amel Mugabal Munira Alabri Amel Khamis Huda Al-Mukheini Nawal Al-Shikeili Rasha Al-Raidan Saif Al-Hashmi Mohamed Al-Kharousi Mohammed A-Badi…arrow_forwardWrite a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the files and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning