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,28 @@
public class Bob {

public static String hey(String phrase) {
return "";
char ch;
int counter = 0;
boolean flag = true;
String reply = "";
if(phrase == "") return "Fine.";

for(int i = 0; i < phrase.length(); i++){
ch = phrase.charAt(i);
if(ch == '?'){
reply = "Yeap.";
} else if(ch == '!'){
Copy link
Member

Choose a reason for hiding this comment

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

It's not correct case for yelling. Check the test cases and determine what should be in the phrase for each type of answer.

reply = "Chill out!";
} else if(ch == '.') {
reply = "Whatever.";
} else if(ch == ' '){
counter++;
} else continue;
}
if(counter == phrase.length())
reply = "Fine.";

return reply;
}

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

import java.util.Scanner;

public class ConsoleCalculator {

public static void main(String[] args) {
System.out.println("Console Calculation");
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");
boolean flag = true;
while(flag) {
System.out.println("Make your choice: ");
Scanner read = new Scanner(System.in);
String choice = read.next();
choice = choice.toLowerCase();
switch (choice) {
case "add": {
System.out.println("Enter first number: ");
int first = read.nextInt();
System.out.println("Enter second number: ");
int second = read.nextInt();
int res = first + second;
System.out.println(" Result of " + first + "+" + second + " is " + res);
break;
}
case "sub" : {
System.out.println("Enter first number: ");
int first = read.nextInt();
System.out.println("Enter second number: ");
int second = read.nextInt();
int res = first - second;
System.out.println(" Result of " + first + "-" + second + " is " + res);
break;
}
case "mul" : {
System.out.println("Enter first number: ");
int first = read.nextInt();
System.out.println("Enter second number: ");
int second = read.nextInt();
int res = first*second;
System.out.println(" Result of " + first + "*" + second + " is " + res);
break;
}
case "div" : {
System.out.println("Enter first number: ");
int first = read.nextInt();
System.out.println("Enter second number: ");
int second = read.nextInt();
double res = first/second;
System.out.println(" Result of " + first + "/" + second + " is " + res);
break;
}
case "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.

You should return Bye-bye to pass the test.

flag = false;
break;
}
case "help" : {
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");
}

}
}

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

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