
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Topic Video
Question
in java
Declare a FileOutputStream named outStream and a PrintWriter named dataFS.
Ex: If the input is leek.txt 37.5, then leek.txt contains:
37.5 kilograms of leeks
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.IOException;
public class LeekFileOutput {
publicstaticvoidmain(String[] args) throwsIOException {
Scannerscnr=newScanner(System.in);
StringleekFileName;
doubleleekQuantity;
/* Additional variable declarations go here */
leekFileName=scnr.next();
outStream=newFileOutputStream(leekFileName);
dataFS=newPrintWriter(outStream);
leekQuantity=scnr.nextDouble();
dataFS.println(leekQuantity+" kilograms of leeks");
dataFS.close();
}
}
SAVE
AI-Generated Solution
info
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
Unlock instant AI solutions
Tap the button
to generate a solution
to generate a solution
Click the button to generate
a solution
a solution
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
- Write an Java application that counts the total number of spaces contained in a quote entered by the user. import java.util.*; public class CountSpaces2 { public static void main(String[] args) { // Write your code here } }arrow_forwardpackage encrypt1; import java.io.*;import java.util.*; public class Encrypt1 { public static void main(String[] args) { if(args.length!2) ERROR MESSAGE { System.out.println("Invalid number of argumentss. Usage:src target"); } try { BufferedInputStream in = new BufferedInputStream (new FileInputStream(args[0])); // Create BufferedOutputStream from bos BufferedOutputStream out = new BufferedOutputStream (new FileOutputStream(args[1])); // Declare the variable num int buffer; // Checks content in the variable num is not equal to -1 while ((buffer=in.read())!=-1) { // Call the function Write() out.write(buffer+5); } System.out.println("Encrypted file saved"); } catch(IOException ex) { ex.printStackTrace(); }}}arrow_forwardIN JAVA What is the error in writeFile( )? public static void writeFile() throws IOException{ FileOutputStream foStream = null; PrintWriter outFS = null; foStream = new FileOutputStream();outFS = new PrintWriter(foStream);outFS.println("Java is my favorite language!");outFS.flush();foStream.close(); } A. The output stream has not been properly opened B. writeFile( ) should throw PrintException C. outFS has not been closed D. foStream has not been flushedarrow_forward
- I need help with my code Ask the user for a filename. Display the oldest car for every manufacturer from that file. If two cars have the same year, compare based on the VIN. here is my code so far import java.io.File;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;class Car {String manufacturer;String model;int year;String vin;public Car(String manufacturer, String model, int year, String vin) {this.manufacturer = manufacturer;this.model = model;this.year = year;this.vin = vin;}public String getManufacturer() {return manufacturer;}public void setManufacturer(String manufacturer) {this.manufacturer = manufacturer;}public String getModel() {return model;}public void setModel(String model) {this.model = model;}public int getYear() {return year;}public void setYear(int year) {this.year = year;}public String getVin() {return vin;}public void setVin(String vin) {this.vin = vin;}}public class Demo {public static void main(String[] args)…arrow_forwardPlease help I don’t understand what I am getting errors inarrow_forwardI need help fixing this java program below: import java.util.Scanner;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.PrintWriter;import java.io.IOException; public class LabProgram { public static void main(String[] args) throws IOException { Scanner scnr = new Scanner(System.in); String fileName; String[] lastNames, firstNames; int[] midterm1, midterm2, finalScores; // Read a file name from the user and read the tsv file fileName = scnr.next(); try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) { int numStudents = Integer.parseInt(fileScanner.nextLine()); lastNames = new String[numStudents]; firstNames = new String[numStudents]; midterm1 = new int[numStudents]; midterm2 = new int[numStudents]; finalScores = new int[numStudents]; for (int i = 0; i < numStudents; i++) { lastNames[i] =…arrow_forward
- New JAVA code can only be added between lines 27 and 29. As seen in image.arrow_forwardplease see image for instructions starter code for Main.java import java.io.*;import java.util.*;; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(countConnectedComponents("data.txt")); } public static int countConnectedComponents(String fileName) { try { //the file to be opened for reading FileInputStream fis=new FileInputStream(fileName); Scanner sc=new Scanner(fis); //file to be scanned //returns true if there is another line to read ArrayList<int []> edge = new ArrayList<int[]>(); Set<String> set = new HashSet<String>(); while(sc.hasNextLine()) { int temp [] = new int[2]; int index = 0; for(String s : sc.nextLine().split(" ")) { temp[index] =…arrow_forwardJAVA PROGRAM MODIFY AND CHANGE THIS PROGRAM EVEN MORE FOR THE FOLLOWING: IT MUST PASS THE TEST CASE WHEN I UPLOAD IT TO HYPERGRADE. I EVEN CHANGED THE TEXT FILES NAMES. I HAVE ALSO PROVIDED THE BOYMNAMES.TXT AND GIRLNAMES.TXT WHICH ARE INPUTS AND THE FAILED TEST CASES AS A SCREENSHOT. THANK YOU import java.io.*;import java.util.*;public class NameSearcher { private static List<String> loadFileToList(String filename) throws FileNotFoundException { List<String> namesList = new ArrayList<>(); File file = new File(filename); if (!file.exists()) { throw new FileNotFoundException(filename); } try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String[] names = line.split("\\s+"); for (String name : names) { namesList.add(name.toLowerCase()); } } }…arrow_forward
- I need this in JAVAarrow_forwardWhat is wrong with this code it creates a file Exercise17_1 but no input into the file? package randomintegers; import java.io.*;import java.util.*; public class RandomIntegers { public static void main(String[] args)throws Exception{ PrintWriter out = new PrintWriter(new FileOutputStream("Exercise17_1.txt",(true)); { for(int j=0;j<100; j++) out.print((int)(Math.random()*100000)+""); } }}arrow_forwardPlease help me using java. I am not understanding why I am getting errorsarrow_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