Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.";
Copy link
Member

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 endWith String method.




}




}

}

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For such purposes it's better to use boolean variables.


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.");
Copy link
Member

Choose a reason for hiding this comment

The 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 switch statement. And also do not forget about code duplication - create additional functions if they'll help you.

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;

}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about help command ? I don't see any handler for help.

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this 2 additional variables.
String has method chatAt that will given you character at some position.

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
Expand Up @@ -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."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't modify tests.

"" || "Fine."
}
}