"Bună, Amigo! Destul de bătaie de cap! Iată sarcinile tale. Vor fi mai dificile decât cele anterioare și vor fi sigur că îți vor îmbunătăți procesorul. Și cu siguranță este ceva de care avem nevoie. Dacă întâmpinați dificultăți, consultați-vă colegii. Cu siguranță vă vor ajuta."
"Ai făcut totul deja? Ei bine, iată câteva exerciții care sunt și mai dificile:"
20
Sarcină
Java Core, nivel, lecţie
Tracking changes
Read 2 file names from the console: file1 and file2.
Both files contain text, but file2 is an updated version of file1. Some of the lines are still the same.
You need to create a merged version of the lines by writing them to the lines list.
The ADDED and REMOVED labels can't be used consecutively—t
20
Sarcină
Java Core, nivel, lecţie
Your own FileWriter
Implement FileConsoleWriter's logic.
The FileConsoleWriter class must have a private FileWriter field called fileWriter.
The FileConsoleWriter class must have every constructor used to initialize fileWriter for writing.
The FileConsoleWriter class must have five write methods and one close method:
-
20
Sarcină
Java Core, nivel, lecţie
Introducing tags
Read from the console the name of a file containing HTML.
Example:
Info about Leela Leela Turanga
Supergirl
The main method's first parameter is a tag name. For example, "span".
Display all tags that match the speci
12
Sarcină
Java Core, nivel, lecţie
Calculating salaries
The first parameter of the main method is a file name.
Each line of the specified file has the following format:
name value
where [name] is a String and [value] is a double. [name] and [value] are separated by a space.
Find the sum of all the values for each name.
Display all the data, sorted by na
12
Sarcină
Java Core, nivel, lecţie
The richest
The first parameter of the main method is a file name.
Each line of the specified file has the following format:
name value
where [name] is a String and [value] is a double. [name] and [value] are separated by a space.
Find the sum of all the values for each name.
Display in alphabetical order the
20
Sarcină
Java Core, nivel, lecţie
John Johnson
The first parameter of the main method is a file name.
Each line of the specified file has the following format:
name month day year
where [name] is a String that can contain several words separated by spaces.
[month] is an int, [day] is an int, and [year] is an int.
The data is separated by spaces.
12
Sarcină
Java Core, nivel, lecţie
Searching for the right lines
Read a file name from the console.
Display all of the file's lines that contain only 2 words in the words list.
Close the streams.
Example: words contains the words A, B, and C
Lines:
C B A D // 3 words from words, rejected
A B A D // 3 words from words, rejected
D A D // 1 word from words, rejecte
12
Sarcină
Java Core, nivel, lecţie
Words with numbers
The main method's first parameter is file1 and the second is file2.
file1 contains lines with words separated by spaces.
Write to file2 all the words that contain numbers, for example, a1 or abc3d. Separate the words with spaces.
Close the streams.
20
Sarcină
Java Core, nivel, lecţie
Replacing numbers
1. In a static block, initialize map with (number, word) pairs from 0 to 12 inclusive.
For example, (0, "zero"), (1, "one"), (2, "two")
2. Read the file name from the console, and then read the contents of the file.
3. Use map to replace all of the numbers with words.
4. Display the result.
5. Close
12
Sarcină
Java Core, nivel, lecţie
Long words
The main method's first parameter is file1 and the second is file2.
file1 contains words separated by spaces.
Write to file2 a comma-separated list of words longer than 6 characters.
file2 should not end with a comma.
Close the streams.
Example output to file2:
lengthy,shortened,abbreviation
12
Sarcină
Java Core, nivel, lecţie
Mirror image
1. Read a file name from the console. Read the contents of the file.
2. For each line in the file:
2.1. reverse the order of all characters.
2.2. display the result.
3. Close the streams.
Example input file:
I'm a programmer.
Amigo
Example result:
.remmargorp a m'I
ogimA
12
Sarcină
Java Core, nivel, lecţie
Contextual advertising
Replace the System.out object in the main method with your own reader wrapper.
Your reader wrapper should display a contextual ad after every other call to println.
Call testString's existing printSomething() method.
Restore the System.out variable back to the original stream.
Ad text: "CodeGym - o
12
Sarcină
Java Core, nivel, lecţie
Correct the bug. Classes and interfaces
This program has just 1 logical error. Find and fix it.