From 244099760edba4c238c70cf679af1c45dfd776b3 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sat, 21 Sep 2019 17:07:09 +0400 Subject: [PATCH] Init commit --- FractionCalc/.idea/description.html | 1 + FractionCalc/.idea/misc.xml | 12 + FractionCalc/.idea/modules.xml | 8 + FractionCalc/.idea/project-template.xml | 3 + FractionCalc/.idea/workspace.xml | 219 ++++++++++ FractionCalc/Fraction.iml | 12 + .../production/Fraction/main/Fraction.class | Bin 0 -> 1834 bytes .../out/production/Fraction/main/Main.class | Bin 0 -> 842 bytes FractionCalc/src/main/Fraction.java | 61 +++ FractionCalc/src/main/Main.java | 19 + OneFourThree/.idea/description.html | 1 + OneFourThree/.idea/misc.xml | 12 + OneFourThree/.idea/modules.xml | 8 + OneFourThree/.idea/project-template.xml | 3 + OneFourThree/.idea/workspace.xml | 222 ++++++++++ OneFourThree/OneFourThree.iml | 12 + OneFourThree/src/main/Main.java | 54 +++ StringCalc/.idea/compiler.xml | 22 + .../.idea/copyright/profiles_settings.xml | 3 + StringCalc/.idea/description.html | 1 + StringCalc/.idea/misc.xml | 12 + StringCalc/.idea/modules.xml | 8 + StringCalc/.idea/project-template.xml | 3 + StringCalc/.idea/workspace.xml | 408 ++++++++++++++++++ StringCalc/UnnamedCalc.iml | 12 + .../production/UnnamedCalc/main/Main.class | Bin 0 -> 2539 bytes StringCalc/src/main/Main.java | 88 ++++ 27 files changed, 1204 insertions(+) create mode 100644 FractionCalc/.idea/description.html create mode 100644 FractionCalc/.idea/misc.xml create mode 100644 FractionCalc/.idea/modules.xml create mode 100644 FractionCalc/.idea/project-template.xml create mode 100644 FractionCalc/.idea/workspace.xml create mode 100644 FractionCalc/Fraction.iml create mode 100644 FractionCalc/out/production/Fraction/main/Fraction.class create mode 100644 FractionCalc/out/production/Fraction/main/Main.class create mode 100644 FractionCalc/src/main/Fraction.java create mode 100644 FractionCalc/src/main/Main.java create mode 100644 OneFourThree/.idea/description.html create mode 100644 OneFourThree/.idea/misc.xml create mode 100644 OneFourThree/.idea/modules.xml create mode 100644 OneFourThree/.idea/project-template.xml create mode 100644 OneFourThree/.idea/workspace.xml create mode 100644 OneFourThree/OneFourThree.iml create mode 100644 OneFourThree/src/main/Main.java create mode 100644 StringCalc/.idea/compiler.xml create mode 100644 StringCalc/.idea/copyright/profiles_settings.xml create mode 100644 StringCalc/.idea/description.html create mode 100644 StringCalc/.idea/misc.xml create mode 100644 StringCalc/.idea/modules.xml create mode 100644 StringCalc/.idea/project-template.xml create mode 100644 StringCalc/.idea/workspace.xml create mode 100644 StringCalc/UnnamedCalc.iml create mode 100644 StringCalc/out/production/UnnamedCalc/main/Main.class create mode 100644 StringCalc/src/main/Main.java diff --git a/FractionCalc/.idea/description.html b/FractionCalc/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/FractionCalc/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/FractionCalc/.idea/misc.xml b/FractionCalc/.idea/misc.xml new file mode 100644 index 0000000..5d75313 --- /dev/null +++ b/FractionCalc/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/FractionCalc/.idea/modules.xml b/FractionCalc/.idea/modules.xml new file mode 100644 index 0000000..77433cf --- /dev/null +++ b/FractionCalc/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/FractionCalc/.idea/project-template.xml b/FractionCalc/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/FractionCalc/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/FractionCalc/.idea/workspace.xml b/FractionCalc/.idea/workspace.xml new file mode 100644 index 0000000..23dddf1 --- /dev/null +++ b/FractionCalc/.idea/workspace.xml @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1536858948207 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OneFourThree/OneFourThree.iml b/OneFourThree/OneFourThree.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/OneFourThree/OneFourThree.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/OneFourThree/src/main/Main.java b/OneFourThree/src/main/Main.java new file mode 100644 index 0000000..3368f65 --- /dev/null +++ b/OneFourThree/src/main/Main.java @@ -0,0 +1,54 @@ +package main; + +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + int rangeBegin = 0; + int rangeEnd = 100; + + int tempRand = 0; + //int lastRand = 0; + int countOfAttempt = 1; + String userAnswer; + + + System.out.println("OneFourThree program guesses the number that the user made."); + System.out.println("Make a number from 0 to " + rangeEnd + "."); + System.out.println("Enter +/-/= if the number that the computer displays is more/less than your number, or it is correct."); + System.out.println("For exit, write \"quit\"."); + System.out.printf("\n\n"); + System.out.print("Make a number, then press Enter..."); + scanner.nextLine(); + + System.out.printf("\n\n"); + + + while (true) { + tempRand = (int) (int)Math.round((rangeBegin + rangeEnd) / 2); + + System.out.println(tempRand); + System.out.print("Правильно? +/-/=: "); + userAnswer = scanner.next(); + if( userAnswer.equals("+") ) { + rangeBegin = tempRand; + countOfAttempt++; + } else if( userAnswer.equals("-") ) { + rangeEnd = tempRand; + countOfAttempt++; + } else if( userAnswer.equals("=") ) { + System.out.println("Вы выиграли!"); + System.out.println("Компьютер угадал ваше число за " + countOfAttempt + " попыток (-ки)."); + break; + } else if( userAnswer.equals("quit") ) { + System.out.println("Выходим..."); + break; + } + } + + } + + +} diff --git a/StringCalc/.idea/compiler.xml b/StringCalc/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/StringCalc/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StringCalc/.idea/copyright/profiles_settings.xml b/StringCalc/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/StringCalc/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/StringCalc/.idea/description.html b/StringCalc/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/StringCalc/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/StringCalc/.idea/misc.xml b/StringCalc/.idea/misc.xml new file mode 100644 index 0000000..e29b6f0 --- /dev/null +++ b/StringCalc/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/StringCalc/.idea/modules.xml b/StringCalc/.idea/modules.xml new file mode 100644 index 0000000..e111f7a --- /dev/null +++ b/StringCalc/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/StringCalc/.idea/project-template.xml b/StringCalc/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/StringCalc/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/StringCalc/.idea/workspace.xml b/StringCalc/.idea/workspace.xml new file mode 100644 index 0000000..fc48f52 --- /dev/null +++ b/StringCalc/.idea/workspace.xml @@ -0,0 +1,408 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1537276489642 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/main/Main.java + 25 + + + + file://$PROJECT_DIR$/src/main/Main.java + 33 + + + + file://$PROJECT_DIR$/src/main/Main.java + 80 + + + + file://$PROJECT_DIR$/src/main/Main.java + 53 + + + + file://$PROJECT_DIR$/src/main/Main.java + 54 + + + + file://$PROJECT_DIR$/src/main/Main.java + 55 + + + + file://$PROJECT_DIR$/src/main/Main.java + 57 + + + + file://$PROJECT_DIR$/src/main/Main.java + 58 + + + + file://$PROJECT_DIR$/src/main/Main.java + 59 + + + + file://$PROJECT_DIR$/src/main/Main.java + 63 + + + + file://$PROJECT_DIR$/src/main/Main.java + 67 + + + + file://$PROJECT_DIR$/src/main/Main.java + 71 + + + + file://$PROJECT_DIR$/src/main/Main.java + 76 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StringCalc/UnnamedCalc.iml b/StringCalc/UnnamedCalc.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/StringCalc/UnnamedCalc.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/StringCalc/out/production/UnnamedCalc/main/Main.class b/StringCalc/out/production/UnnamedCalc/main/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..958209eda85138e0d5ed28a84030f8a48efee496 GIT binary patch literal 2539 zcmaJ?TT>KA6#jZ|vn<1Hxrq^35p}ufswhD~B0*M(fEN@+G-geO+>2vz@Io~<`o#ywqKfMBQ z3||M(fHMlt7GV${1>nLt1w#RNaYhQm0n}hbPUoe;g#dQrVgQ#gs^GF8R{|)(m>*Z= zfopz@`*Gcm2`SxBa8tp@0o3A_JpYNDG$~HXRZOmKE6^283HW*vM#Ab9aEF`61U&tz z+qyv6P{Pnhva^%Ad0CrGQWG3X#kAy@W+tSZS9+}JL`I-^XjV%Ykzr2VbRh+Sn()NX zjCN0pBsC)*8MVxW5%0D`Xl9&;D!17dP%<&iFm#jq&gra`NJd5-rF5PoFp1_J*8)YU zv~Frv%B1&-!qb)(yTh}JVJF1hBI%{iG_`pF*F-q!`lE@sp;=jzl^odyz_vMV1yyLYmY~EL7)@o(m>x|? z))Yxj9FljXB7{A>7yI4{FI7QY#WWJqV1~>qFp%(7+(A;sEDRMXq*dI7sp5TfD#)m? zkQHd$;KE=ssmHZspBc~2>V`Ei7t_<0UFf}Jb13&R_ac=0G50FBnp?`f$h{2Zp1uC| z^`qBMLPj>pFd^Jy68!=*x;9Hf?FetX zA^Xg4=yR6rV}Yu0vtw4+i|qZRZp5u=yZ6bQVk_0}a7XrqC)_MM!=1_!)<*aX?Bk8_ zm3Bdhsz6N&rlnDmusz|Zgi@VHSs31a3ewpO!|yNLb}G?b2sp1Im~@KN-<-|*W?)LT z*_f8hGGo4Gk^dVwk7y~_I7#sE$Z?0B0a*Dht}0Nigx~gI>u8q>sH6ttvYDsm#xh`=I46K9U>A>+`aWJ zuf7)xEx(~;6(!@r(q)wW(o%oy2YQ0I$SKSb$&c&&Mmdh=_j>Z*3yY$?HCVocimQvF zxiuJcRt>GeN@rEw8mw|w#VlL(uc+zruw-1+E@4Nfx6ae$b9E?nz9rPzp#hz7WEEuW zvm6qK)OF^+*Xn#S;?D2T;qFitahNjWQr_>8a)>gcQ?Bt!xtuaFQ1k+dl+-j8YG$M+Sg0{Ny=}GL6})GsjjA>lbp^XtP@mU5 zc8kTgk2j7yWn7QV7L#`i?BoqKkfR~qXd^4ogmYx*CD!2zIdFr#xJA5EWI%#;4hpY z(>(O@C%Vv0R=LCj^pK;hl6XRnwiBIPNglGrxRN|{t+UVBJHEcx!MzW7q!ZQu&{^dX yR}p{yWlnwtrxf(@Pbm1%#X)~%Wo7E_ii(OiD18I9{BI)Y=V=#C)8l}>iv9 operators = new Stack<>(); + Stack numbers = new Stack<>(); + + line = scanner.nextLine(); + + char[] lineArray = new char[line.length()]; + + lineArray = line.toCharArray(); + + System.out.println(calcExpression(lineArray, operators, numbers)); + } + + static float calcExpression(char[] charArr, Stack operators, Stack numbers) { + for(int i = 0; i < charArr.length; i++) { + + String operatorTemp; + float numberTemp; + + if (charArr == null) + throw new IllegalArgumentException("Num не должен быть null"); + + switch(charArr[i]) { + case '(': { + break; + } + case '+': { + operators.push("+"); + break; + } + case '-': { + operators.push("-"); + break; + } + case '*': { + operators.push("*"); + break; + } + case '/': { + operators.push("/"); + break; + } + case ')': { + operatorTemp = operators.pop(); + numberTemp = numbers.pop(); + + switch(operatorTemp) { + case "+": { + numberTemp = numbers.pop() + numberTemp; + break; + } + case "-": { + numberTemp = numbers.pop() - numberTemp; + break; + } + case "*": { + numberTemp = numbers.pop() * numberTemp; + break; + } + case "/": { + numberTemp = numbers.pop() / numberTemp; + break; + } + } + + numbers.push(numberTemp); + break; + } + default: { + numbers.push(Float.parseFloat(String.valueOf(charArr[i]))); + } + } + } + + return numbers.pop(); + } +} \ No newline at end of file