lab1/description.html
2016-02-01 12:28:43 +02:00

233 lines
12 KiB
HTML

<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="GENERATOR" content="Mozilla/4.76 [en] (Win98; U)
[Netscape]">
<title>API kordamine</title>
</head>
<body>
<h2 style="margin-left: 40px;">Java API<br>
</h2>
<div style="margin-left: 40px;">This lab is for practicing Java -
you have to find descriptions of the following classes and solve a
set of small problems.<br>
</div>
<p style="margin-left: 40px;"><tt>java.lang.String</tt> <br>
<tt>java.lang.StringBuffer/StringBuilder<br>
java.lang.Character</tt> <br>
<tt>java.lang.Integer (-&gt; Double, ...)</tt> <br>
<tt>java.lang.Math</tt> <br>
<tt>java.lang.Comparable</tt> </p>
<p style="margin-left: 40px;"><tt>java.util.StringTokenizer</tt> <tt><br>
java.util.Calendar</tt><br>
<tt>java.util.Random</tt> <tt><br>
java.util.ArrayList</tt> <tt><br>
java.util.HashMap</tt><br>
<span style="font-family: monospace;">java.util.Set</span><br>
<tt>java.util.List<br>
java.util.Collection<br>
java.util.TreeSet<br>
</tt><tt>java.util.Arrays<br>
java.util.Iterator<br>
</tt></p>
<p style="margin-left: 40px;">...<br>
&nbsp; </p>
<h3 style="margin-left: 40px;">Problems</h3>
<div style="margin-left: 40px;">
<ul>
<li>Convert a given double number (<span style="font-family:
monospace;">double</span>) into String (<span
style="font-family: monospace;">String</span>).</li>
<li>Convert a string (<span style="font-family: monospace;">String</span>)
into an integer number (<span style="font-family: monospace;">int</span>).
Assume that the string actually represents an integer
(Discover what happens, if the string is illegal?).</li>
<li>Take the current moment of time from the computers inner
clock and form a string "hours:minutes:seconds" (use 24h
notation, e.g. "13:25:10").</li>
<li>Find a cosine of a given angle that is expressed in degrees.</li>
<li>Print a table of square roots for numbers from 0 up to 100
using step 5 (print two numbers per line: argument and its
square root).</li>
<li>Given a string replace in it all uppercase letters with
corresponding lowercase letters and all lowercase letters with
corresponding uppercase letters. Do not change other symbols (<span
style="font-family: monospace;">"ABcd12"</span> -&gt; <span
style="font-family: monospace;">"abCD12"</span>). Use <span
style="font-family: monospace;">StringBuffer</span> or <span
style="font-family: monospace;">StringBuilder</span> class
for intermediate result. Create an independent method <code
id="yui_3_2_0_1_1314010804247640">String reverseCase (String
s) </code>for this task.</li>
<li>Given a string find its reverse (<span style="font-family:
monospace;">"1234ab"</span> -&gt; <span style="font-family:
monospace;">"ba4321"</span>).</li>
<li>Given a text (<span style="font-family: monospace;">String</span>)
find the number of words in it. Words are separated by any
positive number of any kind of whitespaces (like space, tab,
...). Create an independent method <code>int countWords
(String t) </code>for this task.</li>
<li>Register the current time, pause the program for 3 seconds,
register the current time again and print the difference
between these two moments of time in milliseconds.</li>
<li>Create a list (<span style="font-family: monospace;">ArrayList</span>)
of 100 random integers (<span style="font-family: monospace;">Integer</span>)
in between 0 and 999. Print the result. What is the difference
between<span style="font-family: monospace;"> int </span>and
<span style="font-family: monospace;">Integer</span>?</li>
<li>Find the minimal element of this list. How to find the
minimal element of any <span style="font-family: monospace;">List</span>
of <span style="font-family: monospace;">Comparable</span>
elements (read about interfaces, also consider that <span
style="font-family: monospace;">ArrayList implements List </span>and
<span style="font-family: monospace;">Integer implements
Comparable</span>)?</li>
<li>Create a hashtable (<span style="font-family: monospace;">HashMap</span>)
containing 5 pairs of strings, where "subject code" serves as
a key and "subject name" serves as a value (e.g. <span
style="font-style: italic;">("I231", "Algorithms and Data
Structures")</span> , just choose any subjects you like).</li>
<li>Print all the keys of this hashtable (one key per line).</li>
<li>Remove one of the subjects from the hashtable.</li>
<li>Print all pairs from this hashtable (each pair on separate
line).</li>
<li>Reverse the order of elements of the list you have created
before. Write an independent method<code> </code>to reverse
any list. The method signature is</li>
</ul>
<div style="margin-left: 80px;"><span style="font-family:
monospace;">public static &lt;T extends Object&gt; void
reverseList (List&lt;T&gt; list)</span><br style="font-family:
monospace;">
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
throws UnsupportedOperationException </span><br>
</div>
</div>
<div style="margin-left: 40px;"><br>
<div style="margin-left: 40px;">Output the result and check that
it is correct.<br>
</div>
</div>
<div style="margin-left: 40px;">
<ul>
<li>Write an independent method to find the maximal element of
any Java collection (you can use your list for testing). The
method signature is</li>
</ul>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;"><span style="font-family:
monospace;">static public &lt;T extends Object &amp;
Comparable&lt;? super T&gt;&gt; T</span> <span
style="font-family: monospace;">maximum (Collection&lt;?
extends T&gt; a) </span><br>
<span style="font-family: monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
throws NoSuchElementException</span><br>
</div>
</div>
<br>
You have to upload your full solution to <a
href="https://moodle.hitsa.ee/">Moodle</a> !<br>
<br>
Git repository address: <a
href="https://jpoial@bitbucket.org/i231/lab1.git">https://jpoial@bitbucket.org/i231/lab1.git</a><br>
</div>
<div style="margin-left: 40px;"> <br>
<hr style="width: 100%; height: 2px;"></div>
<h3 style="margin-left: 40px;">Oskused, mis tuleks praktikumide
käigus omandada:</h3>
<ul style="margin-left: 40px;">
<li>informatsiooni kiire leidmine API kirjeldusest&nbsp;</li>
<li>teisendused ühest tüübist teise, mähisklasside kasutamine</li>
<li> &nbsp;lihtsate arvutuste tegemine</li>
<li> &nbsp;sõnetöötlus, sõnepuhvri kasutamine</li>
<li> &nbsp;aega väljendavate andmetega manipuleerimine</li>
<li> &nbsp;juhuslike andmete genereerimine</li>
<li>&nbsp;listi ja paisktabeli kasutamine, iteraatorid</li>
</ul>
<h3 style="margin-left: 40px;"> Ülesanded:</h3>
<div style="margin-left: 40px;">Koostage peameetod (<tt>main</tt>),
mis sisaldaks lahendust järgmistele probleemidele: </div>
<ul style="margin-left: 40px;">
<li>&nbsp; Teisendada etteantud reaalarv (<span
style="font-family: monospace;">double</span>) sõneks (<tt>String</tt>).</li>
<li>&nbsp; Teisendada etteantud sõne täisarvuks (eeldusel, et see
sõne väljendab täisarvu).</li>
<li>&nbsp; Võtta arvuti kellalt jooksev näit ning moodustada sõne
kujul: <i>tunnid:minutid:sekundid </i>(tunnid 24h skaalal).</li>
<li>&nbsp; Leida kraadides etteantud nurga koosinus.</li>
<li> &nbsp;Väljastada ruutjuurte tabel arvude 0 kuni 100 jaoks
sammuga 5.</li>
<li> &nbsp;Vahetada etteantud sõnes suurtähed väiketähtedega ja
vastupidi jättes muud sümbolid muutmata (<span
style="font-family: monospace;">"ABcd12"</span> -&gt; <span
style="font-family: monospace;">"abCD12"</span>). Kasutage
vahetulemuste salvestamiseks sõnepuhvrit (<tt>StringBuffer</tt>).</li>
<li> &nbsp;Muuta etteantud sõne sümbolite järjekord vastupidiseks
(<span style="font-family: monospace;">"1234ab"</span> -&gt; <span
style="font-family: monospace;">"ba4321"</span>).</li>
<li> &nbsp;Leida sõnade arv etteantud sõnes (sõnade eraldajaks
olgu vähemalt üks tühik, tabulatsioonimärk vms).</li>
<li>&nbsp; Võtta arvuti kellalt jooksev aeg, teha etteantud
pikkusega paus (näiteks 3 sek.), võtta uuesti jooksev aeg ning
arvutada nende kahe ajahetke tegelik vahe millisekundites.<br>
</li>
</ul>
<ul style="margin-left: 40px;">
<li> Genereerida juhuarvudest vahemikus 0 kuni 999 (<tt>Integer</tt>)
koosnev 100-elemendiline list (<tt>ArrayList</tt>) ning
väljastada see.</li>
<li>&nbsp;Leida selle listi vähim element. Proovige kirjutada
eraldi meetod, mis leiaks etteantud <tt>List</tt>-liidest
rahuldava objekti vähima elemendi eeldusel, et elemendid on
võrreldavad liidese <tt>Comparable</tt> mõttes (mida <tt>Integer</tt>
isendid ka on).</li>
<li> &nbsp;Moodustada paisktabel (<tt>HashMap</tt>) umbes 5
elemendiga, milles võtmeks on õppeaine kood (<tt>String</tt>) ja
elemendiks õppeaine nimetus (<tt>String</tt>). Andmed mõelge ise
välja.<br>
</li>
<li> Väljastada selle paisktabeli kõik võtmed.</li>
<li> Eemaldada üks ainetest sellest tabelist.</li>
<li> Väljastada kõik paarid "võti - väärtus" sellest tabelist.</li>
<li> Muuta esimeses ülesandes genereeritud listi (<span
style="font-family: monospace;">ArrayList</span>) elementide
järjekord vastupidiseks. Väljastada tulemus ja kontrollida selle
õigsust.</li>
<li> Koostada maksimumi leidmise meetod (eraldi meetodina), mis
kasutaks liideseid <tt>Collection</tt> ja <tt>Comparable</tt>
(s.t. meetodi parameetriks on <span style="font-family:
monospace;">Collection</span>-objekt, mis sisaldab <span
style="font-family: monospace;">Comparable</span>-liidest
rahuldavaid elemente, meetodi tagastusväärtuseks on maksimaalne
element <span style="font-family: monospace;">Comparable</span>-tüüpi
objektina). Selle meetodi poole pöördumisel võite kasutada
esimeses ülesandes loodud listi.<br>
</li>
</ul>
<ul style="margin-left: 40px;">
</ul>
<div style="margin-left: 40px;">
<div style="margin-left: 40px;"><span style="font-weight: bold;"></span>Programm testida ja
esitada Moodle kaudu.<br>
<br>
Git repositoorium: <a
href="https://jpoial@bitbucket.org/i231/lab1.git">https://jpoial@bitbucket.org/i231/lab1.git<br>
</a><br>
</div>
<br>
<hr style="width: 100%; height: 2px;">Jaanus Pöial<br>
<br>
<br>
<br>
<br>
</div>
</body>
</html>