divinedragon / code-challenges-java Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
To be able to track Code Coverage of the files, we need to setup Jacoco which collects Coverage metrics.
Write code and JUnit test cases for CodingBat - Warmup1 - endUp
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String endUp(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - or35
Return true if the given non-negative number is a multiple of 3 or a multiple of 5. Use the % "mod"
operator -- see Introduction to Mod
or35(3) → true
or35(10) → true
or35(8) → false
public boolean or35(int n) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - frontTimes
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String frontTimes(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - stringSplosion
Given a non-empty string like "Code" return a string like "CCoCodCode".
stringSplosion("Code") → "CCoCodCode"
stringSplosion("abc") → "aababc"
stringSplosion("ab") → "aab"
public String stringSplosion(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - sumDouble
Given two int values, return their sum. Unless the two values are the same, then return double their sum.
sumDouble(1, 2) → 3
sumDouble(3, 2) → 5
sumDouble(2, 2) → 8
public int sumDouble(int a, int b) {
}
### Tasks
- [x] https://github.com/divinedragon/code-challenges-java/issues/45
- [x] https://github.com/divinedragon/code-challenges-java/issues/46
- [x] https://github.com/divinedragon/code-challenges-java/issues/47
- [x] https://github.com/divinedragon/code-challenges-java/issues/48
- [x] https://github.com/divinedragon/code-challenges-java/issues/49
- [x] https://github.com/divinedragon/code-challenges-java/issues/50
- [x] https://github.com/divinedragon/code-challenges-java/issues/51
- [x] https://github.com/divinedragon/code-challenges-java/issues/52
- [x] https://github.com/divinedragon/code-challenges-java/issues/53
- [x] https://github.com/divinedragon/code-challenges-java/issues/54
- [x] https://github.com/divinedragon/code-challenges-java/issues/55
- [x] https://github.com/divinedragon/code-challenges-java/issues/56
- [x] https://github.com/divinedragon/code-challenges-java/issues/57
- [x] https://github.com/divinedragon/code-challenges-java/issues/58
- [x] https://github.com/divinedragon/code-challenges-java/issues/59
- [x] https://github.com/divinedragon/code-challenges-java/issues/60
- [x] https://github.com/divinedragon/code-challenges-java/issues/61
Write code and JUnit test cases for CodingBat - Warmup1 - startHi
Given a string, return true if the string starts with "hi" and false otherwise.
startHi("hi there") → true
startHi("hi") → true
startHi("hello hi") → false
public boolean startHi(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - everyNth
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String everyNth(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - frontBack
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
frontBack("code") → "eodc"
frontBack("a") → "a"
frontBack("ab") → "ba"
public String frontBack(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - parrotTrouble
We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return true if we are in trouble.
parrotTrouble(true, 6) → true
parrotTrouble(true, 7) → false
parrotTrouble(false, 6) → false
public boolean parrotTrouble(boolean talking, int hour) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - makes10
Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.
makes10(9, 10) → true
makes10(9, 9) → false
makes10(1, 9) → true
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - in1020
Given 2 int values, return true if either of them is in the range 10..20 inclusive.
in1020(12, 99) → true
in1020(21, 12) → true
in1020(8, 99) → false
public boolean in1020(int a, int b) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - stringE
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
stringE("Hello") → true
stringE("Heelle") → true
stringE("Heelele") → false
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - startOz
Given a string, return a string made of the first 2 chars (if present), however include first char only if it is 'o' and include the second only if it is 'z', so "ozymandias" yields "oz".
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String startOz(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - stringBits
Given a string, return a new string made of every other char starting with the first, so "Hello" yields "Hlo".
stringBits("Hello") → "Hlo"
stringBits("Hi") → "H"
stringBits("Heeololeo") → "Hello"
public String stringBits(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - sleepIn
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - delDel
Given a string, if the string "del" appears starting at index 1, return a string where that "del" has been deleted. Otherwise, return the string unchanged.
delDel("adelbc") → "abc"
delDel("adelHello") → "aHello"
delDel("adedbc") → "adedbc"
public String delDel(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - stringMatch
Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the "xx", "aa", and "az" substrings appear in the same place in both strings.
stringMatch("xxcaazz", "xxbaaz") → 3
stringMatch("abc", "abc") → 2
stringMatch("abc", "axc") → 0
public int stringMatch(String a, String b) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - notString
Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: use .equals()
to compare 2 strings.
notString("candy") → "not candy"
notString("x") → "not x"
notString("not bad") → "not bad"
public String notString(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - front3
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - icyHot
Given two temperatures, return true if one is less than 0 and the other is greater than 100.
icyHot(120, -1) → true
icyHot(-1, 120) → true
icyHot(2, 120) → false
public boolean icyHot(int temp1, int temp2) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - close10
Given 2 int values, return whichever value is nearest to the value 10, or return 0 in the event of a tie. Note that Math.abs(n)
returns the absolute value of a number.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public int close10(int a, int b) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - monkeyTrouble
We have two monkeys, a and b, and the parameters aSmile
and bSmile
indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - front22
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - loneTeen
We'll say that a number is "teen" if it is in the range 13..19 inclusive. Given 2 int values, return true if one or the other is teen, but not both.
loneTeen(13, 99) → true
loneTeen(21, 19) → true
loneTeen(13, 13) → false
public boolean loneTeen(int a, int b) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - countXX
Count the number of "xx" in the given string. We'll say that overlapping is allowed, so "xxx" contains 2 "xx".
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String everyNth(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - posNeg
Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
posNeg(1, -1, false) → true
posNeg(-1, 1, false) → true
posNeg(-4, -5, true) → true
public boolean posNeg(int a, int b, boolean negative) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - backAround
Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more.
backAround("cat") → "tcatt"
backAround("Hello") → "oHelloo"
backAround("a") → "aaa"
public String backAround(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - missingChar
Given a non-empty string and an int n, return a new string where the char at index n has been removed. The value of n will be a valid index of a char in the original string (i.e. n will be in the range 0..str.length()-1 inclusive).
missingChar("kitten", 1) → "ktten"
missingChar("kitten", 0) → "itten"
missingChar("kitten", 4) → "kittn"
public String missingChar(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - hasTeen
We'll say that a number is "teen" if it is in the range 13..19 inclusive. Given 3 int values, return true if 1 or more of them are teen.
hasTeen(13, 20, 10) → true
hasTeen(20, 19, 10) → true
hasTeen(20, 10, 13) → true
public boolean hasTeen(int a, int b, int c) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - intMax
Given three int values, a b c, return the largest.
intMax(1, 2, 3) → 3
intMax(1, 3, 2) → 3
intMax(3, 2, 1) → 3
public int intMax(int a, int b, int c) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - in3050
Given 2 int values, return true if they are both in the range 30..40 inclusive, or they are both in the range 40..50 inclusive.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean in3050(int a, int b) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - lastDigit
Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public boolean sleepIn(boolean weekday, boolean vacation) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - max1020
Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public int max1020(int a, int b) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - arrayFront9
Given an array of ints, return true if one of the first 4 elements in the array is a 9. The array length may be less than 4.
arrayFront9([1, 2, 9, 3, 4]) → true
arrayFront9([1, 2, 3, 4, 9]) → false
arrayFront9([1, 2, 3, 4, 5]) → false
public String everyNth(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - mixStart
Return true if the given string begins with "mix", except the 'm' can be anything, so "pix", "9ix" .. all count.
mixStart("mix snacks") → true
mixStart("pix snacks") → true
mixStart("piz snacks") → false
public boolean mixStart(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - arrayCount9
Given an array of ints, return the number of 9's in the array.
arrayCount9([1, 2, 9]) → 1
arrayCount9([1, 9, 9]) → 2
arrayCount9([1, 9, 9, 3, 9]) → 3
public int arrayCount9(int[] nums) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - array123
Given an array of ints, return true if the sequence of numbers 1, 2, 3 appears in the array somewhere.
array123([1, 1, 2, 3, 1]) → true
array123([1, 1, 2, 4, 1]) → false
array123([1, 1, 2, 1, 2, 3]) → true
public boolean array123(int[] nums) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - doubleX
Given a string, return true if the first instance of "x" in the string is immediately followed by another "x".
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
boolean doubleX(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - stringX
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
stringX("xxHxix") → "xHix"
stringX("abxxxcd") → "abcd"
stringX("xabxxxcdx") → "xabcdx"
public String stringX(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - last2
Given a string, return the count of the number of times that a substring length 2 appears in the string and also as the last 2 chars of the string, so "hixxxhi" yields 1 (we won't count the end substring).
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public int last2(String str) {
}
Write code and JUnit test cases for CodingBat - Warmup1 - nearHundred
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
nearHundred(93) → true
nearHundred(90) → true
nearHundred(89) → false
public boolean sleepIn(boolean weekday, boolean vacation) {
}
### Tasks
- [x] https://github.com/divinedragon/code-challenges-java/issues/12
- [x] https://github.com/divinedragon/code-challenges-java/issues/13
- [x] https://github.com/divinedragon/code-challenges-java/issues/14
- [x] https://github.com/divinedragon/code-challenges-java/issues/15
- [x] https://github.com/divinedragon/code-challenges-java/issues/16
- [x] https://github.com/divinedragon/code-challenges-java/issues/17
- [x] https://github.com/divinedragon/code-challenges-java/issues/18
- [x] https://github.com/divinedragon/code-challenges-java/issues/19
- [x] https://github.com/divinedragon/code-challenges-java/issues/20
- [x] https://github.com/divinedragon/code-challenges-java/issues/21
- [x] https://github.com/divinedragon/code-challenges-java/issues/22
- [x] https://github.com/divinedragon/code-challenges-java/issues/23
- [x] https://github.com/divinedragon/code-challenges-java/issues/24
- [x] https://github.com/divinedragon/code-challenges-java/issues/25
- [x] https://github.com/divinedragon/code-challenges-java/issues/26
- [x] https://github.com/divinedragon/code-challenges-java/issues/27
- [x] https://github.com/divinedragon/code-challenges-java/issues/28
- [x] https://github.com/divinedragon/code-challenges-java/issues/29
- [x] https://github.com/divinedragon/code-challenges-java/issues/30
- [x] https://github.com/divinedragon/code-challenges-java/issues/31
- [x] https://github.com/divinedragon/code-challenges-java/issues/32
- [x] https://github.com/divinedragon/code-challenges-java/issues/33
- [x] https://github.com/divinedragon/code-challenges-java/issues/34
- [x] https://github.com/divinedragon/code-challenges-java/issues/35
- [x] https://github.com/divinedragon/code-challenges-java/issues/36
- [x] https://github.com/divinedragon/code-challenges-java/issues/37
- [x] https://github.com/divinedragon/code-challenges-java/issues/38
- [x] https://github.com/divinedragon/code-challenges-java/issues/39
- [x] https://github.com/divinedragon/code-challenges-java/issues/40
- [x] https://github.com/divinedragon/code-challenges-java/issues/41
- [x] https://github.com/divinedragon/code-challenges-java/issues/42
Write code and JUnit test cases for CodingBat - Warmup1 - diff21
Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.
diff21(19) → 2
diff21(10) → 11
diff21(21) → 0
public int diff21(int n) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - stringTimes
Given a string and a non-negative int n, return a larger string that is n copies of the original string.
stringTimes("Hi", 2) → "HiHi"
stringTimes("Hi", 3) → "HiHiHi"
stringTimes("Hi", 1) → "Hi"
public String stringTimes(String str, int n) {
}
Write code and JUnit test cases for CodingBat - Warmup2 - altPairs
Given a string, return a string made of the chars at indexes 0,1, 4,5, 8,9 ... so "kittens" yields "kien".
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
public String altPairs(String str) {
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.