You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter-02-simple-calculations.md
+48-48Lines changed: 48 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -504,63 +504,63 @@ Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#0
504
504
505
505
### Exercise: Inches to centimeters
506
506
507
-
Write a program that **reads a number from the console** (not necessarily an integer) and converts the number from **inches to centimeters.** For this purpose **it multiplies the inches by 2.54** (because one inch = 2.54 centimeters).
507
+
Write a program that **reads a number from the console** (not necessarily an integer) and converts the number from **inches to centimeters.** For this purpose **multiply the inches by 2.54** (because one inch = 2.54 centimeters).
508
508
509
-
#### Hints and Guidelines
509
+
#### Hints and guidelines
510
510
511
-
First, we create **new Java class** in the project “SimpleCalculations”. We click on the folder **src** and choose [**New**] → [**Java Class**]:
511
+
First, we create a **new Java class** in the project “SimpleCalculations”. We click on the folder **src** and choose [**New**] → [**Java Class**]:
**We start the program** with the right button of the mouse on the window of the current program. We choose [**Run InchesToCentim...main()**] or we press [**Ctrl+Shift+F10**]. This shortcut starts the program in the current Java class (the one in which we wrote last):
523
+
**We start the program** with the right click on the window of the current program. We choose [**Run InchesToCentim...main()**] or we press [**Ctrl+Shift+F10**]. This shortcut starts the program in the current Java class (the one in which we wrote last):
Now **let's switch to the previous program / task** ("Square Area"). This is done by double-clicking on the file **`SquareArea.java`** from the folder **src** in the project [**SimpleCalculations**]:
531
+
Now **let's switch to the previous program/task** ("Square Area"). This is done by double-clicking on the file **`SquareArea.java`** from the folder **src** in the project [**SimpleCalculations**]:
The last compiled program will be executed (**InchesToCentimeters**). We can see it as a name in the upper right corner of the window in front of one of the two green arrows:
539
+
the last compiled program will be executed (**InchesToCentimeters**). We can see it as a name in the upper right corner of the window in front of one of the two green arrows:
**Switching between projects** is very easy, isn't it? Just choose the file with the source code of the program, double click it and when it starts, the program from the current file is being executed.
543
+
**Switching between projects** is an easy task, isn't it? Choose the file with the source code of the program, double click on it and when it starts, the program from the current file runs.
544
544
545
-
Let's test with floating-point numbers, for example with **2.5**:
545
+
Let's test with floating-point numbers, for example, with **2.5**:
<td>В зависимост от регионалните настройки на операционната система, е възможно вместо <b>десетична точка</b> (US настройки) да се използва <b>десетична запетая</b> (BG настройки).</td>
550
+
<td>Depending on the regional settings of the operating system, it is possible to use <b> decimal point </b> (US settings) instead of <b> decimal comma </b> (BG settings).</td>
551
551
</tr></table>
552
552
553
553
If the program expects a decimal point and instead you enter a number with a decimal comma or the opposite (to enter a decimal point, when a decimal comma is expected), the following error will be produced:
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#2](hhttps://judge.softuni.bg/Contests/Practice/Index/649#2).
593
593
594
594
595
-
### Problem: Concatenating Text and Numbers
595
+
### Exercise: Concatenating Text and Numbers
596
596
597
597
Write a Java program, that reads from the console a first name, last name, age and city and prints a message of the following kind: **`You are <firstName> <lastName>, a <age>-years old person from <town>.`**.
598
598
599
-
#### Hints and Guidelines
599
+
#### Hints and guidelines
600
600
601
601
We add to the existing IntelliJ IDEA Project one more Java Class with name "`ConcatenateData`". **We write the code**, which reads the input from the console:
602
602
@@ -610,20 +610,20 @@ In the picture above the code is blurred on purpose, in order for you to think o
610
610
611
611
СNext, the solution should be tested locally using [**Ctrl+Shift+F10**] and by entering an exemplary input data.
612
612
613
-
#### Testing in the Judge System
613
+
#### Testing in the Judge system
614
614
615
615
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#3](https://judge.softuni.bg/Contests/Practice/Index/649#3).
616
616
617
617
618
-
### Problem: Trapezoid Area
618
+
### Exercise: Trapezoid Area
619
619
620
620
Write a program that reads three numbers from the console **b1**, **b2** and **h** and calculates **the area of a trapezoid** with bases **b1** and **b2** and height **h**. The formula for trapezoid area is **(b1 + b2) * h / 2**.
621
621
622
622
On the figure below shows a trapezoid with bases 8 and 13 and height 7. It has an area **(8 + 13) * 7 / 2 = 73.5**.
Again, we have to add to the existing IntelliJ IDEA Project another **Java class** with name "`TrapezoidArea`" and to write **the code that reads the input from the console, calculates the trapezoid area and prints it**:
629
629
@@ -633,57 +633,57 @@ The code on the picture is purposely blurred, in order for you to give it a thou
633
633
634
634
**Test** your solution locally using [**Ctrl+Shift+F10**] and enter an exemplary data.
635
635
636
-
#### Testing in the Judge System
636
+
#### Testing in the Judge system
637
637
638
638
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#4](https://judge.softuni.bg/Contests/Practice/Index/649#4).
639
639
640
640
641
-
### Problem: Circle Area and Perimeter
641
+
### Exercise: Circle Area and Perimeter
642
642
643
643
Write a program that reads from the console **a number r** r and calculates and prints **the area and perimeter of the circle**/**round** with **radius r**.
| 3 | Area = 28.2743338823081 <br> Perimeter = 18.8495559215388|
650
650
| 4.5 | Area = 63.6172512351933 <br> Perimeter = 28.2743338823081|
651
651
652
-
#### Hints and Guidelines
652
+
#### Hints and guidelines
653
653
654
654
For the calculations you may use the following formulas:
655
655
-**`Area = Math.PI * r * r`**.
656
656
-**`Perimeter = 2 * Math.PI * r`**.
657
657
658
-
#### Testing in the Judge System
658
+
#### Testing in the Judge system
659
659
660
660
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#5](https://judge.softuni.bg/Contests/Practice/Index/649#5).
661
661
662
662
663
-
### Problem: Rectangle Area
663
+
### Exercise: Rectangle Area
664
664
665
665
**A rectangle** is defined by the **coordinates** at two of its opposite angles (x1, y1) – (x2, y2). Calculate its **area and perimeter**. **The input** is read from the console. The numbers **x1, y1, x2 и y2** are given one per line. **The output** is printed on the console and it has to contain two lines, each with one number – the area and the perimeter.
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#6](https://judge.softuni.bg/Contests/Practice/Index/649#6).
680
680
681
681
682
-
### Problem: Triangle Area
682
+
### Exercise: Triangle Area
683
683
684
684
Write a program that reads from the console **a side and height of a triangle** and calculates its area. Use **the formula** for triangle area: **area = a * h / 2**. Round the result to **2 digits after the decimal point using `Math.round(area, 2)`**.
685
685
686
-
#### Sample Input and Output
686
+
#### Sample input and output
687
687
688
688
| Input | Output |
689
689
|--------------------|---------------------|
@@ -692,16 +692,16 @@ Write a program that reads from the console **a side and height of a triangle**
692
692
| 7.75 <br>8.45 | Triangle area = 32.74 |
693
693
| 1.23456 <br>4.56789 | Triangle area = 2.82 |
694
694
695
-
#### Testing in the Judge System
695
+
#### Testing in the Judge system
696
696
697
697
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#7](https://judge.softuni.bg/Contests/Practice/Index/649#7).
698
698
699
699
700
-
### Problem: Converter – from °C Degrees to °F Degrees
700
+
### Exercise: Converter – from °C Degrees to °F Degrees
701
701
702
702
Write a program that reads **degrees on Celsius scale** (°C) and converts them to **degrees on Fahrenheit scale** (°F). Look on the Internet for a proper [formula](http://bfy.tw/3rGh"Търсене в Google"), to do the calculations. Round the result to **2 digits after the decimal point**. Here are a few examples:
703
703
704
-
#### Sample Input and Output
704
+
#### Sample input and output
705
705
706
706
| Input | Output |
707
707
|----|-----|
@@ -710,16 +710,16 @@ Write a program that reads **degrees on Celsius scale** (°C) and converts them
710
710
| -5.5 | 22.1 |
711
711
| 32.3 | 90.14 |
712
712
713
-
#### Testing in the Judge System
713
+
#### Testing in the Judge system
714
714
715
715
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#8](https://judge.softuni.bg/Contests/Practice/Index/649#8).
716
716
717
717
718
-
### Problem: Converter – from Radians to Degrees
718
+
### Exercise: Converter – from Radians to Degrees
719
719
720
720
Write a program, that reads **ъan angle in [radians](https://bg.wikipedia.org/wiki/Радиан)** (**`rad`**) and converts it to **[degrees](https://bg.wikipedia.org/wiki/Градус_(ъгъл))** (`deg`). Look for a proper formula on the Internet. The number **π** in Java programs is available through **``Math.PI``**. Round the result to the nearest integer using the method **``Math.round(…)``**.
721
721
722
-
#### Sample Input and Output
722
+
#### Sample input and output
723
723
724
724
| Input | Output |
725
725
|------|-----|
@@ -728,29 +728,29 @@ Write a program, that reads **ъan angle in [radians](https://bg.wikipedia.org/w
728
728
| 0.7854 | 45 |
729
729
| 0.5236 | 30 |
730
730
731
-
#### Testing in the Judge System
731
+
#### Testing in the Judge system
732
732
733
733
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#9](https://judge.softuni.bg/Contests/Practice/Index/649#9).
734
734
735
735
736
-
### Problem: Converter – USD to BGN
736
+
### Exercise: Converter – USD to BGN
737
737
738
738
Write a program for **conversion of US dollars** (USD) **into Bulgarian levs** (BGN). **Round** the result **2 digits** след десетичния знак. after the decimal point. Use a fixed rate between a dollar and levs: **1 USD = 1.79549 BGN**.
739
739
740
-
#### Sample Input and Output
740
+
#### Sample input and output
741
741
742
742
| Input | Output |
743
743
|------|---------|
744
744
| 20 | 35.91 BGN |
745
745
| 100 | 179.55 BGN|
746
746
| 12.5 | 22.44 BGN |
747
747
748
-
#### Testing in the Judge System
748
+
#### Testing in the Judge system
749
749
750
750
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#10](https://judge.softuni.bg/Contests/Practice/Index/649#10).
751
751
752
752
753
-
### Problem: \* Currency Converter
753
+
### Exercise: \* Currency Converter
754
754
755
755
Write a program for **conversion of money from one currency into another**. It has to support the following currencies: **BGN, USD, EUR, GBP**. Use the following fixed currency rates:
756
756
@@ -760,7 +760,7 @@ Write a program for **conversion of money from one currency into another**. It h
760
760
761
761
**The input** is **sum for conversion**, **input currency** and **output currency**. **The output** is one number – the converted value of the above currency rates, rounded **2 digits** after the decimal point.
762
762
763
-
#### Sample Input and Output
763
+
#### Sample input and output
764
764
765
765
| Input | Input |
766
766
|------------------|--------|
@@ -769,16 +769,16 @@ Write a program for **conversion of money from one currency into another**. It h
769
769
| 12.35<br>EUR<br>GBP| 9.53 GBP |
770
770
|150.35<br>USD<br>EUR|138.02 EUR|
771
771
772
-
#### Testing in the Judge System
772
+
#### Testing in the Judge system
773
773
774
774
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#11](https://judge.softuni.bg/Contests/Practice/Index/649#11).
775
775
776
776
777
-
### Problem: ** Date Calculations – 1000 Days on the Earth
777
+
### Exercise: ** Date Calculations – 1000 Days on the Earth
778
778
779
779
Write a program that enters a **birth date** in format **`dd-MM-yyyy`** and calculates the date on which **1000 days** are turned since this birth date and prints it in the same format.
780
780
781
-
#### Sample Input and Output
781
+
#### Sample input and output
782
782
783
783
| Input | Output |
784
784
|--------|--------|
@@ -788,10 +788,10 @@ Write a program that enters a **birth date** in format **`dd-MM-yyyy`** and calc
788
788
|01-01-2012|27-09-2014|
789
789
|14-06-1980|11-03-1983|
790
790
791
-
#### Hints and Guidelines
791
+
#### Hints and guidelines
792
792
* Look for information about the data type **`Date`**, **`Calendar`** and **`SimpleDateFormat`** in Java and in particular look at the methods **`Calendar.setTime(date)`**, **`Calendar.add(countDays)`** and **`SimpleDateFormat.format(date)`**. With their help you can solve the problem without the need to calculate days, months and leap years.
793
793
***Don't print** anything additional on the console except for the wanted date!
794
794
795
-
#### Testing in the Judge System
795
+
#### Testing in the Judge system
796
796
797
797
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#12](https://judge.softuni.bg/Contests/Practice/Index/649#12).
0 commit comments