"Hello, Amigo! Enough messing around! Here are your tasks. They are going to be more difficult than the previous ones, and they'll be sure to improve your processor. And that's certainly something we need. If you run into difficulties, check with your colleagues. They'll definitely help."
20
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
"You did everything already? Well, here are some exercises that are even more difficult:"
12
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
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
Task
Java Core,
level 9,
lesson 11
Locked
Correct the bug. Classes and interfaces
This program has just 1 logical error. Find and fix it.
GO TO FULL VERSION