This commit is contained in:
VictoriaPresnyakova 2023-03-27 13:57:17 +04:00
parent 3efed43ce8
commit 4374567702
5 changed files with 120 additions and 126 deletions

View File

@ -1,12 +1,17 @@
<!DOCTYPE html>
<html>
<html xmlns:background="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<!-- Подключаем Bootstrap CSS -->
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
<style>
.btn{
background: aquamarine;
}
</style>
</head>
<body>
@ -22,54 +27,40 @@
<div class="form-row">
<div class="col">
<div class="form-group">
<label for="input1">String 1</label>
<input type="text" class="form-control" id="input1" placeholder="Enter String 1">
<label for="input1">Value 1</label>
<input type="text" class="form-control" id="input1" placeholder="Enter Value 1">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="getFirstChar()">First-char</button>
<div class="col">
<div class="form-group">
<label for="input2">Value 2</label>
<input type="text" class="form-control" id="input2" placeholder="Enter Value 2">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="operator">Method</label>
<select class="form-control" id="operator">
<option value="Sum">+</option>
<option value="Min">-</option>
<option value="Mul">*</option>
<option value="Del">/</option>
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="operator">Type</label>
<select class="form-control" id="Type">
<option value="int">Integer</option>
<option value="str">String</option>
<option value="arr">Array</option>
<div class="col">
<div class="form-group">
<label for="input2">Str</label>
<input type="text" class="form-control" id="input2" placeholder="Enter Str">
</select>
</div>
</div>
<div class="col">
<div class="form-group">
<label for="input3">Str</label>
<input type="text" class="form-control" id="input3" placeholder="Enter Str">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="doSum()">Sum</button>
<div class="col">
<div class="form-group">
<label for="input4">Year of birth</label>
<input type="number" class="form-control" id="input4" placeholder="Enter Year">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="getYears()">getYears</button>
<div class="col">
<div class="form-group">
<label for="input5">Str</label>
<input type="text" class="form-control" id="input5" placeholder="Enter Str">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="input6">Num</label>
<input type="number" class="form-control" id="input6" placeholder="Enter Num">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="getSubstring()">Substring</button>
<div class="col">
<div class="form-group">
<label for="input7">Array's size</label>
<input type="number" class="form-control" id="input7" placeholder="Enter Num">
</div>
</div>
<button type="button" class="btn btn-primary btn-block" onclick="getArray()">Get random Array</button>
<button type="button" class="btn" onclick="getResult()">Result</button>
</div>
<div class="form-group">

View File

@ -1,57 +1,17 @@
'use strict'
let num1 = document.getElementById("input1")
let num2 = document.getElementById("input2")
let num3 = document.getElementById("input3")
let num4 = document.getElementById("input4")
let num5 = document.getElementById("input5")
let num6 = document.getElementById("input6")
let num7 = document.getElementById("input7")
let operator = document.getElementById("operator")
let result = document.getElementById("result")
function getFirstChar(){
let s = num1.value
fetch(`http://localhost:8080/FirstCharacter/${s}`)
function getResult() {
let num1 = document.getElementById("input1").value
let num2 = document.getElementById("input2").value
let operator = document.getElementById("operator").value
let result = document.getElementById("result")
let type = document.getElementById("Type").value
fetch(`http://localhost:8080/${operator}?Type=${type}&value1=${num1}&value2=${num2}`)
.then(response => response.text())
.then(data => {result.value = data})
}
function doSum(){
let s1 = num2.value
let s2 = num3.value
fetch(`http://localhost:8080/Sum/${s1}/${s2}`)
.then(response => response.text())
.then(data => {result.value = data})
}
function getYears(){
let s4 = num4.value
fetch(`http://localhost:8080/SayYears/${s4}`)
.then(response => response.text())
.then(data => {result.value = data})
}
function getSubstring(){
let s5 = num5.value
let s6 = num6.value
fetch(`http://localhost:8080/DoSub/${s5}/${s6}`)
.then(response => response.text())
.then(data => {result.value = data})
}
function getArray(){
let s7 = num7.value
fetch(`http://localhost:8080/DoArray/${s7}`)
.then(response => response.text())
.then(data => {result.value = data})
.then(data => {
result.value = data
})
}

View File

@ -3,44 +3,14 @@ package ru.ulstu.is.sbapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.websocket.server.PathParam;
import java.util.Date;
@SpringBootApplication
@RestController
public class SbappApplication {
public static void main(String[] args) {
SpringApplication.run(SbappApplication.class, args);
}
@GetMapping("/FirstCharacter/{name}")
public Character FirstCharacter(@PathVariable String name) {
return name.charAt(0);
}
@GetMapping("/Sum/{val1}/{val2}")
public String Sum(@PathVariable String val1, @PathVariable String val2) {
return String.format(val1+val2);
}
@GetMapping("/SayYears/{birthday}")
public Integer SayYears(@PathVariable int birthday) {
return new Date().getYear() % 100 + 2000 - birthday;
}
@GetMapping("/DoSub/{val1}/{val2}")
public String DoSub(@PathVariable String val1, @PathVariable int val2) {
return val1.substring(val2);
}
@GetMapping("/DoArray/{val1}")
public double[] DoArray(@PathVariable int val1) {
double [] arr = new double[val1];
for(int i = 0; i < val1; i++){
arr[i] = Math.random();
}
return arr;
}
}

View File

@ -0,0 +1,26 @@
package ru.ulstu.is.sbapp.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.ulstu.is.sbapp.domain.TypeInt;
import ru.ulstu.is.sbapp.domain.TypeString;
import ru.ulstu.is.sbapp.domain.TypeArray;
@Configuration
public class TypeConfiguration {
@Bean(value = "int")
public TypeInt createIntType(){
return new TypeInt();
}
@Bean(value = "str")
public TypeString createStrType(){
return new TypeString();
}
@Bean(value = "arr")
public TypeArray createArrayType(){
return new TypeArray();
}
}

View File

@ -1,13 +1,60 @@
package ru.ulstu.is.sbapp;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import ru.ulstu.is.sbapp.Service.TypeService;
@SpringBootTest
class SbappApplicationTests {
@Autowired
TypeService Service;
@Test
void contextLoads() {
void testIntPlus() {
final String res = (String) Service.Sum( "100", "10", "int");
Assertions.assertEquals("110", res);
}
@Test
void testIntMinus() {
final String res = (String)Service.Min( "100", "10", "int");
Assertions.assertEquals("90", res);
}
@Test
void testIntMultiply() {
final String res = (String)Service.Mul( "100", "10", "int");
Assertions.assertEquals("1000", res);
}
@Test
void testIntDivision() {
final String res = (String)Service.Del( "100", "10", "int");
Assertions.assertEquals("10", res);
}
@Test
void testStringPlus() {
final String res = (String)Service.Sum( "abc", "dfe", "str");
Assertions.assertEquals("abcdfe", res);
}
@Test
void testStringMin() {
final String res = (String)Service.Min( "abcd", "ef", "str");
Assertions.assertEquals("cd", res);
}
@Test
void testStringMul() {
final String res = (String)Service.Mul( "adc", "de", "str");
Assertions.assertEquals("adcdeadcde", res);
}
@Test
void testStringDiv() {
final String res = (String)Service.Del( "adcdef", "de", "str");
Assertions.assertEquals("adcf", res);
}
}