Print the file on the BlueJ console Java  Filename: input.txt Number of lines: 5 Longest Line: 10 Total number of characters: 33 Asterisk character found at 3,2

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I need help

Print the file on the BlueJ console Java 


Filename: input.txt

Number of lines: 5

Longest Line: 10

Total number of characters: 33

Asterisk character found at 3,2

 

xxxxxxxxx

xxxxxxx

xxx*xxxxxx

xx

xxxxx

Work done so far (my code)


// we need to import this library for classes to read and write files
import java.io.*;
import java.util.Scanner;
import java.io.FileReader;


/**
* Write a description of class FileStats here.
*
* @author (Tanishq Verma)
*/
public class FileStats
{

/**
* Constructor for objects of class FileStats
*/
public FileStats()
{

}

public static void main(String args[]) {

// Assignment 5 Part A 

// print out a message to help show where we are at in the console
System.out.println(
"\n\nFileStats program running!!");

// create a scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);

// Get the filename from user input
System.out.print("Enter the filename: ");
String filename = keyboard.nextLine();

// Create a new File object
File file = new File(filename);

// If the file does not exist, default to "input.txt"
if (!file.exists()) {
// Display an error message.
System.out.println(
"Sorry that file doesn't exist, tring input.txt");
filename = "input.txt";

// try creating the File again using input.txt
file = new File(filename);
}

System.out.println("Reading in file: " + filename);

// use try to check for errors
try {
// create a new Scanner object to read the file
Scanner inputFile = new Scanner(file);
int lineCounter=0;
int strl=0;
int max=0;
int xC=0;
int yC=0;



while (inputFile.hasNext()) {
String str = inputFile.nextLine();
int lineLength=str.length();
lineCounter++;
for (int x=0; x < lineLength; x++){
char next=str.charAt(x);
if(next=='*'){
xC=x-1;
yC= lineCounter;
}
}

//if(strl > max){
// max=strl;
// }

//count++;


// Assignment 5 - Part A
// For now, we are just printing it out, you need
// to count number of lines etc.!
System.out.println(str);

System.out.println("the number of line is "+ );
System.out.println("the number of character "+ );
System.out.println("the number of Longest Line is "+ );
System.out.println("the number of Asterisk character fount line "+ );


}

// close the file when done.

} catch (FileNotFoundException e) {
System.out.println("Error reading file: " + e.toString());
System.exit(1);
}

}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Constants and Variables
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education