Question
please help me solve in java. public class ScannerMethods { /** * * Return the first int token contained in the provided * Scanner, even
please help me solve in java.
public class ScannerMethods {
/**
*
* Return the first int token contained in the provided
* Scanner, even if non-int tokens precede it. A token is
* any sequence of characters surrounded by whitespace.
* Non-int tokens preceding the first int are discarded.
* If no such int is found, then throw an IllegalArgumentException.
*
* @param scan Scanner containing tokens (at least one int token)
* @return The first int found in the scanner
*/
public static int firstInt(Scanner scan) {
// TODO: Return first int if found
// No int was found
throw new IllegalArgumentException("The Scanner must contain an integer!");
}
/**
*
* Count the number of tokens contained in a Scanner
* of a finite data stream (not from the console).
* All tokens that are counted are discarded from
* the Scanner. Use the Scanner's next method.
*
* @param scan Scanner on finite stream of data
* @return number of tokens in Scanner
*/
public static int countTokens(Scanner scan) {
return -1; // TODO
}
/**
*
* Count number of lines contained in a Scanner
* of a finite data stream (not from the console).
* All lines that are counted are discarded from
* the Scanner. Use the Scanner's nextLine method.
*
* @param scan scan Scanner on finite stream of data
* @return number of lines in Scanner
*/
public static int countLines(Scanner scan) {
return -1; // TODO
}
/**
*
* Take all lines from a Scanner connected to a finite
* data source and store them in an ArrayList in the order
* they are encountered.
*
* @param scan Scanner of finite data stream (not console)
* @return ArrayList of String lines from Scanner
*/
public static ArrayList
return null; // TODO
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started