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
Expand Up @@ -4,7 +4,19 @@
public class Bob {

public static String hey(String phrase) {
return "";

if (phrase.trim().isEmpty()) {
return "Fine.";
}

if (phrase.equals(phrase.toUpperCase()) && !phrase.equals(phrase.toLowerCase())) {
return "Chill out!";
}

if (phrase.endsWith("?")) {
return "Yeap.";
}
else return "Whatever.";
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,71 @@
package school.lemon.changerequest.java.introduction.pr1;


import java.util.Scanner;

public class ConsoleCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
makeChoice();
String input;
int a, b;
while (true) {
while (!scanner.hasNext("(exit|help|add|sub|mul|div)")) {
System.out.println("False, please try again.");
makeChoice();
scanner.next();
}
input = scanner.next();

if (input.equals("exit")) {
System.out.println("Bye-bye");
scanner.close();
break;
}
if (input.equals("help")) {
makeChoice();
scanner.next();
}
Copy link
Member

Choose a reason for hiding this comment

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

I personally don't like such solution, where you move some switch clauses into separate if-else statements, I'd really prefer some other implementation where all possible commands would be inside one switch.


System.out.println("Enter first number:");
a = scanner.nextInt();
System.out.println("Enter second number:");
b = scanner.nextInt();

switch (input) {
case "add":
int sum = a + b;
System.out.println(a + "+" + b + "= " + sum);
break;
case "sub":
int sub = a - b;
System.out.println(a + "-" + b + "= " + sub);
break;
case "mul":
int mul = a * b;
System.out.println(a + "*" + b + "= " + mul);
break;
case "div":
int div = a / b;
System.out.println(a + "/" + b + "= " + div);
break;
}
makeChoice();
}

}

private static void makeChoice () {
Copy link
Member

Choose a reason for hiding this comment

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

This function should be renamed, as it don't really "make any choice", it just prints your "help" or "menu" messages.

System.out.println("Console calculator");
System.out.println("Enter 'add' to perform addition.");
System.out.println("Enter 'sub' to perform subtraction.");
System.out.println("Enter 'mul' to perform multiplication.");
System.out.println("Enter 'div' to perform division.");
System.out.println("Enter 'exit' to exit.");
System.out.println("Enter 'help' to see help message.");
System.out.println("Make your choice.");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

public class HammingDistance {
public static int compute(String a, String a1) {
return -1;

if (a.length() != a1.length()) return -1;

int result = 0;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) != a1.charAt(i)) {
return result++;
Copy link
Member

Choose a reason for hiding this comment

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

for sure, you shouldn't return result here, you should only increment it here.

}
}
return result;
}
}