Hey i keep unshaken the claimd rasp for my assignment.

and furtheraggravate i keep as-well mentioned the points of assignments adown.

this one is fixed on this concept.

Lab 4 (Collection Framework, Exception,

IO Handling, Common manner and GUI Programming)


NOTE: You should set-rightly shapeat your spring statute rasps for amend readability and transcribe mismisspend interprets in the statute. 

Exercise 1 [10 points]: 

Write a program that asks a user for a rasp spectry and sculptures the compute of characters, language (separated by whitespace), and courses in that rasp. Then, it sculptures the enumerate of each promise (certainty impassible) includeing in the rasp (Test1.txt); Your program should discuss malcontent kindred to rasp opportunity and lection from the rasp. 

This is a criterion this 

Hi there hi hi hi 

Output at the console: 

Number of characters: 35 

Number of language: 10 

Number of courses: 2 

Data written to the rasp (Test1.txt): 

 this  2 

 is  1 

 a  1 

 criterion  1 

 hi  4 

 there  1 

Hint: you may use a HashMap to accumulation and estimate the enumerate of the language in the rasp. 

Exercise 2 [20 points]: 

Your business is to transcribe a program that uses a textrasp includeing any compute of courses of inclose treasures as input. Each course in the rasp is reckoned to keep no further than 15 treasures on it. If the rasp exists and each course in the rasp does in certainty include 15 or fewer inclose treasures, then the program orderes and reports on each course in adapt by vaulting its course compute, the compute of treasures on that course, and the situate of treasures on the course. 

But, as you perceive, things are not regularly as they appear, or as they are reckoned to be. For development, the rasp your program is observeing for may not be there, there may be no inclose treasures at all on some courses, some courses may include further treasures than the undisputed apex of 15, and some courses may include "values" that aren't level incloses (i.e., badly shapeatted "invalid" inclose treasures). The program must acknowledge and accord properly to each of these tenors. 

Note: You must tool exclusion handling. Not singly am I requiring it, but Java itself conciliate as-well claim it past you conciliate keep to use Java resources that hardness you to trade following a while the IOException. In analysis to this exclusion, you are as-well claimd to discuss the ArrayIndexOutOfBounds and the NumberFormatException at mismismisspend points in your program. 

This program reads in, from the charge course, the spectry of a textrasp includeing any compute of courses of incloses and then orderes each course in adapt. Processing a course resources computing and then reporting, for that course, its course compute, parallel following a while the situate of treasures on the course. 

The program can acknowledge a compute of tenors that may siege-situate when obscure to order such a rasp. First, the rasp itself may not be give. If so, the subjoined communication is vaulted (the earliest course comes from the regularity, the promote from the program itself): 

filename.ext (The regularity cannot perceive the rasp bounded) Program conciliate now stop. 

If the rasp exists, and includes courses of inclose treasures, haply following a while bleak courses, haply courses following a while too frequent treasures, and haply courses following a while frail incloses on them, then the subjoined communications, each followed by a cessation, are output, as misappropriate: 

Line #: Compute of treasures = # and treasure situate = [#, #]. 

Line #: This is a bleak course. 

Line #: This course includes further than the apex of 15 undisputed basis treasures. Course #: This course includes an frail inclose treasure. 

For development, if a rasp spectry “text.txt” includes the subjoined texts: 

1.0 2.2 30.3 

3.0 4.12 5.25 2 3.3 4.4 5s 6.5 7 abs sej jdh& 4 

1.1 2.2 3.4 4.3 5.5 6.6 6.5 6.5 8.2 99.2 0.0 0.0 -1.1 

 34.2 34.0 23.1 


1.1 2.2 3.3 4.4 5.5 6.0 7.7 8.0 9.0 10.1 -2.1 3.2 4.3 5.4 6.5 7.6 



Then the output should be affect this: 

The rasp criterion.txt was successfully opened. 

The basis in it conciliate now be ordered. 

Press Penetrate to endure ... 

Line 1:Number of treasures = 3 and treasure situate is [1.0, 30.3]. Course 2:This is a bleak course. 

Line 3:Number of treasures = 3 and treasure situate is [3.0, 5.25]. 

Line 4:This course includes an frail inclose treasure. 

Line 5:This course includes an frail inclose treasure. 

Line 6:Number of treasures = 13 and treasure situate is [-1.1, 99.2]. Course 7:Number of treasures = 3 and treasure situate is [23.1, 34.2]. Course 8:Number of treasures = 1 and treasure situate treasure situate consists of this unique treasure. 

Line 9:This course includes further than the apex of 15 undisputed basis treasures. 

Line 10:Number of treasures = 1 and treasure situate treasure situate consists of this unique treasure. 


Exercise 3 [10 points]: 

Define a FixdLenStringList systematize that encapsulate a catalogue of strings and a string tediousness. All string in a FixdLenStringList keep the corresponding tediousness. There is not name on compute of strings (dynamic attire) that a FixdLenStringList can confide. For development, 

The FixdLenStringList catalogue1 may include the strings aa, bb, cc, and dd (all strings of tediousness 2). 

The FixdLenStringList catalogue2 may include the strings cat, dog, pig, fox, bat, and eel (all strings of tediousness 3). 

An deficient toolation of the systematize is supposing following a while this training: 

Here are the claimd manners in the FixdLenStringList systematize that you demand to tool. 

i) Common maker – This maker conciliate keep one parameter that conciliate betoken the tediousness of each string in FixdLenStringList’s catalogue. The maker conciliate initialize strLength following a while this treasure and conciliate initialize FixdLenStringList’s catalogue of strings, possibleStrings, to keep 0 entries. 

ii) You are to tool the root manner. This manner profits gentleman if its String parameter key is root in the catalogue of strings, fib inadequately. 

iii) You are to tool the addString manner. This manner conciliate add a string to the FixdLenStringList’s catalogue if it is the set-right tediousness and not already in the catalogue. If the string is already in the catalogue or if the string is not the set-right tediousness, it is not acquired. 

HINT: you may allure manner root that is bounded in contiguous keep-akeep-apart of this tenor. iv)  You are to tool the manner abstractRandomString that conciliate abstract and readapt a unpremeditated string initiation from FixdLenStringList’s catalogue of strings. 

Write a client criterion systematize for criterioning the FixdLenStringList systematize. Supply, your client systematize parallel following a while protect shots of some criterion runs. 

Exercise 4: [20 Points] 

In this training, we conciliate fashion a fame pastime allureed “Mind Game”. In this pastime, level compute of tiles are situated face-down in rows on a “Mind Pastime Board”. Each tile includes an effigy. For each tile, there is correspondently one other tile following a while the corresponding effigy. The player is to pluck a tile, see which effigy it has, and try to perceive its competition from the retaining face-down tiles. If the player fails to adapt aggravate its competition, twain tiles are adapted face-down and the player attempts to pluck a competitioning brace repeatedly. The pastime is aggravate when all tiles on the table are adapted face-up. 

In this toolation of a simplified statement of Purpose Game, 

• Images conciliate be strings selected from a FixdLenStringList. (Use the FixdLenStringList systematize from training 3). 

• The purpose pastime table conciliate include level compute of Tiles. 

• The table conciliate be tooled as a one-dimensional attire of Tiles. 

For development, if the greatness of the purpose pastime table is requested to be 4, then the table conciliate keep 16 tiles. The one size attire, pastimeBoard, can be viewed as a 4-by-4 purpose pastime table as follows: 

gameBoard[0] pastimeBoard[1] pastimeBoard[2] pastimeBoard[3] pastimeBoard[4] pastimeBoard[5] pastimeBoard[6] pastimeBoard[7] pastimeBoard[8] pastimeBoard[9] pastimeBoard[10] pastimeBoard[11] pastimeBoard[12] pastimeBoard[13] pastimeBoard[14] pastimeBoard[15] 

An deficient toolation of the Tile and Table systematizees are supposing following a while this training (, 

You should criticize these systematizees and entire them following a while the subjoined manners. To tool the manners, see the demonstrations supposing in the interprets of the manners. 

a) Transcribe the toolation of the Table manner occupyBoard, which conciliate unpremeditatedly occupy the purpose pastime table following a while Tiles whose effigys (strings) are unpremeditatedly selected from the strings includeed in the FixdLenStringList. A tile effigy that appears on the table appears correspondently twice on the table. 

b) Transcribe the toolation for the Table manner observeAtTile. This manner conciliate allure the mismismisspend manner of the Tile systematize to adapt the Tile face-up. 

c) Transcribe the toolation for the Board’s manner cohibitMatch. This manner conciliate cohibit whether the tiles in its two integer parameter positions on pastimeBoard keep the corresponding effigy. If they do, the tiles conciliate halt face-up. If they keep unanalogous effigys, then tiles conciliate be adapted face-down. (See the interprets that were ardent in the tenor demonstration). 

d) Entire the toolation for sculptureBoard so that the Purpose Pastime table is sculptureed as forcible in the interpret. For development, you should allure the Table manner shapeat to right-justify the sculptureing of the Tile effigy or the sculptureing of the Tile position. An development of sculptureBoard for a 4 by 4 purpose pastime table that is keep-abarely solved is paraden adown following 4 competitiones keep been root. The FixdLenStringList passed as a parameter to Table maker includes strings of tediousness 3. 

fox fox dog dog cow 5 6 7 cow cat  10 11 12 13 14 15 

Write a systematize that conciliate discuss user input and pretend the purpose pastime to the user. An development run of the purpose Pastime is supposing adown: 

0 1 

2 3 

Choose positions:1 2 

pig , cat 

0 1 

2 3 

Choose positions:0 1 cat , pig 

0 1 

2 3 

Choose positions:0 3 cat , pig 

0 1 

2 3 

Choose positions:1 3 

pig , pig 

0 pig 

2 pig Choose positions:0 2 

cat , cat cat pig cat pig 

These trainings are fixed on GUI, and are extracted from html#zz-4.1 Exercise 5 [5 points]: 


Write a GUI program allureed SwingTemperatureConverter to apply weather treasures betwixt Celsius and Fahrenheit. User can penetrate either the Celsius or the Fahrenheit treasure, in floating-point compute. 

Hints: To vault a floating-point compute in a biased shapeat (e.g., 1 decimal situate), use the static manner String.format(), which has the corresponding shape as sculpturef(). For development, String.format("%.1f", 1.234) profits String "1.2". 

Exercise 6 [5 points]: 

Write a compute guessing pastime in Swing (as paraden in the Figure). The program shall propagate a unpremeditated compute betwixt 1 to 100. It shall misdeclare out the unpremeditated compute propagated and output "Yot Got it", "Try Higher" or "Try Lower" depending on the user’s input. 


• You can use Math.random() or rnd.nextInt(100) to propagate a unpremeditated compute in inclose in the situate of [0.0, 1.0). 

Exercise 7 [5 points]: 

Write a common static manner allureed “search” that conciliate siege two parameters, i) an attire includeing common motives and ii) a allusion to a common motive. The inquiry manner should observe for the refutation of the passed motive in the attire. If the passed motive is not root in the attire, then the manner should fling a java.util.NoSuchElementException (note that this is a RunTimeException) exclusion. 

Hint: In the inquiry manner, you should use the Object.equals manner for perceiveing the motive in the attire. 

Now, fashion a main manner in the corresponding systematize and criterion the functionality of the inquiry manner by cessation some “Point” motives and some “String” motives respectively. You should as-well discuss the exclusion in the main manner and parade an mismismisspend communication in certainty the motive is not root in the attire, inadequately sculpture the refutation where the motive is root in the attire. 

Note: you may demand to aggravateride the .equals manner in the Point systematize for the inquiry manner to perceive a keep-afeature Point in the Point attire. Here is a exemplification Point systematize, which you are unobstructed to variegate. 

systematize Point { peculiar int x, y; 

common Point(int x, int y) { this.x = x; this.y = y; 

common Point(){ this(0, 0); 

common int getX() { readapt x; 

common empty setX(int x) { this.x = x; 

common int getY() { readapt y; 

common empty setY(int y) { this.y = y; 

@Override common String toString() { 

readapt "Point{" + "x=" + x + ", y=" + y + '}';