Project #22804 - Java

Create a class String Handler representing objects of input strings. A String Handler object must have private instance variable str, thus "private String str" which stores the string that was input as well as a static class variable nrOfObjects counting how many objects you have created.

 

(Every task should have it's own java file, so in total StringHandler.java + "Task 1.1-1.5".java)

 

Task 1.1 - 4p: Extend String Handler class with a getter method (to get the str string) and another getter method that counts the number of "words" (substrings separated by a space -> "Charlie 12 years" has 3 words). Create a class with a main method and a method of "printing." Main method to be graphically bring in a string by the user and create an object of type String Handler with the entered string as an input (ie, you have to create constructor in the String Handler class). The user shall be able to enter multiple strings until the "cancel" button, then the program should print the graphic from printing method in a window: 

 

"You pressed cancel." 

You have given <number of strings> strings. 

The latest string you gave were: 

<latest string>, it had <number of words> words " 

 

If the user enters a null string (press ok without keyboard press), the program should respond to this by not creating an object with an empty string. If the user enters spaces, this may be interpreted as a string (part of task 1.5). 

 

 

Task 1.2 - 8p: Extend the main method in 1.1 to create new objects for input strings. Main method must keep track of the n-last strings (n can be defined as final but shall be arbitrarily large -> no if-statements). 

So you have to write about the main to operate on a number of strings, and extend printing method. Print method will print the n most recently entered strings in order (last fed first, etc.). The printout must therefore with n = 5 and the following input be: 

1 11 

OK 

2 12 22 

OK 

3 13

OK 

4 14 Donald Stina 

OK 

5 15 Per-Ole Fjalar 

OK 

Java 

Cancel 

 

Printing: 

You pressed cancel. The last 5 strings you gave were: 

"Java" is one word. 

"5 15 Per-Ole Fjalar" has 4 words. 

"4 14 Donald Stina" has 4 words. 

"3 13" has 2 words. 

"2 12 22" has 3 words. 

 

 

 

 

Task 1.3 - 2p: Make objects mutable, ie, instead of creating a new string for each string, creating the first n and then you change the existing ones. Thus, you must create a setter in String Handler class and modify the main method to call on it atfter the nth created object. 

 

 

Task 1.4 - 3p: Extend the main method to react to empty strings and strings containing only spaces. The program should take note of this and if not change the items via setter created in 1.3. "Move" method of printing as well as any other methods from the class with the main to another class that you create (you have to import this new class to the main). 

 

Task 1.5 - 3p: Extend the main method to take and ask for the "cancel" if you want to parse the words you entered. The possibilities will be to parse with a character (char) or per word (String). Given the choice and input of the character / string, the printout to see how many instances of char / words that were in each string, for example, with Task 1.2 inputs should print with choice of char and 4 read: 

You pressed cancel. The last 5 strings you gave were: 

The string "Java" which has 0 numbers of symbols 4 

The string "5 15 Per-Ole Fjalar" which has 0 numbers of symbols 4

The string "4 14 Donald Stina" which has two numbers of symbols 4

The string "3 13" which has 0 numbers of symbols 4 

The string "2 12 22" which has 0 numbers of symbols 4

Subject Computer
Due By (Pacific Time) 02/13/2014 06:31 pm
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy