Method called wordlengths that accepts a scanner

Assignment Help JAVA Programming
Reference no: EM13161169

Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file, count the number of letters in each token in the file, and output a result diagram of how many words contain each number of letters. Use tabs before the asterisks so that they'll line up. If there are no words of a given length, omit that line from the output.

For example, if the file contains the following text:

Before sorting:
13 23 480 -18 75
hello how are you feeling today

After sorting:
-18 13 23 75 480
are feeling hello how today you

your method should produce the following output to the console:

2: 6    ******
3: 10   **********
5: 5    *****
6: 1    *
7: 2    **
8: 2    **

You may assume that no token in the file is more than 80 characters in length.

My Code:

public class WordLengths {

WordLengths() {}
  
public static void wordLengths(Scanner scan) {
int[] lengthCountArray = new int[100];
for(int i = 0; i < 100; ++i) {
lengthCountArray[i] = 0;
}
while(scan.hasNextLine()) {
String line = scan.nextLine();
String[] words = line.split("\\s+");
for(int i = 0; i < words.length; ++i) {
int length = words[i].length();
++lengthCountArray[length];
}
}
for(int i = 1; i <= 80; ++i) {
if(lengthCountArray[i] > 0) {
System.out.print(i + ": " + lengthCountArray[i] + "\t");
for(int j = 1; j <= lengthCountArray[i]; ++j) {
System.out.print("*");
}
System.out.println("");
}
}
}
  
public static (String[] args) throws FileNotFoundException {
// say input filename is "input.txt";
String filename = "input.txt";
Scanner scan = new Scanner(new File(filename));
//WordLengths.wordLengths(scan);
}
}

Errors:

Your code did not compile. Please read and correct the errors below.

  • Line 29

    You have an illegal description of a data type here. Sometimes this happens when you misuse the syntax for generic types.

    illegal start of type

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You may have forgotten to end a statement with a semicolon. Each Java statement must end with a semicolon.

    ';' expected

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You have an illegal description of a data type here. Sometimes this happens when you misuse the syntax for generic types.

    illegal start of type

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You may have forgotten to type an identifier here, such as a variable's name or type.

    <identifier> expected

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You may have forgotten to end a statement with a semicolon. Each Java statement must end with a semicolon.

    ';' expected

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You have an illegal description of a data type here. Sometimes this happens when you misuse the syntax for generic types.

    illegal start of type

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You may have forgotten to type an identifier here, such as a variable's name or type.

    <identifier> expected

    public static (String[] args) throws FileNotFoundException { ^

  • Line 29

    You may have forgotten to end a statement with a semicolon. Each Java statement must end with a semicolon.

    ';' expected

    public static (String[] args) throws FileNotFoundException { ^ 8 errors

Reference no: EM13161169

Questions Cloud

Compute average memory access time : Compute Average Memory Access Time under a variety of memory system configurations and workload assumptions
State what is the frequency of light : A red laser pointer emits light with a wavelength of 660. What is the frequency of this light? 2.What is the energy of one of these photons?
How can predator populations function as agents : How can predator populations function as agents of natural selection in prey populations? How can prey populations function as agents of natural selection in predator populations?
The arm assembly language routine : For the ARM assembly language routine below, what function does it perform for the calling program?
Method called wordlengths that accepts a scanner : Write a method called wordLengths that accepts a Scanner representing an input file as its argument. Your method should read from the given file.
Method named isallvowels that returns : Write a method named isAllVowels that returns whether a String consists entirely of vowels (a, e, i, o, or u, case-insensitively). If every character of the String is a vowel, your method should return true. If any character of the String is a non-vo..
Multidimensional arrays : multidimensional arrays to life, let's consider a specific example: How can you visualize a 4-dimensional array? How can you give meaning to each dimension this array has? What kind of application would such an array be useful for?
What is the energy required to move a mole of urea out : What is the energy required to move a mole of urea out of the kidney cells and into the urine?
What is the minimal total weight of cylinders : A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of ..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Java problem - g queue

A queue is an ordered collection of items in which the removal of items is restricted to the FIFO ( rst in rst out) principle.

  Write java program to evaluate postfix expressions

Write a java program to evaluate postfix expressions containing complex numbers using a stack. This program should contain two classes.

  Write java program to enter number of marks

Write a java program called AverageMark.java. This program should allow the user to enter any number of marks and then display the minimum, maximum & average mark.

  Develop a graphical user interface based java program

Develop a Java program that can communicate with a real SMTP email server for sending emails. TNE 60003 - introduction to network programming, You program should provide a GUI and can successfully send the SMTP commands to the mail server

  Determine java application on web and structure functions

Determine the Java application on Web and explain how program structure functions. Explain the application in as much detail as possible.

  Develop java code to compute monthly rent for housing units

Develop a java code that computes monthly rent for 3 housing units namely Bungalows,Apartments and hostels. All housing units have got size,color and monthly rental rate.

  Create java application which creates random phone number

Create and implement Java application which creates and prints a random phone number of the form xxx-xxx-xxxx. Include the dashes in the output.

  Write java program to utilizes gui with five text fields

Write down the program called MaxMinAvgGUI.java which utilizes GUI with five(5)text fields which asks user to enter 5(five) decimal numbers. 1(one)number in each text field.

  Write java program to print price of table-furniture company

Write down the Java program for furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany. Illustrate the price of table produced with chosen wood.

  Write a class array that encapsulates an array

Write a class Array that encapsulates an array and provides bounds-checked access. The private instance variables should be int index and inarray[10]. The public members should be a default constructor and methods (signatures shown below) to provide ..

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd