CSCI605 Week 3 Assignment 2 solution

$25.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (6 votes)

In general, a wrapper class is any class which “wraps” or “encapsulates” the functionality of another class or component. These are useful by providing a level of abstraction from the implementation of the underlying class or component.

Your assignment is to implement your own Scanner class. This class will be a wrapper class for Java’s implementation of the Scanner class.

The only constructor you need to implement accepts a string which names a file that your class will open.

The method’s you must implement are

public boolean hasNext()

public void close()

public String nextLine()

public int getLineCount()

public int getCharacterCount()

 

Note: The additional functionality you are adding is the line count and character count methods which will return the count for each respectively. Neither of these methods should impact the original functionality that your scanner class provides. That means the position in the file where your scanner is located must persist through line or character count calls.

 

You should write a main method that tests the functionality of your implementation.

 

Your file should be named MyScanner.java and you may only use basic java types.

 

Example:

 

>$ cat test_file.txt

first line

second line

third line

fourth line

 

>$java MyScanner

Print first 2 lines from file:

first line

second line

 

file line count: 5

file character count: 56

 

Next line in file:

third line

 

Grading:
Correctness: You can lose up to 20% if your solution is not correct
Quality: You can lose up to 20% if your solution is poorly designed
Testing: You can lose up to 20% if your solution is not well tested
Explanation: You can lose up to 40% if you cannot explain your solution during the grading session