notify
instead of notifyAll
), exercisesjava.util.logging
, which features similar functionality, and no external tools are needed.Create a class with a main
method. For all of the exercises below, put code in main
that tests the new content.
MyDate
class
enum
s Month
and Weekday
Month::getEnglishName
Month::getHunName
,Month::getXName
(where X
is your favourite language),enum Language
Weekday
sMyDate::getWeekDay
Weekday::isThisDay(Month month, int day)
Make a serializable class Book
that holds the following information:
title
author
year
pages
The class BookStore
stores books in a hash table, identifying them by their names. The class should implement the following methods:
// Puts some predefined books into the hash table, to serve as initial data.
void addSomeBooks();
// Loads the books from the given file.
// Returns whether the load operation was successful.
boolean loadBooks(String fileName);
// Writes the books into the given file.
// Returns whether the save operation was successful.
boolean saveBooks(String fileName);
Make a command line application that tests the above operations.
Make a simple client-server application whose parts communicate using TCP/IP. Use the classes Book
and BookStore
from the previous exercise.
The server accepts clients one after the other. When a client connects, the server does the following.
BookStore
.addSomeBooks
.true
to the client, then the book itself.false
to the client.The client connects to the server, and takes the appropriate steps, mirroring the server.
System.out.println
to print a given text 10000
times. (Give different texts to the threads.)
println
, print each text character by character (and an ending newline).
n
th Fibonacci number so that the non-basic cases compute the two halves of the addition on two threads.accept
ing them, each connection is handled by a separate thread. The client sends a number, and the server replies with the corresponding Fibonacci number.
Thread.sleep
).Use wait
and notifyAll
in the following exercises.
n
producers and n
files.m
consumers.
n
-tuple of produced words will be taken by only one consumer.n
-tuple of produced words will be taken by all consumers.compose
that takes two functions and returns their composition, which is another function.iterate
that takes a function f
and a (nonnegative) integer n
and returns a function that iterates f
n
times.'a'
characters in them.createArray
that fills in an array. It takes the length of the array as an argument, and an int->int
function f
. Use the f
function on each index of the array, and it will produce the value for the index.
createArray
generate an array of arbitrary depth?geneticAlgorithm
that runs a genetic algorithm. The algorithm takes a number of arguments.
populationCount
entities are created using createRandomEntity()
.doCrossover(Entity e1, Entity e2)
is invoked on two random entities. This is repeated crossoverCount
times.mutateEntity(Entity e)
is invoked on a randomly selected entity. The method, with mutationProbability
probability will change the entity in some way. (Usually, mutationProbability
is quite low, perhaps 0.1%.)calculateFitness(Entity e)
calculates the fitness of each entity. We only keep the best pruneCount
entities; we fill up the remaining places with createRandomEntity()
.generationCount
times, then return with the entity with the highest finess value of the last generation.Entity
type, use String
s. Your goal is to find a given String
goal
; the fitness values show how far our String
is from the goal
: let it be the difference of the lengths of the strings, plus the number of differing character positions. (Therefore, the best fitness value is 0, which is reached when we have reached the goal
.) A crossover splits both strings at random positions, and joins their first and second parts. A mutation changes a random character in the string.
n
prime numbers.Install aspects into Eclipse by opening Help>Install New Software
, pasting http://download.eclipse.org/tools/ajdt/44/dev/update
in the box, and selecting the required packages.
Airplane
class contains a fuel
field, and its getMaxFlightDistance
method returns how many kilometres it can fly. We have an instance gimliGlider
, whose fuel
field was unfortunately set in pounds, but because of the change in units, the return value of the getMaxFlightDistance
, which uses the fuel
field, expects its value in kilograms. Can you help the plane land in safety?
PrintFirstArgs
that is activated when a method in class Test
is called that has at least one parameter. The aspect should print the first parameter’s value on the command line.
Test
?CallerCallee
aspect, which counts how many method calls in the code are such that the caller object and the callee object are the same. For each such call, print the counter’s current value to the standard output.ExceptionLog
that logs into a file each exception that is thrown by the methods of the program.Entity
class a template parameter.Map<T,T>
and a Function<T,Optional<T>>
are very similar to each other. Given a value of type T
(the key of the Map
; the parameter of the Function
), both can say that this value is not present (the Map
doesn’t have the key; the Function
returns an empty Optional
), or they will associate it with another value of type T
. Make a class EmulateMapWithFunction
whose constructor takes such a Map
, and its method checkAttempt
will take a Function
and try to find a difference between the two.
Supplier<T>
parameter. As a first step, checkAttempt
uses this Supplier
to generate a value currentValue
.Map
and the Function
from currentValue
.
Map
can take a step and the Function
can’t, or the Map
can’t and the Function
can, then we have found a difference, and checkAttempt
returns the currentValue
, where the difference was found.Map
and the Function
can’t take a step, we couldn’t find a difference, and checkAttempt
returns an empty Optional
.Map
and the Function
take us to different values, then we have found a difference, and checkAttempt
returns the currentValue
, where the difference was found.Map
and the Function
take us to the same element. Take it as a new currentValue
, and continue taking steps.
currentValue
that we have already seen, checkAttempt
should return an empty Optional
, otherwise it would loop infinitely.checkAttempt
(in EmulateMapWithFunction
) to log all of the values that it progresses through.
checkAttempt
, and make an aspect that will take care of the logging. Use a data field in EmulateMapWithFunction
to store the most recently checked value.checkAttempt
are logged separately. Produce a file that contains the progressions with the accepted runs first, and then the rejected runs afterwards; in both parts, the progressions should be ordered by the number of progression steps.geneticAlgorithm
so that it also takes an entity as a parameter; this entity should always be a member of the population (that is, it should not be thrown out even if its fitness is too low).
geneticAlgorithm
is not less than that of this entity.geneticAlgorithm
into a separate function. Make a JUnit test case that checks that the size of the population at the beginning of every loop iteration equals the population count (which, for the sake of simplicity, should be the first parameter of geneticAlgorithm
).