Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please i need some help with my programing assigment in Java Part 1. A. Take som

ID: 3796809 • Letter: P

Question

Please i need some help with my programing assigment in Java

Part 1.  

A. Take some notes on JavaDoc, and include them in your submission.

B. This is a separate exercise – go search out the description of these concepts.

Describe each of the following:

Wrapper classes

Immutable objects

Tokenizing strings

The differences between String and StringBuffer class

String objects and == operator vs. the equals() method - what is the difference?

Part 2.

I will include a text file with this assignment. It is a text version of this assignment.

Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number.  

Part 3. Programming with String obejcts.

Create a class to deal with telephone numbers that your customers enter.

User’s aren’t very disciplined, so even if you indicate that you want the number entered like this:

407 582 2213

They sometimes enter the number like any of these:

(407)582-2213

1 (407) 582-2213

407.582.2213

4075822213

1 407 582-2213

Or other combinations that I can’t think of, but they will.

The constructor for your class takes a String as its only parameter.

If the number they pass to your constructor does not have 10 digits, (or 11 digits if it starts with a 1), you should throw an Exception from the constructor.

  InvalidTelephoneException. It’s the Telephone constructor method that will throw this exception.

A test of your class can be though of as: try to make a phone number out of a String.

Telephone phone;

String testString = “407.582.2213”;

try {

    phone = new Telephone(testString);

}catch(InvalidTelephoneException ite) {

    Send some information to the console about why that string is not a phone number

}

Your class must have a getAreaCode, getExchange, getLocalNumber methods. For the example above, the area code is 407, the exchange is 582, and the local number is 2213.

Follow good practices for OO programming.

A toString method will present the number in a canonical form: (407) 582-2213

Create a test class that demonstrates that your code will work correctly for each of the documented cases above.

Include all of the code, and the output from running your test class.

·       Use JavaDoc comments to document the class. Include examples IN THE JAVADOC of what format of phone numbers will be acceptable by the class (service provider) that you have created.

http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

Include the JavaDoc that is generated by running the JavaDoc tool on your code. Paste in the web page that is created. It might be messy - don’t try to format it in Word.

There is no end to this one….   The ‘service’ that this class provides will vary in its capabilities.   This is a pretty common real-world problem. As soon as you think you are done someone will want it to handle something that you didn’t think of. You are ‘done’ when your code meets the requirements that are documented, and it is demonstrated.

Part 2. I will include a text file with this assignment. It is a text version of this assignment. Write a program that will read the file line by line, and break each line into an array of words using the tokenize method in the String class. Count how many words are in the file and print out that number.

Explanation / Answer

As the highlighted portion is only Part 2, I am assuming, we need to code only for that.

---------------------------------------------------------------------------------------------------------------------------------------------------

WordCount Class

import java.io.File;
import java.util.Scanner;
import java.util.StringTokenizer;

public class WordCount {

   public static void main(String[] args) {
       Scanner txtscan;
       try {
           txtscan = new Scanner(new File("D:\abc.txt"));

           int totCount = 0;

           while(txtscan.hasNextLine()){

               String str = txtscan.nextLine();

               StringTokenizer stringTokenizer = new StringTokenizer(str, " ");

               while (stringTokenizer.hasMoreElements()) {
                   totCount++;
                   stringTokenizer.nextElement();
               }
           }
          
           System.out.println("Number of words in the file are : "+totCount);

       } catch (Exception e) {
           e.printStackTrace();
       }

   }

}

-----------------------------------------------------------------------------------------------------------------------------------------------------------

abc.txt file

I am a boy
hello how r u

Output of the code for this file

Number of words in the file are : 8