Skip to content

Commit 99e8da5

Browse files
Update chapter-02-simple-calculations.md
Review "Exercise: Calculating the area of the square"
1 parent d5993d2 commit 99e8da5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

chapter-02-simple-calculations.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In the example above, in the variable **`num`** of integer type **`int`**, we wi
4848

4949
Java is **highly typed language** this means that the variables have type determine at compile-time and can not change at the execution time (as it is in dynamic languages such as JavaScript and Python). In the example above `scanner` is from type `java.util.Scanner` (scanning text reader) and the variable `num` is from type `int` (integer number).
5050

51-
### Example: Calculating a square area with side **а**
51+
### Example: Calculating the area of the square with side **а**
5252

5353
As an example, let us look at a program. The task is to calculate the area of a square by a given side's length read as input from the console. The sample source code of the program is below. The code **reads an integer** as input from the console, **multiply it** by itself (squares it), and as output **prints the result** from the multiplication. Save the code in a file with the name SquareArea.java, or else you will have a compile-time error:
5454

@@ -383,7 +383,7 @@ Scanner scanner = new Scanner(System.in);
383383
System.out.print("Enter circle radius. r = ");
384384
double r = Double.parseDouble(scanner.nextLine());
385385
System.out.println("Area = " + Math.PI * r * r);
386-
// Math.PI - вградена в Java константа за π
386+
// Math.PI - built-in function in Java
387387
System.out.println("Perimeter = " + 2 * Math.PI * r);
388388
```
389389
Let’s test the program with **radius `r = 10`**:
@@ -442,11 +442,11 @@ To summarize what have we learned in this chapter of the book:
442442

443443
## Exercises: Simple calculations
444444

445-
Let's solidify what we learned in this chapter with some exercises.
445+
To consolidate our knowledge of simple calculations, let's solve several exercises.
446446

447-
### Blank IntelliJ IDEA Solution (Project)
447+
### Blank IntelliJ IDEA solution (Project)
448448

449-
We start by creating an empty solution **(Project)** in IntelliJ IDEA. The solutions (project) in IntelliJ IDEA combine **a group of tasks**. This opportunity is **very convenient** when we want to **work on a few projects** and switch quickly between them or we want to **unite logically a few interconnected projects**.
449+
We start by creating an empty solution **(Project)** in IntelliJ IDEA. The solutions (project) in IntelliJ IDEA combine **a group of tasks**. This opportunity is **very convenient** when we want to **work on a few projects** and switch quickly between them or we want to **consolidate logically a few interconnected projects**.
450450

451451
In the current practical exercise we will use a **Project with a couple of tasks (Java classes)** to organize the solutions of the tasks from the exercises – every task in a separate Java class and all of them in a common project.
452452

@@ -461,7 +461,7 @@ Select from the dialog window [**Java**], in the field Project SDK we specify wh
461461

462462
![](assets/chapter-2-1-images/06.New-project-03.png)
463463

464-
Give an appropriate name for the project, for example "SimpleCalculations" and also where to be stored our project, after that we click [**Finish**]:
464+
Give an appropriate name for the project, for example "SimpleCalculations" and also where to be stored our project, and after that we click [**Finish**]:
465465

466466
![](assets/chapter-2-1-images/06.New-project-04.png)
467467

@@ -471,29 +471,29 @@ Now we have **empty IntelliJ IDEA Project** (without any Java classes in it whic
471471

472472
The purpose of this project is to add in it **`.java` class per problem** from the exercises.
473473

474-
### Problem: Calculating Square Area
474+
### Exercise: Calculating the area of the square
475475

476-
The first exercise from this topic is the following: write a console program that **inputs an integer `a` and calculates the area** of a square with side **`a`**. The task is trivial and easy: **input a number** from the console, **multiply it by itself** and **print the obtained result** on the console.
476+
The first task from this topic is the following: write a console program that read as **input data an integer `a` and calculates the area** of a square with side **`a`**. The task is trivial and easy: read as **input data a number** from the console, then **multiply it by itself** and **print the obtained result** as an output on the console.
477477

478-
#### Hints and Guidelines
478+
#### Hints and guidelines
479479

480-
We create **new Java class** in existing IntelliJ IDEA project. On the **src** folder right-click with the mouse. Choose [**New**][**Java Class**]:
480+
We create a **new Java class** in the existing IntelliJ IDEA project. On the **src** folder, right-click with the mouse. Choose [**New**][**Java Class**]:
481481

482482
![](assets/chapter-2-1-images/07.Square-area-01.png)
483483

484-
A **dialogue window** will open for choosing name to the Java class, for example “SquareArea”:
484+
A **dialogue window** will open for choosing а name to the Java class, for example, “SquareArea”:
485485

486486
![](assets/chapter-2-1-images/07.Square-area-02.png)
487487

488-
We already have a Project with Java class in it. What remains is to write the **code for solving this problem**. For this purpose, we write in our Java class `Main` method(as it is shown on the picture) and we go to the main method's body **`Main(string[] args)`**, and write the following code between the opening and closing curly brackets:
488+
We already have a Project with Java class in it. What remains is to write the **code for solving this problem**. For this purpose, we write in our Java class a `Main` method(as in the picture below). In the body of the `Main` method **`Main(string[] args)`** we write the following code between the opening and closing curly brackets:
489489

490490
![](assets/chapter-2-1-images/07.Square-area-03.png)
491491

492-
The code inputs an integer through **`a = Integer.parseInt(scanner.nextLine())`**, afterwards it calculates **`area = a * a`** and finally prints the value of the variable **`area`**. **We start** the program with [**Ctrl+Shft+F10**] and we **test** it with different input values:
492+
As we can see in the code above, we read as input data an integer and assign it to a variable **`a`** (line **`int a = Integer.parseInt(scanner.nextLine())`**), afterwards we calculate the area (line **`int area = a * a`**) and finally prints the value of the variable **`area`** on the console. **We start** the program with [**Ctrl+Shft+F10**] and we **test** it with different input values:
493493

494494
![](assets/chapter-2-1-images/07.Square-area-04.png)
495495

496-
#### Testing in the Judge System
496+
#### Testing in the Judge system
497497

498498
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#0](https://judge.softuni.bg/Contests/Practice/Index/649#0). You have to get 100 points (completely correct solution):
499499

@@ -502,7 +502,7 @@ Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#0
502502
![](assets/chapter-2-1-images/07.Square-area-06.png)
503503

504504

505-
### Problem: Inches to Centimeters
505+
### Exercise: Inches to centimeters
506506

507507
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).
508508

0 commit comments

Comments
 (0)