Zadania z podstaw OO oraz kolekcji w Javie

Transkrypt

Zadania z podstaw OO oraz kolekcji w Javie
Zadania z podstaw OO oraz kolekcji w Javie
1. Napisz program, który dla pliku tekstowego o podanej nazwie wyznaczy statystyki
dotyczące wystąpień słów:
• 20 najczęstszych słów (słowo - liczba wystąpień), np:
and - 6109
the - 4867
...
• 20 najrzadszych słów, np:
bricked - 1
...
• 20 najdłuższych słów,
• wszystkie słowa, które są palindromami.
Uwaga – za słowo przyjmujemy tylko ciągi złożone z liter, cyfr, myślnika oraz podkreślenia. Jeżeli ciąg zawiera inny symbol nie jest liczony jako słowo. Do testów
można wykorzystać, np. „Adventures of Huckleberry Finn” M. Twaina dostępnego pod adresem:
http://www.gutenberg.org/dirs/7/76/76.txt
Wskazówka – do wygodnego zliczania słów warto użyć
java.utils.HashMap<String, Integer>
2. Na podstawie częstości słów z Zad. 1 wygenerować „chmurę słów” 400 najczęściej
używanych słów. Wielkość czcionki słowa powinna być proporcjonalna do liczby
wystąpień, przy czym minimalna wielkość czcionki to 20 pikseli, a maksymalna
to 70 pikseli.
Rysowanie można zrealizować generując stronę HTML o następującym szablonie:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
1
<body>
<-- Tutaj znaczniki dla słów -->
</body>
</html>
Dla każdego należy wygenerować ciąg postaci:
<div style="position:absolute;
left: 12px; top: 45px;
font-size: 30px">Słowo</div>
gdzie
• left: 12px oznacza współrzędną x,
• top: 45px oznacza współrzędną y,
• font-size: 3px to wielkość czcionki.
Współrzędne (x, y) słów należy wygenerować losowo z zakresu [0, 800], co da prostokątny obszar. Można też wygenerować je losowo w obrębie koła o promieniu
r = 400 oraz środku w punkcie (400, 400).
Przykładowa chmura dla teksu „Adventures of Huckleberry Finn” M. Twaina
pokazana jest na rys. 1.1.
2
shot
looking
middle
ready
allowed
sawyer
saying
up
long
that man
these
gonetalk
bank resteverybody
best
your
we
talked
tin
low
lot
mary
laying
want place
black
dropped
keep
maybe
hear
jumped
fool
name wish
trying
makes
thousand
think
when
many
talking days struck
but
somebody
show
just
which
all
anybody
nor
or
if
seem
about
much
raft
himself
poor woods
started
work have
same
still
try water
amongst
hide reckoned
home looked
has used
more
thing
too
room
well
chance
everything
stealwidow
wuz wrote
coming
set
own
bed
new she
canoe help
down
out
stay
might
felt
deadnothing
open
bad
ever
seen
as
miss
so
along
course
alwayshis
shoved
asked
showed
left
took
dark mars
last
laid other
under acrossme
mind
till
kill
leave
hardly
gwyne
him
goes
piece had for
roundbegun
judge
make
by
where enough
nobody
could hands lit stood
white
going
without
boy
after
another
though being
one
island
been
slow
hung are
believe
feel
six
done
stopped
how
behind
men
pap
called
fetched
some
foot
whole
made
aunt
runaway
run
he half right judged through
_was_ know
way
town
uncle
most
ben
head
our
little
below
fetch awfulgutenberg gotwent de tom
slid readwithriver
inwho
will
niggers
frontsee
king
at
straightlight money
person
log
while
such
dey
en
on
told dat
duke couple
old
er world
call
into
people
body
wait
said
nigger
first
three
take
knowed
hidhere
whilst
do
hanging
fix
thought
country
mile
found
electronic
chapter
time
hour
anyus lay
what
be
morning
side let
from
getting
no
you
high
go
their
_you_
glad
project
tell
hold
its
things
does
them door night
day house it anything
back
works
come
two
wanted
again
turned
_is_
her
full woman
something
write
is
becausekilled
mean
hand
give
they hundred
must
say
sign
kind didgood
put
look
like
every
five
considerable
easy
both
dollars
youngtrouble not
then
than
end
kept
clothes
there
sometimes
can
says
never
times
over
sally
heard
jimtriedmay
shut
turn
jane dig off this
waysfind
second
only
doing
comes
would
ten
against an
soon
before
sight
huck reckon
now
eyes
hard
use
get
minute
four prettymy
free
away
bet
doctor mighty
better around
stand
next
git fire
start
very
eachtowards
sound
eat
big
the
a
to
of
and
i
was
Rysunek 1.1: Przykładowa chmura słów do Zad. 1.
3