Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10.4, Problem 14STQ
Give a statement that will close the stream toFile created for the previous two questions.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please make a procedure that takes two parameters and prints a list of students from the first parameter as a student ID to the last parameter which is another student ID. If student is not found, then process an exception NO_DATA_FOUND.
Create a data file with 1,000 lines. Each line in the fileconsists of a faculty member’s first name, last name, rank, and salary. Thefaculty member’s first name and last name for the ith line are FirstNamei andLastNamei. The rank is randomly generated as assistant, associate, and full.The salary is randomly generated as a number with two digits after the decimalpoint. The salary for an assistant professor should be in the range from 50,000to 80,000, for associate professor from 60,000 to 110,000, and for full professorfrom 75,000 to 130,000. Save the file in Salary.txt. Here are some sample data:FirstName1 LastName1 assistant 60055.95FirstName2 LastName2 associate 81112.45. . .FirstName1000 LastName1000 full 92255.21
We will use the file classlist.txt. Note that it contains a list of usernames.
3.
Write a script called finduser that is to be called as follows, where classlist is the name of the classlist
file, and username is a particular student's username, either first name or last time.
./finduser classlist username
The script should
check that the correct number of arguments was received and print an error message if not,
check whether the classlist file exists and print an error message if not,
print the line of the given username in the classlist file
If you have not been doing so all along, you should now add some comments to your script and thoroughly
test it!
4.
Write the script into your lab report.
Chapter 10 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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.6 - Prob. 36STQCh. 10.6 - Prob. 37STQCh. 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. 9PPCh. 10 - Prob. 12PPCh. 10 - Prob. 15PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
This is a small holding section" in memory that many systems write data to before writing the data to a file. a...
Starting Out with Python (4th Edition)
A criticism of the break statement and the continue statement is that each is unstructured. Actually, break sta...
C How to Program (8th Edition)
Write a program to print the corresponding Celsius to Fahrenheit table.
C Programming Language
TeamLeader Class In a particular factory, a team leader is an hourly paid production worker that leads a small ...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Practice Problem 3.43 (solution page 344) Suppose you are given the job of checking that a C compiler generates...
Computer Systems: A Programmer's Perspective (3rd Edition)
Is it possible to have more than one constructor? Is it possible to have more than one destructor?
Starting Out with C++ from Control Structures to Objects (8th 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
- Include an inner listener class to handle the events from the Save Record button. WhenSave Record button is clicked, new customer record is inserted into the table named“CUSTOMER” and display a message “New Customer Record Inserted” in a dialog box.Include another anonymous inner listener class to handle the events from the Reset button.When Reset is clicked then clear all the text fields and place the cursor in the first text fieldto allow the user to re-enter the correct values and Write a code that includes an exception handler that deals with duplicate records (e.g. sameCustomer ID.) and database error (e.g. Error establishing a database connection).arrow_forwardCreate an anonymous block that a teacher can run to insert the student's grade on a particular assignment. Accept a NUMERIC_GRADE, CLASS_ASSESSMENT_ID, CLASS_ID and STU_ID. Use “today‟s” date for the DATE_TURNED_IN.arrow_forwardUse the following code to create a new Transcript class instance.arrow_forward
- please help fix the following Scenario: Your team is working with data where dates are caputred as a string, "9/15/2019". You are tasked to create a python function named 'mdy_date' that will accept a string input, convert it to a python datetime object, and return the datetime object. Create the function in the cell below.arrow_forwardKindly add comments /* Thank you!arrow_forwardProvide a function named "addToSessionStorage" that accepts two parameters: The first parameter "storeName" is the store name for your session storage. The second parameter "objName" is an object. Inside the function, use sessionStorage to save "objName" under the store name. Your test object can contain any properties you want.Hint: Use JSON methods on these storage problems. Note: The remaining buttons and paragraphs do not have id attributes. You will need to construct selectors to meet these challenges.arrow_forward
- Write a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy’s name, a girl’s name, or both, and the application will display messages indicating whether the names were among the most popular. your program should read the files into separate lists for boys and girls names the program should accept either a girl name or a boy name or both, entry of a NULL i.e. just pressing the "enter key" results in no search for that entry the program must continue to run until told to stop by the person running the program using any method of your choice report on the success or not of each attempt to locate a name in the popular names filesarrow_forwardCell 6: Write a header at the top of the file (i.e., above Cell 1) with a description of this lab using the header format described above. If you haven't already, add comments to all the code you've written so far. Add docstrings to all the functions you've written so far using the "Generate docstring" method. Then, in a new cell (#6), add lines of code that print the docstrings of these functions.arrow_forwardWhich of the following code elements is often removed at the end of a line? Why it is removed?arrow_forward
- Create a simple loop that prints instructor names, where instructor IDs are in the range from 101 to 105 only.arrow_forwardDesign a Client class that interfaces with your SQLDatabase Server (from the class Server). The Client sends a SQLQuery to the SQLDatabase and receives a Dataframe from the SQLDatabase. Your class should contain the default __dunders__ and potentially introduce some custom __dunders__. classServer.py (Just change if this file has something doesn't run or doesn't fit with new code) import sqlite3import pandas as pdclass Server:def __init__(self, db_name):self.db = sqlite3.connect(db_name)self.cursor = self.db.cursor()def __enter__(self):return selfdef __exit__(self, exc_type, exc_val, exc_tb):self.db.close()def create_table(self, table_schema):self.cursor.execute(table_schema)self.db.commit()def insert_data(self, table_name, data):for i in range(len(data)):keys = ", ".join(data.columns)values = ", ".join([f"'{value}'" if pd.isna(value) else str(value) for value in data.iloc[i]])self.cursor.execute(f"INSERT INTO {table_name} ({keys}) VALUES ({values})")self.db.commit()def…arrow_forwardConsider the data contained in the text file data1.txt. The first row of this file contains the column names. The remaining rows have one number for each column. The numbers are separated by a tab character. You can work in your command window. No need to create a matlab file for this question. Download the data file. Use importdata() function to load data into Matlab. What is the average of the numbers contained in the third column of this data? Data1: col1 col2 col3 col4 col5 906 552 743 348 45 676 229 425 661 558 469 642 430 384 773 913 485 125 628 312 105 152 25 22 179 746 782 291 911 339 737 101 318 801 211 562 295 654 746 511 185 238 957 814 907 598 531 936 384 629 300 92 458 618 102 135 406 241 576 391 213 105 764 531 55 895 113 760 276 502 72 785 741 249 432 243 292 744 452 998 54 604 106 228 812 442 965 682 805 486 14 433 464 987 895 898 695 213 30 138 197 759 99 536 391 94 433 824 88 928 308 656 176 803 918 457 110 164 990 714 102 934 666 67 619 996 188 895 940 344 333 267…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE L
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:9780357392676
Author:FREUND, Steven
Publisher:CENGAGE L
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