Created
November 30, 2022 07:49
-
-
Save Verssae/e4baf9a43599519cbc5fe80dfeaf56e6 to your computer and use it in GitHub Desktop.
A Class for JUnit5 Exercise (CSE2024 SW Development Practices)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.List; | |
/** | |
* A Class for JUnit5 Exercise (CSE2024 SW Development Practices) | |
* | |
* @author juhansae | |
* @version 2022.2 | |
* @// Create a JUnit test class with some test methods | |
* @// Then, refactor it to pass all the tests ! | |
*/ | |
public class Utility { | |
public static void main(String[] args) { | |
System.out.println("This will be printed"); | |
} | |
public static int dayOfYear(int month, int dayOfMonth, int year) { | |
if (month == 2) { | |
dayOfMonth += 31; | |
} else if (month == 3) { | |
dayOfMonth += 59; | |
} else if (month == 4) { | |
dayOfMonth += 90; | |
} else if (month == 5) { | |
dayOfMonth += 31 + 28 + 31 + 30; | |
} else if (month == 6) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31; | |
} else if (month == 7) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30; | |
} else if (month == 8) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30 + 31; | |
} else if (month == 9) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 30; | |
} else if (month == 10) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 30 + 30; | |
} else if (month == 11) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 30 + 30 + 31; | |
} else if (month == 12) { | |
dayOfMonth += 31 + 28 + 31 + 30 + 31 + 30 + 31 + 30 + 30 + 31 + 31; | |
} | |
return dayOfMonth; | |
} | |
public static boolean leap(int y) { | |
String tmp = String.valueOf(y); | |
if (tmp.charAt(2) == '1' || tmp.charAt(2) == '3' || tmp.charAt(2) == 5 || tmp.charAt(2) == '7' || tmp.charAt(2) == '9') { | |
if (tmp.charAt(3)=='2'||tmp.charAt(3)=='6') return true; | |
else | |
return false; | |
}else{ | |
if (tmp.charAt(2) == '0' && tmp.charAt(3) == '0') { | |
return false; | |
} | |
if (tmp.charAt(3)=='0'||tmp.charAt(3)=='4'||tmp.charAt(3)=='8')return true; | |
} | |
return false; | |
} | |
public static int LONG_WORD_LENGTH = 5; | |
public static String longestWord; | |
public static void countLongWords(List<String> words) { | |
int n = 0; | |
longestWord = ""; | |
for (String word: words) { | |
if (word.length() > LONG_WORD_LENGTH) ++n; | |
if (word.length() > longestWord.length()) longestWord = word; | |
} | |
System.out.println(n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can modify the return type of
countLongWords()
method toint
fromvoid
before writing test cases.