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,26 @@
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 "";


if (phrase.equals(phrase.toUpperCase()) ) {
Copy link

Choose a reason for hiding this comment

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

The thing is, that "1 2 3".toUpperCase() is the same as 1 2 3.
There are two ways, first one - use regexp figure out whether string contains upper case letters. Second one - additionally use toLowerCase().

return "Chill out!";
}
else if (phrase.endsWith("?")) {
Copy link

Choose a reason for hiding this comment

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

Please format your code.

return "Yeap.";
}
String trimmed = phrase.trim();
if (trimmed.isEmpty()) {
return "Fine.";
}

return "Whatever.";
}

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


import java.util.Scanner;

public class ConsoleCalculator {
public int Add(int scannetFirstNumInt, int scannetSecondNumInt, String scannerOperations) {
Copy link

Choose a reason for hiding this comment

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

Please use lowerCamelCase for method names https://ru.wikipedia.org/wiki/CamelCase
Also please use static for this methods, so it won't be needed to create instance of ConsoleCalculator

if (scannerOperations.equals("add"))
{
return scannetFirstNumInt + scannetSecondNumInt;}
return 0;
}

public static void main(String[] args) {
public int Sub(int scannerFirstNum, int scannerSecondNum) {
return scannerFirstNum - scannerSecondNum;
}

public int Mul(int scannerFirstNum, int scannerSecondNum) {
return scannerFirstNum * scannerSecondNum;
}

public int Div(int scannerFirstNum, int scannerSecondNum) {
return scannerFirstNum / scannerSecondNum;
}


public static void main(String[] args) {
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.");
Scanner scannerOperations = new Scanner(System.in);


Copy link

Choose a reason for hiding this comment

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

User should have possibility to do more than one operations, so there should be a loop, until user enter exit.

System.out.println("Enter first number:");
Scanner scannerFirstNum = new Scanner(System.in);
int scannetFirstNumInt;
if (scannerFirstNum.hasNextInt()) {
scannetFirstNumInt = scannerFirstNum.nextInt();}

System.out.println("Enter second number:");
Scanner scannerSecondNum = new Scanner(System.in);
int scannetSecondNumInt;
if (scannerSecondNum.hasNextInt()) {
scannetSecondNumInt = scannerSecondNum.nextInt();}


ConsoleCalculator resultat = new ConsoleCalculator();

System.out.println("Result of" + resultat);
System.out.println("Make your choice.");
Scanner scannerOperationsSecond = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

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

One scanner will be enough for reading all numbers and operations, so no reason to create another one.

System.out.println("Make your choice.");

}


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

public class HammingDistance {
public static int compute(String a, String a1) {
if (a.length() == a1.length()) {
int numbers = 0;
for (int i = 0; i < a.length(); i++) {
if (a.charAt(i) != a1.charAt(i))
numbers++;
}
return numbers;
}
return -1;
}
}