Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
11th Edition
ISBN: 9780134671604
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 12.11, Problem 12.11.1CP
Explanation of Solution
PrintWriter class:
The PrintWriter class helps to create the object for PrintWriter for text file creation and data can be written into that text file.
The syntax to create an object for PrintWriter class is given below:
PrintWriter objName = new PrinterWriter(filename);
Then, use the object of PrintWriter class to call the print, println, and printf method to write the data into file.
Reason to throws Exception in main method in WriteData.java:
In WriteData...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
How can I create a validation in java? for example: I want that the only possible entries be: a, b or c. If the user input any other character in the string should be invalid. For example, user enter: abc (is valid), user enter: ab (is valid), user enter: abt (invalid). Should I throw an exception?
Java Foundations :
Please provide code and explain. Thank you.
Write the code segments in main( ) and in methodA( ) for the following scenario:
main( ) passes methodA an int variable called a.
methodA generates an exception, but does not deal with it, if a is not between 1 and 100.
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.
Chapter 12 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
Ch. 12.2 - Prob. 12.2.1CPCh. 12.2 - Prob. 12.2.2CPCh. 12.2 - Prob. 12.2.3CPCh. 12.2 - Prob. 12.2.4CPCh. 12.2 - Prob. 12.2.5CPCh. 12.2 - Show the output of the following code:Ch. 12.3 - Prob. 12.3.1CPCh. 12.3 - Prob. 12.3.2CPCh. 12.4 - Prob. 12.4.1CPCh. 12.4 - Prob. 12.4.2CP
Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
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
- ABC airport has a list of travelers kept in a file (see below) and has asked you to write a complete Q7 program that reads from the user a filename and a destination and prints all the travelers (Format: --Last name, First name) that travelled to that destination. O points if you code everything in main. You should have at least 2 methods: main and one other method (excluding the readFile method). You can assume that the method: public static String (] [] readFile (String filename) is available (in the same program). That is, you can just use it to read from the file. It returns a String[][] with as many rows as lines in the file, and each row will have as many Strings as comma-separated items on that line in the file. For the sample file below, the String[]] will look like this: [ ["Alex Aiono","Johanesburg", "8-6-2017"], ["Marcus Schultz","Marrakech","1-24-2017"], ..] Sample file (travelers.txt) DO NOT HARDCODE THE FILE NAME. Alex Aiono,Johanesburg,8-6-2017 Marcus Schultz,Marrakech,…arrow_forwardNote: You must use proper naming convention for the Java code and you need to briefly elaborate keywords, concept, and logic in your own words. Task 2.2. Using the same scenario, implement (in Java) a console application for writing data to a sequential text file with a formatter class in Java. Implement createFile() method - To open/create a new file named as 'mec.txť with explanations of the methods involved. 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. Implement closeFile() method – Close the file with explanations of the methods involved. Note: You must use proper naming convention for the Java code and you need to briefly elaborate keywords, concept, and logic in your own words. Task 3 Dranare a ranort to nrocent the work done from taek 2 The…arrow_forward/The language is java. What is the difference between throw and throws an exception in java? say an example for each Exceptions(Arthimatic, FileNotFound, ArrayIndexOutOfBound,NumberFormat) with THROW and THROWS.arrow_forward
- in my code I am experiencing a problem with the inStack.peek() method. it is giving me an out of bounds exception "java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10" I have no idea why this is happening but i believe the problem is in the first for loop in the do while in the code. When the code goes through its second run of the do while loop it gives me the error message at the first instance of inStack.peek() method the comments explain what the code should do.please explain to me what the problem is in words not in code. queue is hidden due to character constraints. I have to use stacks and queues for this assignment no other data structure is allowed. is there any way to reset the stack to its original form? this is in java code. here is the code: MAIN FUNCTION import java.util.Scanner;import java.util.Random;public class test{public static void main(String[] Args){Scanner input = new Scanner(System.in); Random rand = new Random(); item maximum = new…arrow_forwardin my code I am experiencing a problem with the inStack.peek() method. it is giving me an out of bounds exception "java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10" I have no idea why this is happening but i believe the problem is in the first for loop in the do while in the code. When the code goes through its second run of the do while loop it gives me the error message at the first instance of inStack.peek() method the comments explain what the code should do.please explain to me what the problem is in words not in code. queue is hidden due to character constraints. this is in java code. here is the code: MAIN FUNCTION import java.util.Scanner;import java.util.Random;public class test{public static void main(String[] Args){Scanner input = new Scanner(System.in); Random rand = new Random(); item maximum = new item(0, 0); stackX inStack; stackX outStack; queue discardQueue; item itemObj; System.out.println("please enter the size of the array");int…arrow_forwardWrite the code in java and please don't plagiarize or copy from other sources write it on your own. Read carefully and follow the instructions in the question. Thank you.arrow_forward
- Write a JAVA program to handle index out of bound exception in an array with 5 elements {1,2,3,4,5}. Take input an index from the user and print the value at that index. Print the message "Invalid Index entered." using exception handling for index out of bound exception.arrow_forwardThis is a java program question dont copy from any other source or internet for gods sake write the program and give me the output also write the code in your own imagination dont copy it from other source pleasearrow_forwardWhat is the keyword throw used for? What is the keyword throws used for? Can you throw multiple exceptions in one throw statement? Explain with at least 3 or more examples in javaarrow_forward
- true or false. language is javaarrow_forwardJava : Write the code segments in main( ) and in methodA( ) for the following scenario: main( ) passes methodA an int variable called a. methodA generates an exception, but does not deal with it, if a is not between 1 and 100. Hint: main will try and catch the exception and methodA throws exception.arrow_forwardi got this error when I try to compile my code. What should I do? Should i change the name of my file (CompactDisc.java) to another? I already created a Song.java file, what command or action should I make next. import java.io.*; /** This program creates a list of songs for a CD by reading from a file.*/ public class CompactDisc{ public static void main(String[] args)throws IOException { FileReader file = new FileReader("Classics.txt"); BufferedReader input = new BufferedReader(file); String title; String artist; Song[] cd= new Song[6]; // ADD LINES FOR TASK #3 HERE // Declare an array of Song objects, called cd, // with a size of 6 for (int i = 0; i < cd.length; i++) { title = input.readLine(); artist = input.readLine(); //Song dc= new Song(title,artist); cd[i]= new Song(title,artist); // ADD LINES FOR TASK #3 HERE // Fill the array by creating a new song with…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