Лаб1. Доп задание

This commit is contained in:
Катя Ихонкина 2023-02-21 14:01:58 +04:00
parent fff4caf5d7
commit af1bc9135e
3 changed files with 49 additions and 10 deletions

View File

@ -61,6 +61,21 @@
<button type="button" class="btn btn-success" id="calculate-button">Посчитать</button>
</div>
</div>
<div class="row" style="margin-top: 3%">
<div class="input-group">
<span class="input-group-text">Твой массив:</span>
<input class="form-control" id="array"></input>
</div>
</div>
<div class="row" style="margin-top: 3%">
<div class="col-md-4">
<label for="arrayin" class="form-label">Число для умножения</label>
<input type="number" class="form-control" value="0" id="arrayin" />
</div>
<div class="col-md-3">
<button type="button" class="btn btn-success" id="do-button">Умножить массив</button>
</div>
</div>
</div>

View File

@ -1,15 +1,15 @@
let calculateButton = document.getElementById("calculate-button");
let helloButton = document.getElementById("hello-button");
let doButton = document.getElementById("do-button");
let yournamee = document.getElementById("yourname");
let numberOneInput = document.getElementById("number-1");
let numberTwoInput = document.getElementById("number-2");
let select = document.getElementById("operation");
let result = document.getElementById("my-card-text");
let inputElement = document.getElementById("array");
let arrayinn = document.getElementById("arrayin");
fetch(`http://localhost:8080/`)
.then(response => response.text())
.then(res => result.textContent = res);
hello();
helloButton.onclick = function() {
@ -20,6 +20,21 @@ calculateButton.onclick = function() {
calculate();
};
doButton.onclick = function() {
doing();
};
function doing() {
var arr = Array.from((inputElement.value).split(' '));
for (let i = 0; i < arr.length ; i++) {
arr[i]=parseInt(arr[i]);
}
let num =arrayinn.value;
fetch(`http://localhost:8080/array?array=${arr}&num=${num}`)
.then(response => response.text())
.then(res => result.textContent ="Умноженный массив: " + res);
}
function hello() {
let name = yournamee.value;
fetch(`http://localhost:8080/?name=${name}`)

View File

@ -20,20 +20,20 @@ public class SpringAppApplication {
}
@GetMapping("/sum")
public double sum(@RequestParam(value = "num1") double num1,
@RequestParam(value = "num2") double num2) {
public int sum(@RequestParam(value = "num1") int num1,
@RequestParam(value = "num2") int num2) {
return num1 + num2;
}
@GetMapping("/dif")
public double dif(@RequestParam(value = "num1") double num1,
@RequestParam(value = "num2") double num2) {
public int dif(@RequestParam(value = "num1") int num1,
@RequestParam(value = "num2") int num2) {
return num1 - num2;
}
@GetMapping("/mul")
public double mul(@RequestParam(value = "num1") double num1,
@RequestParam(value = "num2") double num2) {
public int mul(@RequestParam(value = "num1") int num1,
@RequestParam(value = "num2") int num2) {
return num1 * num2;
}
@ -45,4 +45,13 @@ public class SpringAppApplication {
}
return num1 / num2;
}
@GetMapping("/array")
public int[] array(@RequestParam(value = "array") int[] array,
@RequestParam(value = "num") int num) {
for(int i=0;i<array.length;i++) {
array[i] = array[i] * num;
}
return array;
}
}