Absolute Java (6th Edition)
6th Edition
ISBN: 9780134041674
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 2, Problem 18STE
Explanation of Solution
Given: The file named as player.txt is not present in the same directory of the
To find:Â The output of the program if there is not any file named with player.txt is present inside the same directory.
Solution:
If file named as player...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In Java
Suppose you are given a text file that contains the names of people. Every name in the file consistsof a first name and a last name. Unfortunately, the programmer that created the file of names hada strange sense of humor and did not guarantee that each name was on a single line of the file.Write a program that reads this file of names and writes them to a new text file, one name per line.For example, if the input file (Names.txt) contains:Bob Jones FredCharles EdMarstonJeffWilliamsThe output file (RecoveredName.txt) should be:Bob JonesFred CharlesEd MarstonJeff WilliamsSample Output:Enter the name of the input file:Names.txtEnter the name of the output file: RecoveredName.txtFile processing completed.
Write a Java program that print its own source code. Note: Don't use any file path
Write a Java program that reads in a paragraph of text from a file and prompts the user to enter a word to search for. The program should then output the number of times the word appears in the paragraph.
Here are the basic steps to implement this program:
Prompt the user to enter the name of the input file.
Read in the paragraph of text from the input file.
Prompt the user to enter a word to search for.
Search the paragraph for the word and count the number of times it appears.
Output the number of times the word appears in the paragraph.
To implement step 4, you can use a similar approach to the example I provided in class:
Split the paragraph into an array of words using the split() method.
Iterate through each word in the array and compare it to the search word (ignoring case).
If the word matches the search word, increment a counter variable.
Chapter 2 Solutions
Absolute Java (6th Edition)
Ch. 2 - Prob. 1STECh. 2 - Write Java statements that will cause the...Ch. 2 - What is the difference between System.out.println...Ch. 2 - Prob. 4STECh. 2 - What output is produced by the following code?
Ch. 2 - What output is produced by the following code? For...Ch. 2 - Write a Java statement to output the value in...Ch. 2 - What output is produced by the following code?...Ch. 2 - Suppose the class Robot is a part of the standard...Ch. 2 - Write an import statement that makes the Scanner...
Ch. 2 - Prob. 11STECh. 2 - Write a line of code that uses the object frank...Ch. 2 - Write a complete Java program that reads in a line...Ch. 2 - Write a complete Java program that reads in a line...Ch. 2 - Something could go wrong with the following code....Ch. 2 - Suppose your code creates an object of the class...Ch. 2 - Continue with the object keyboard from Self-Test...Ch. 2 - Prob. 18STECh. 2 - What is missing from the following code, which...Ch. 2 - The Babylonian algorithm to compute the square...Ch. 2 - (This is a version with input of an exercise from...Ch. 2 - Write a program that reads in two numbers typed on...Ch. 2 - John travels a distance of 55 miles at an average...Ch. 2 - Grade point average (GPA) in a 4-point scale is...Ch. 2 - (This is a better version of an exercise from...Ch. 2 - Write a program that determines the change to be...Ch. 2 - Write a program that reads in a string containing...Ch. 2 - (This is a better version of an exercise from...Ch. 2 - Write a program that inputs the name, quantity,...Ch. 2 - Write a program that calculates the total grade...Ch. 2 - (This is a variant of an exercise from Chapter 1.)...Ch. 2 - (This is an extension of an exercise from Chapter...Ch. 2 - From Programming Project 10 in Chapter 1,...
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
- In Java:arrow_forwardWrite a program that will open the file dataFile.csv, read its contents and print them out. Your output should look like this: First Last Age Wagejane Smith 21.00 21.50Jack Jones 20.00 19.50Edgar Martinez 22.00 22.75Zanab Sayegh 21.00 21.75 Could I get help doing this code in python. I can't put the file here but I put a screenshot of it in the images below. If I'm missing more details let me know. Thanks.arrow_forwardWrite a java program that will solve the problem: For a given ListADT that contains Items with numerical key value (integer), reorder it into two partitions of equal size such as the difference between the sum of those integers in the first partition and the second partition would be minimal. The program should have a class code separate from the main code. 1. Use a separate file to store the graph data. The name of the file should be "yourname_floyd.dat". 2. Use a few (3- 4) different graphs to compare actual performance (execution time).arrow_forward
- I need help with my assignment in my Java programing class. I have already created the "Monkey" class (#5) but need help in creating a loop (#6) as I struggle with loops since they are not clicking. Please see the picture for the criteria on the loop. Attached is also a picture of the first page of the driver class.arrow_forwardWrite a program that reads a file containing two columns of floating-point numbers Prompt the user of the file name.Print the average of each column. javaarrow_forwardfrom Big Java 6th. Edition. Ch.11 P11.12: the capacitor is represented by the equation v(t) = B(1 - e-t/(RC)) Suppose the parameters of the electric circuit are B = 12 volts, R = 500 Ω, and C = 0.25 μF. Consequently v(t) = 12(1 – e-0.008t) where t has units of μs. Read a file params.txt containing the values for B, R, C, and the starting and ending values for t. Write a file rc.txt of values for the time t and the corresponding capacitor voltage v(t), where t goes from the given starting value to the given ending value in 100 steps. In our example, if t goes from 0 to 1000 μs, the twelfth entry in the output file would be: 110.00 7.02261 Make sure that your program catches the FileNotFoundException that can occur if your input file params.txt cannot be found. Your program should catch this exception, and then prompt the user for a file name again until a valid file is entered. I hbelieve I have everything needed, but I cannot figure out how to write in the…arrow_forward
- Write a java program that uses a for loop or a while loop that reads a word and prints each character of the word on a separate line.arrow_forwardJava question: A text file called names.txt contains one name per line, e.g.,AllisonJohnWilliamJohnetc.Names can be duplicated in the file. Write the code that:1. Reads the names line by line.2. Stores each name and the number of times the name appears in one collection.3. Prints the number of different names to the console.4. Prints the names and how many times each name appears on the console.Think about what data structure would work in associating each name with the number of times it appears in the file. You do not need to write imports.arrow_forwardI have this homework where I have to search a word in a file and count how many words in and how long takes to find it. My code working well but counts the empty lines as words and I don't want the empty lines to be counted . would you look at it and see what I can add to it so the code will not count the empty lines in the file. Here the code import java.io.File;import java.io.FileNotFoundException;//scanner class for user inputimport java.util.Scanner;public class Uppgift2 {//main functionpublic static void main(String[] args) {//string to store input file nameString input_file;//check if argument is passed in command lineif (args.length == 0) {//if arg. is not passed initialise file to wordlist1.txtinput_file = "wordlist1.txt";} else {//else store the argumentinput_file = args[0];}try {//opening file in read modeFile fp = new File(input_file);//scanner object for input fileScanner scan = new Scanner(fp);//scanner object to take word inputScanner search = new…arrow_forward
- You should turn in FibonacciComparison.java and your plot (as a PNG). This can be a screenshot of the plot or the plot saved as a PNG file. Remember, your FibonacciComparison.java file should not be within a package other than src. This means the word "package" should not be at the top of the file signifying that the file is within a sub-directory of src. Your directory structure of your project should be: [project name] | src | | FibonacciComparison.java | | Pair.java There will be -15 points if one of the following happen: 1. Your code throws a compiler exception (meaning your code cannot be run) 2. You do not use FibonacciComparisonthe class name 3. Your FibonacciComparison.java file is within another packagearrow_forwardWrite a JAVA program to read array of numbers from a file and write even and odd numbers to two arrays in separate files.arrow_forwardin python. Please include docstring, so I can understand each step to this program. Thanks. you will import the json module. Write a class named NeighborhoodPets that has methods for adding a pet, deleting a pet, searching for the owner of a pet, saving data to a JSON file, loading data from a JSON file, and getting a set of all pet species. It will only be loading JSON files that it has previously created, so the internal organization of the data is up to you. The init method takes no parameters and initializes all the data members, which must all be private. The add_pet method takes as parameters the name of the pet, the species of the pet, and the name of the pet's owner. If a pet has the same name as a pet that has already been added, then the function should raise a DuplicateNameError (you'll need to define this exception class). The delete_pet method takes as a parameter the name of the pet and deletes that pet. The get_owner method takes as a parameter the name of the pet and…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