Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

BasicJavaRecap Season Finale

This recap exercise was produced by Professor Kitlei Robert

Using OO

  1. Pairs of command line arguments describe coordinates of points. Print the coordinates of the point that is farthest away from (0,0).

  2. Points are given as before. Print the closest point to the first one (excluding itself).

  3. Print the command line arguments so that consecutive 'a' characters are replaced by a single 'a' in them. Look at the documentation of String for an appropriate function.

  4. The first command line argument is a text, all other arguments contain two characters. Change all occurrences of the first characters to the second ones in the text.

  5. Print the first n lines of Pascal's function, where n is a command line argument.

  6. Let us make a board of size n times m. Shots are fired at the board, their coordinates are given similar to Exercise 1a. Draw the table so the 'X' marks fields that are hit and '.' otherwise.

  7. Let us simulate a direct elimination tournament. Our command line arguments are grouped the following way.

    • The first argument is the number of players (n). This number is always a power of two: 1, 2, 4, 8, 16...

    • The next n arguments are the names of the players.

    • The remaning n-1 arguments indicate the results of the matches.

      The first round has n/2 matches, the second one n/4, n/8, n/16 and so on, until the last round (the final).

      A '1' in the argument means that the top player wins the match, and a '2' means that the bottom one wins the match.

    The program has to print the results of the tournament in the following way.

    Example: if the input is 8 J1 J2 J3 J4 J5 J6 J7 J8 1 1 1 2 1 2 2 then the output is

       J1 J1 J1 J8
       J2
       J3 J3
       J4
       J5 J5 J8
       J6
       J7 J8
       J8
    
       round 1, players: J1 and J2, advances: J1, eliminated: J2
       round 1, players: J3 and J4, advances: J3, eliminated: J4
       round 1, players: J5 and J6, advances: J5, eliminated: J6
       round 1, players: J7 and J8, advances: J8, eliminated: J7
       round 2, players: J1 and J3, advances: J1, eliminated: J3
       round 2, players: J5 and J8, advances: J8, eliminated: J5
       round 3 (final), players: J1 and J8, champion: J8, finalist: J1
    

ONCE YOU ARE DONE, TAKE THIS HOMEWORK

  1. Using a Scanner...

    • read a string from the standard input, and print it on the standard output
    • read two numbers from stdin, and print their sum
    • read a line and print how many characters it contains (including whitespaces)
    • read a line and print how many words it contains
      • note: the words may be separated by more than one space
    • read a number (n) and print... A. the nth Fibonacci number B. the nth row of Pascal's triangle on one line
  2. Using a PrintWriter...

    • copy the contents of a file into another file line by line
    • like a., but the lines should be in reverse order (hint: use a Stack)
  3. A file contains filenames. These files contain integer numbers.

    • Print the name of the file that contains the smallest number.
    • Print the name of only those files that do not contain duplicate numbers. (hint: use a Set)
    • Calculate the sum of numbers for all of the files. Print the filenames with their sums in increasing order. (hint: use a Map)

About

Second batch of exercises on Basic Java

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages