Compare commits
No commits in common. "499575123dcb9181a77fd56e36864ac5d3cff4a4" and "e8358ded65cec69498aa9a75d68edef19b132ff0" have entirely different histories.
499575123d
...
e8358ded65
132
front/index.html
132
front/index.html
@ -2,109 +2,71 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>LabWork02</title>
|
||||
<title>LabWork01</title>
|
||||
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div class="container">
|
||||
<div class="py-5 text-center"><h2>Лабораторная работа 2</h2></div>
|
||||
<div class="row">
|
||||
<div>
|
||||
<body>
|
||||
|
||||
<div class="container mt-4">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<h3 class="text-center font-weight-light my-2">Лабораторная работа 1</h3>
|
||||
<form>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="input1">Значение 1 (string или double)</label>
|
||||
<input class="form-control" id="input1" placeholder="Введите значение 1">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="input1">Значение 2 (string или double)</label>
|
||||
<input class="form-control" id="input2" placeholder="Введите значение 2">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-row">
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="operator">Выберите функцию</label>
|
||||
<select class="form-control" id="operator">
|
||||
<option value>Выбрать...</option>
|
||||
<option value="Func1">(string, double)Сумма</option>
|
||||
<option value="Func2">(double)Минимум, (string)Сумма в верхний регистр</option>
|
||||
<option value="Func3">(double)Mаксимум, (string)Разделить</option>
|
||||
<option value="Func4">(double)Число 1 в степени числа 2, (string)Сумма в нижний регистр</option>
|
||||
</select>
|
||||
<label for="input1">Первая строка</label>
|
||||
<input type="text" class="form-control" id="input1" placeholder="Введите перую строку">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="operator">Выберите тип данных</label>
|
||||
<select class="form-control" id="Type">
|
||||
<option value>Выбрать...</option>
|
||||
<option value="str">String</option>
|
||||
<option value="double">Double</option>
|
||||
</select>
|
||||
<label for="input2">Вторая строка</label>
|
||||
<input type="text" class="form-control" id="input2" placeholder="Введите вторую строку">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="Sum()">Сумма</button>
|
||||
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="input3">Строка</label>
|
||||
<input type="text" class="form-control" id="input3" placeholder="Введите строку">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="ToUpper()">В верхний регистр</button>
|
||||
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="input4">Строка</label>
|
||||
<input type="text" class="form-control" id="input4" placeholder="Введите строку">
|
||||
<label for="input5">Разделитель</label>
|
||||
<input type="text" class="form-control" id="input5" placeholder="Введите разделитель">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="Split()">Разделить</button>
|
||||
|
||||
<div class="col">
|
||||
<div class="form-group">
|
||||
<label for="input6">Строка</label>
|
||||
<input type="text" class="form-control" id="input6" placeholder="Введите строку">
|
||||
<label for="input7">Новый символ</label>
|
||||
<input type="text" class="form-control" id="input7" placeholder="Введите старый символ">
|
||||
<label for="input8">Старый символ</label>
|
||||
<input type="text" class="form-control" id="input8" placeholder="Введите новый символ">
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="Replace()">Заменить</button>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="result">Результат</label>
|
||||
<input type="text" class="form-control result" id="result" readonly>
|
||||
<hr class="mb-4">
|
||||
<button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--<div class="container mt-4">-->
|
||||
<!-- <div class="row justify-content-center">-->
|
||||
<!-- <div class="col-lg-6">-->
|
||||
<!-- <h3 class="text-center font-weight-light my-2">Лабораторная работа 2</h3>-->
|
||||
<!-- <form>-->
|
||||
<!-- <div class="form-row">-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="input1">Значение 1 (string или double)</label>-->
|
||||
<!-- <input class="form-control" id="input1" placeholder="Введите значение 1">-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="input2">Значение 2 (string или double)</label>-->
|
||||
<!-- <input class="form-control" id="input2" placeholder="Введите значение 2">-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="operator">Выбрать функцию...</label>-->
|
||||
<!-- <select class="form-control" id="operator">-->
|
||||
<!-- <option value="Func1">Сумма</option>-->
|
||||
<!-- <option value="Func2">Минимум, Сумма в верхний регистр</option>-->
|
||||
<!-- <option value="Func3">Mаксимум, Разделить</option>-->
|
||||
<!-- <option value="Func4">Число 1 в степени числа 2, Сумма в нижний регистр</option>-->
|
||||
<!-- </select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col">-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="operator">Выбрать тип данных...</label>-->
|
||||
<!-- <select class="form-control" id="Type">-->
|
||||
<!-- <option value="str">String</option>-->
|
||||
<!-- <option value="double">Double</option>-->
|
||||
<!-- </select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="form-group">-->
|
||||
<!-- <label for="result">Результат</label>-->
|
||||
<!-- <input type="text" class="form-control result" id="result" readonly>-->
|
||||
<!-- </div>-->
|
||||
<!-- <button type="button" class="btn btn-primary btn-block" onclick="calculate()">Посчитать</button>-->
|
||||
<!-- </form>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!--</div>-->
|
||||
<script src = "script.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,13 +1,44 @@
|
||||
'use strict'
|
||||
async function calculate(){
|
||||
let num1 = document.getElementById("input1").value
|
||||
let num2 = document.getElementById("input2").value
|
||||
let operator = document.getElementById("operator").value
|
||||
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 num8 = document.getElementById("input8")
|
||||
|
||||
let operator = document.getElementById("operator")
|
||||
let result = document.getElementById("result")
|
||||
let type = document.getElementById("Type").value
|
||||
|
||||
|
||||
let response = await fetch(`http://localhost:8080/${operator}?Type=${type}&value1=${num1}&value2=${num2}`)
|
||||
async function Sum(){
|
||||
let str1 = num1.value
|
||||
let str2 = num2.value
|
||||
let response = await fetch(`http://localhost:8080/Sum/${str1}/${str2}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
||||
|
||||
async function ToUpper(){
|
||||
let str3 = num3.value
|
||||
let response = await fetch(`http://localhost:8080/ToUpper/${str3}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
||||
|
||||
async function Split(){
|
||||
let str4 = num4.value
|
||||
let str5 = num5.value
|
||||
let response = await fetch(`http://localhost:8080/Split/${str4}/${str5}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
||||
|
||||
async function Replace(){
|
||||
let str6 = num6.value
|
||||
let str7 = num7.value
|
||||
let str8 = num8.value
|
||||
let response = await fetch(`http://localhost:8080/Replace/${str6}/${str7}/${str8}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
@ -2,12 +2,33 @@ 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.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
|
||||
public class SbappApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SbappApplication.class, args);
|
||||
}
|
||||
@GetMapping("/Sum/{val1}/{val2}")
|
||||
public String Sum(@PathVariable String val1, @PathVariable String val2) {
|
||||
return val1 + val2;
|
||||
}
|
||||
@GetMapping("/ToUpper/{str3}")
|
||||
public String ToUpper(@PathVariable String str3) {
|
||||
return str3.toUpperCase();
|
||||
}
|
||||
@GetMapping("/Split/{str1}/{str2}")
|
||||
public String Split(@PathVariable String str1, @PathVariable String str2) {
|
||||
String[] array = str1.split(str2);
|
||||
return String.join(" ", array);
|
||||
}
|
||||
@GetMapping("/Replace/{str}/{oldChar}/{newChar}")
|
||||
public String Replace(@PathVariable String str, @PathVariable char oldChar, @PathVariable char newChar) {
|
||||
return str.replace(oldChar, newChar);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.configuration;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.ulstu.is.sbapp.interfaces.DoubleType;
|
||||
import ru.ulstu.is.sbapp.interfaces.StringType;
|
||||
|
||||
@Configuration
|
||||
public class TypeConfiguration {
|
||||
|
||||
@Bean(value = "str")
|
||||
public StringType createStrType(){
|
||||
return new StringType();
|
||||
}
|
||||
|
||||
@Bean(value = "double")
|
||||
public DoubleType createDoubleType(){
|
||||
return new DoubleType();
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.service.ServiceType;
|
||||
|
||||
@RestController
|
||||
public class MainController {
|
||||
private final ServiceType Service;
|
||||
|
||||
public MainController(ServiceType service) {
|
||||
Service = service;
|
||||
}
|
||||
|
||||
@GetMapping("/Func1")
|
||||
public Object Func1(@RequestParam(value = "Type") String Type,
|
||||
@RequestParam(value = "value1") Object value1,
|
||||
@RequestParam(value = "value2") Object value2){
|
||||
return Service.Func1(value1,value2,Type);
|
||||
}
|
||||
|
||||
@GetMapping("/Func2")
|
||||
public Object Func2(@RequestParam(value = "Type") String Type,
|
||||
@RequestParam(value = "value1") Object value1,
|
||||
@RequestParam(value = "value2") Object value2){
|
||||
return Service.Func2(value1, value2, Type);
|
||||
}
|
||||
|
||||
@GetMapping("/Func3")
|
||||
public Object Func3(@RequestParam(value = "Type") String Type,
|
||||
@RequestParam(value = "value1") Object value1,
|
||||
@RequestParam(value = "value2") Object value2){
|
||||
return Service.Func3(value1,value2,Type);
|
||||
}
|
||||
|
||||
@GetMapping("/Func4")
|
||||
public Object Func4(@RequestParam(value = "Type") String Type,
|
||||
@RequestParam(value = "value1") Object value1,
|
||||
@RequestParam(value = "value2") Object value2){
|
||||
return Service.Func4(value1,value2,Type);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.interfaces;
|
||||
|
||||
public class DoubleType implements ITypeOfData<Double> {
|
||||
@Override
|
||||
public Double Func1(Double value1, Double value2) {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double Func2(Double value1, Double value2) {
|
||||
return Math.min(value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double Func3(Double value1, Double value2) {
|
||||
return Math.max(value1, value2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double Func4(Double value1, Double value2) {
|
||||
return Math.pow(value1,value2);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.interfaces;
|
||||
|
||||
public interface ITypeOfData <T>{
|
||||
T Func1(T value1, T value2);
|
||||
T Func2(T value1, T value2);
|
||||
T Func3(T value1, T value2);
|
||||
T Func4(T value1, T value2);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.interfaces;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class StringType implements ITypeOfData<String> {
|
||||
@Override
|
||||
public String Func1(String value1, String value2) {
|
||||
return value1 + value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Func2(String value1, String value2) {
|
||||
return value1.toUpperCase() + value2.toUpperCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Func3(String value1, String value2) {
|
||||
String[] array = value1.split(value2);
|
||||
return String.join(" ", array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String Func4(String value1, String value2) {
|
||||
return value1.toLowerCase() + value2.toLowerCase();
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package ru.ulstu.is.sbapp.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import ru.ulstu.is.sbapp.interfaces.ITypeOfData;
|
||||
|
||||
@Service
|
||||
public class ServiceType {
|
||||
private final ApplicationContext applicationContext;
|
||||
private ITypeOfData _type;
|
||||
private Object _value1;
|
||||
private Object _value2;
|
||||
|
||||
public ServiceType(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
private void ValidateParams(Object value1, Object value2, String type){
|
||||
_type = (ITypeOfData)applicationContext.getBean(type);
|
||||
|
||||
switch (type) {
|
||||
case "double" -> {
|
||||
try {
|
||||
_value1 = Double.valueOf(value1.toString());
|
||||
_value2 = Double.valueOf(value2.toString());
|
||||
}catch (Exception ex){
|
||||
_value1 = 0.0;
|
||||
_value2 = 0.0;
|
||||
}
|
||||
}
|
||||
case "str" -> {
|
||||
_value1 = value1;
|
||||
_value2 = value2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Object Func1(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _type.Func1(_value1,_value2));
|
||||
}
|
||||
|
||||
public Object Func2(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _type.Func2(_value1, _value2));
|
||||
}
|
||||
|
||||
public Object Func3(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _type.Func3(_value1,_value2));
|
||||
}
|
||||
|
||||
public Object Func4(Object value1, Object value2, String type){
|
||||
ValidateParams(value1,value2,type);
|
||||
return String.format("%s", _type.Func4(_value1,_value2));
|
||||
}
|
||||
}
|
@ -1,88 +1,13 @@
|
||||
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.ServiceType;
|
||||
|
||||
@SpringBootTest
|
||||
class SbappApplicationTests {
|
||||
|
||||
@Autowired
|
||||
ServiceType Service;
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
@Test
|
||||
void testIntPlus() {
|
||||
final String res = (String) Service.Func1( "100", "10", "int");
|
||||
Assertions.assertEquals("110", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIntMinus() {
|
||||
final String res = (String)Service.Func2( "100", "10", "int");
|
||||
Assertions.assertEquals("90", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIntMultiply() {
|
||||
final String res = (String)Service.Func3( "100", "10", "int");
|
||||
Assertions.assertEquals("1000", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIntDivision() {
|
||||
final String res = (String)Service.Func4( "100", "10", "int");
|
||||
Assertions.assertEquals("10", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringPlus() {
|
||||
final String res = (String)Service.Func1( "abc", "dfe", "str");
|
||||
Assertions.assertEquals("abcdfe", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringtoUpper() {
|
||||
final String res = (String)Service.Func2( "abc", "dfe", "str");
|
||||
Assertions.assertEquals("ABCDFE", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringtoLower() {
|
||||
final String res = (String)Service.Func3( "abc", "dfe", "str");
|
||||
Assertions.assertEquals("abcdfe", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringStrange() {
|
||||
final String res = (String)Service.Func4( "abc", "dfe", "str");
|
||||
Assertions.assertEquals("abcDFE", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoublePlus() {
|
||||
final String res = (String)Service.Func1( "1.01", "2.76", "double");
|
||||
Assertions.assertEquals("3.7699999999999996", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoubleMinus() {
|
||||
final String res = (String)Service.Func2( "1.01", "2.76", "double");
|
||||
Assertions.assertEquals("-1.7499999999999998", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoubleMyltiply() {
|
||||
final String res = (String)Service.Func3( "1.01", "2.76", "double");
|
||||
Assertions.assertEquals("2.7876", res);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDoubleDivision() {
|
||||
final String res = (String)Service.Func4( "1.01", "2.76", "double");
|
||||
Assertions.assertEquals("0.36594202898550726", res);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user