diff --git a/Calculator/pom.xml b/Calculator/pom.xml new file mode 100644 index 0000000..c4f8d9f --- /dev/null +++ b/Calculator/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + com.mycompany + Calculator + 1.0-SNAPSHOT + jar + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + UTF-8 + 1.8 + 1.8 + + \ No newline at end of file diff --git a/Calculator/src/main/java/com/mycompany/calculator/Calculator.java b/Calculator/src/main/java/com/mycompany/calculator/Calculator.java new file mode 100644 index 0000000..9e3c52e --- /dev/null +++ b/Calculator/src/main/java/com/mycompany/calculator/Calculator.java @@ -0,0 +1,40 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.mycompany.calculator; + +/** + * + * @author Наташа + */ +public class Calculator { +float c; + public Calculator() { + } + + public float add(float a, float b) { + c= a+b; + return c; + } + public float sub(float a, float b) { + c = a-b; + return c; + } + public float mul(float a, float b) { + c = a*b; + return c; + } + public long div(long a, long b) { + try { + return a/b; + }catch (java.lang.ArithmeticException e) { + throw new ArithmeticException(); + } + } + + public static void main(String[] args) { + + } +} diff --git a/Calculator/src/test/java/NewTest.java b/Calculator/src/test/java/NewTest.java new file mode 100644 index 0000000..4feff92 --- /dev/null +++ b/Calculator/src/test/java/NewTest.java @@ -0,0 +1,64 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +import com.mycompany.calculator.Calculator; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + + +/** + * + * @author Наташа + */ +public class NewTest { + private Calculator calc; + public NewTest() { + } + + @BeforeClass + public static void setUpClass() { + + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + calc = new Calculator(); + } + + @After + public void tearDown() { + } + @Test + public void divNZ(){ + assertTrue(calc.div(24, 12) == 2); + } + @Test + public void mulTest(){ + assertTrue(calc.mul(45, 15) == 675); + } + @Test(expected = ArithmeticException.class) + public void divZero(){ + calc.div(12,0); + } + + @Test + public void addT(){ + assertTrue(calc.add(56, 45) == 101); + } + @Test + public void subT(){ + assertTrue(calc.sub(56, 12) == 44); + } + +} diff --git a/Calculator/target/classes/com/mycompany/calculator/Calculator.class b/Calculator/target/classes/com/mycompany/calculator/Calculator.class new file mode 100644 index 0000000..18c6fb2 Binary files /dev/null and b/Calculator/target/classes/com/mycompany/calculator/Calculator.class differ diff --git a/Calculator/target/surefire-reports/NewTest.txt b/Calculator/target/surefire-reports/NewTest.txt new file mode 100644 index 0000000..6aea931 --- /dev/null +++ b/Calculator/target/surefire-reports/NewTest.txt @@ -0,0 +1,4 @@ +------------------------------------------------------------------------------- +Test set: NewTest +------------------------------------------------------------------------------- +Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.193 sec diff --git a/Calculator/target/surefire-reports/TEST-NewTest.xml b/Calculator/target/surefire-reports/TEST-NewTest.xml new file mode 100644 index 0000000..44c31de --- /dev/null +++ b/Calculator/target/surefire-reports/TEST-NewTest.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Calculator/target/test-classes/NewTest.class b/Calculator/target/test-classes/NewTest.class new file mode 100644 index 0000000..66b230a Binary files /dev/null and b/Calculator/target/test-classes/NewTest.class differ diff --git a/DataBase/build.xml b/DataBase/build.xml new file mode 100644 index 0000000..c138705 --- /dev/null +++ b/DataBase/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project DataBase. + + + diff --git a/DataBase/build/classes/database/DataBase.class b/DataBase/build/classes/database/DataBase.class new file mode 100644 index 0000000..7110fd5 Binary files /dev/null and b/DataBase/build/classes/database/DataBase.class differ diff --git a/DataBase/manifest.mf b/DataBase/manifest.mf new file mode 100644 index 0000000..1574df4 --- /dev/null +++ b/DataBase/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/DataBase/nbproject/build-impl.xml b/DataBase/nbproject/build-impl.xml new file mode 100644 index 0000000..3573697 --- /dev/null +++ b/DataBase/nbproject/build-impl.xml @@ -0,0 +1,1420 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DataBase/nbproject/genfiles.properties b/DataBase/nbproject/genfiles.properties new file mode 100644 index 0000000..af48843 --- /dev/null +++ b/DataBase/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=c402950b +build.xml.script.CRC32=33632e37 +build.xml.stylesheet.CRC32=8064a381@1.80.1.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=c402950b +nbproject/build-impl.xml.script.CRC32=90930164 +nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/DataBase/nbproject/private/private.properties b/DataBase/nbproject/private/private.properties new file mode 100644 index 0000000..3110b41 --- /dev/null +++ b/DataBase/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=C:\\Users\\\u041d\u0430\u0442\u0430\u0448\u0430\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/DataBase/nbproject/private/private.xml b/DataBase/nbproject/private/private.xml new file mode 100644 index 0000000..284eeec --- /dev/null +++ b/DataBase/nbproject/private/private.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/DataBase/nbproject/project.properties b/DataBase/nbproject/project.properties new file mode 100644 index 0000000..68632bb --- /dev/null +++ b/DataBase/nbproject/project.properties @@ -0,0 +1,76 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/DataBase.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +file.reference.com.mysql.jdbc_5.1.5.jar=C:\\Users\\\u041d\u0430\u0442\u0430\u0448\u0430\\Desktop\\com.mysql.jdbc_5.1.5.jar +includes=** +jar.compress=false +javac.classpath=\ + ${file.reference.com.mysql.jdbc_5.1.5.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=database.DataBase +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/DataBase/nbproject/project.xml b/DataBase/nbproject/project.xml new file mode 100644 index 0000000..ade5d29 --- /dev/null +++ b/DataBase/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + DataBase + + + + + + + + + diff --git a/DataBase/src/database/DataBase.java b/DataBase/src/database/DataBase.java new file mode 100644 index 0000000..ba9a693 --- /dev/null +++ b/DataBase/src/database/DataBase.java @@ -0,0 +1,176 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package database; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Наташа + */ +public class DataBase { + public static Connection conn; + public static Statement state; + // private static int id; + public static ResultSet rs; + + private static void connect() { + try { + Class.forName("com.mysql.jdbc.Driver"); + } catch (ClassNotFoundException ex) { + System.out.println("Can't find this class."); + } + try { + conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/banan", "root", "4444"); + state = conn.createStatement(); + conn.setAutoCommit(false); + + } catch (SQLException ex) { + System.out.println("Excepion connection"); + } + + } + + public static void createTable() { + connect(); + try { + state.execute("CREATE TABLE user(id int PRIMARY KEY NOT NULL, login varchar(15), age int NOT NULL);"); + state.execute("CREATE TABLE passward (idPas int PRIMARY KEY NOT NULL, pass varchar(8));"); + conn.commit(); + conn.close(); + } catch (SQLException ex) { + System.out.println("Exception creation"); + try { + conn.rollback(); + conn.close(); + } catch (SQLException ex1) { + System.out.println("Exeption rollback"); + } + } + } + + public static void addElement(String name, int age, String pas) { + connect(); + try { + state.executeUpdate("INSERT INTO user (login, age) VALUES ('"+name+"', '"+age+"')"); + state.executeUpdate("INSERT INTO passward (pass) values ( '"+pas+"')"); + conn.commit(); + conn.close(); + System.out.println("Success!!"); + } catch (SQLException ex) { + System.out.println("Element wasn't added"); + try { + conn.rollback(); + conn.close(); + } catch (SQLException ex1) { + } + } + + + } + + public static void delete (String name) { + connect(); + int idF = 0; + try { + rs = state.executeQuery("SELECT * FROM user WHERE login = '"+name+"'"); + if (rs != null) { + while (rs.next()) { + idF = rs.getInt("id"); + } + state.executeUpdate("DELETE FROM user WHERE login = '"+name+"'"); + state.execute("DELETE FROM passward WHERE idPas = "+idF+""); + } + else { + System.out.println("There is no user with this login"); + } + conn.commit(); + conn.close(); + System.out.println("User was deleted"); + } catch (SQLException ex) { + System.out.println("You can't delete it"); + try { + conn.rollback(); + conn.close(); + } catch (SQLException ex1) { + System.out.println("You didn't delete this element"); + } + } + } + + public static void checkUser(String log, String pass) { + int idPa=0; + String pass2 = null; + connect(); + try { + rs = state.executeQuery("SELECT * FROM user WHERE login = '"+log+"';"); + if (rs != null) { + while(rs.next()) { + System.out.println(rs.getInt("id")); + idPa = rs.getInt("id"); + } + rs = state.executeQuery("SELECT pass FROM passward WHERE idPas = '"+idPa+"';"); + while (rs.next()) + pass2 = rs.getString("pass"); + if (pass.equals(pass2)) { + System.out.println("There is this user. Passward is right"); + } + else { + System.out.println("Passward isn't right"); + } + } + else { + System.out.println("There is no user with this name"); + } + conn.commit(); + conn.close(); + } catch (SQLException ex) { + System.out.println("Exception one"); + try { + conn.rollback(); + conn.close(); + } catch (SQLException ex1) { + System.out.println("Cannot rollback"); + } + } + + } + + public static void result() { + connect(); + try { + rs = state.executeQuery("SELECT * FROM user"); + while (rs.next()) { + System.out.print(rs.getInt("id") + " "); + System.out.print(rs.getString("login") + " "); + System.out.println(rs.getInt("age") + " "); + } + conn.commit(); + conn.close(); + } catch (SQLException ex) { + try { + conn.rollback(); + conn.close(); + } catch (SQLException ex1) { + } + } + + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + } + +}