Arvutiteaduse instituut
  1. Kursused
  2. 2018/19 kevad
  3. Objektorienteeritud programmeerimine (Narva Kolledž) (LTAT.NR.003)
EN
Logi sisse

Objektorienteeritud programmeerimine (Narva Kolledž) 2018/19 kevad

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links

During session 1

slides_s2.pdf

Tasks for 1 point

session_s2.pdf

Once you have submitted the assignment, please proceed with the following tasks.

These tasks help you practise and master your Java skills. If you want your solutions to be checked, please show them to the instructor during the session or send to the instructor by email.

1. Loops

Write a program which calculates and outputs the sum of all the integers between 1 and 5 (inclusive). Solve the task using:

  • while loop
  • do ... while loop
  • for loop

If the task is solved correctly, you will have three separate files.

2. Input

Write a program that gets three numbers as main method arguments.The program has to check if these numbers can be the edges of a triangle. (Hint: check the sum of the edges).

Example of the program output:

 Numbers 10, 15 and 30 cannot be edges of a triangle.

Example of the program output:

 Numbers 10, 15 and 10 can be edges of a triangle.

3. Input with a loop

Write a program that constantly asks the user for an integer (use Scanner) and checks whether it is even. The program has to terminate if the user enters 0.

 Example of the program output:
 Enter a number: 25
 Odd
 Enter a number: 100
 Even
 Enter a number: 0
 I am done.

4. Kilos and Pounds

Write a program that displays the following table (note: 1 kg = 2.2 pounds; if you want to be more precise 1 kg = 2.20462262185 pounds). The output of the program should look like this:

 Kg        Pounds
 1         2.2 
 3         6.6
 ...
 197       433.4
 199       437.8

To output the result as a table, format the output. To create columns for the table, use tab symbol \t. For example, System.out.println("abc"+"\t"+"def"); in such case string def will be allocated into a new column. To format floating point numbers, use System.out.printf. For example, System.out.printf("%.1f",1234.45) will display double numbers with one digit after the comma.

Modify the program so that the user is prompted for the range of the kilos (a starting value of the calculations, a step, a stopping value of the calculations).

5. Sum of a series

Write a program that calculates and prints out the sum of the following series:

Modify the program so that the user is prompted for the number of the first terms to be summed.

  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused