-
Notifications
You must be signed in to change notification settings - Fork 7
Pr1-all #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Pr1-all #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,35 @@ | ||
| package school.lemon.changerequest.java.introduction.pr1; | ||
|
|
||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class Bob { | ||
|
|
||
| public static String hey(String phrase) { | ||
| return ""; | ||
| String phraseCheck=phrase.replaceAll(" ",""); | ||
| if(phraseCheck.equals("")){return "Fine.";} | ||
| char question ='?'; | ||
| char dot = '.'; | ||
| char exclamation ='!'; | ||
| char last= phrase.charAt(phrase.length()-1); | ||
| String anger= phrase.toUpperCase(); | ||
| String notAnger= phrase.toLowerCase(); | ||
| boolean notString=anger==notAnger; | ||
| if (last==question&&(notString||phrase!=anger)) | ||
| {return "Yeap.";} | ||
|
|
||
| if (anger==phrase&&anger!=notAnger){return "Chill out!";} | ||
|
|
||
| return "Whatever."; | ||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,46 @@ | ||
| package school.lemon.changerequest.java.introduction.pr1; | ||
|
|
||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class ConsoleCalculator { | ||
|
|
||
| public static void main(String[] args) { | ||
| System.out.print("Console calculator:\n " + | ||
| "Enter 'add' to perform addition.\n " + | ||
| "Enter 'sub' to perform subtraction.\n " + | ||
| "Enter 'mul' to perform multiplication.\n " + | ||
| "Enter 'div' to perform division.\n " + | ||
| "Enter 'exit' to exit.\n " + | ||
| "Enter 'help' to see help message.\n "); | ||
| int exit=1; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For such purposes it's better to use |
||
|
|
||
| while (exit==1){ | ||
| System.out.print("Make your choice.\n"); | ||
| Scanner sc = new Scanner(System.in); | ||
| String s1 = sc.nextLine(); | ||
| if (s1.equals("exit")) {System.out.println("Bye-bye."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is actually no need for this check. It'll be better if you could move all possible commands cases into |
||
| exit=0; | ||
| break; } | ||
|
|
||
| System.out.print("Enter first number\n"); | ||
| int number1 = sc.nextInt(); | ||
| System.out.print("Enter second number\n"); | ||
| int number2 = sc.nextInt(); | ||
| switch (s1) { | ||
| case "add": | ||
| System.out.println("Result of" + number1 + "+" + number2 + "is" + (number1 + number2)); | ||
| break; | ||
| case "sub": System.out.println("Result of" + number1 + "-" + number2 + "is" + (number1 - number2)); | ||
| break; | ||
| case "mul": System.out.println("Result of" + number1 + "*" + number2 + "is" + (number1 * number2)); | ||
| break; | ||
| case "div": System.out.println("Result of" + number1 + "/" + number2 + "is" + (number1 / number2)); | ||
| break; | ||
|
|
||
| default: System.out.println("WRONG!"); | ||
| break; | ||
|
|
||
| }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And what about |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,21 @@ | |
|
|
||
| public class HammingDistance { | ||
| public static int compute(String a, String a1) { | ||
| return -1; | ||
| } | ||
| } | ||
| char[] aA = a.toCharArray(); | ||
| char[] a1A1 = a1.toCharArray(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for this 2 additional variables. |
||
| int count = 0; | ||
| if (a.length()!= a1.length()) { | ||
| return -1; | ||
| } | ||
| for (int i=0;i<a.length();i++) { | ||
| if (a1A1[i]!=aA[i]) { | ||
| count = count + 1; | ||
| } | ||
|
|
||
| if (i == a1.length()-1) { | ||
|
|
||
| return count;} | ||
| } | ||
|
|
||
| return 0; | ||
| }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ class BobSpecification extends Specification { | |
| "Ending with ? means a question." || "Whatever." | ||
| "I HATE YOU" || "Chill out!" | ||
| "Wait! Hang on. Are you going to be OK?" || "Yeap." | ||
| " " || "Fine." | ||
| " " || "Fine." | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you shouldn't modify tests. |
||
| "" || "Fine." | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done lots of operations that could be avoided.
Try to solve task step-by-step, so that if you already know that it's question - don't do anything related to yelling.
Also, there is easier way to check if it's question or not - just use
endWithStringmethod.