commit 244099760edba4c238c70cf679af1c45dfd776b3 Author: ChronosX88 Date: Sat Sep 21 17:07:09 2019 +0400 Init commit 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 0000000..958209e Binary files /dev/null and b/StringCalc/out/production/UnnamedCalc/main/Main.class differ diff --git a/StringCalc/src/main/Main.java b/StringCalc/src/main/Main.java new file mode 100644 index 0000000..f6e33e3 --- /dev/null +++ b/StringCalc/src/main/Main.java @@ -0,0 +1,88 @@ +package main; + +import java.util.Scanner; +import java.util.Stack; +import java.util.stream.IntStream; + +public class Main { + + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + String line; + Stack 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