Skip to content

Instantly share code, notes, and snippets.

@Verssae
Created November 30, 2022 07:49
Show Gist options
  • Save Verssae/e4baf9a43599519cbc5fe80dfeaf56e6 to your computer and use it in GitHub Desktop.
Save Verssae/e4baf9a43599519cbc5fe80dfeaf56e6 to your computer and use it in GitHub Desktop.
A Class for JUnit5 Exercise (CSE2024 SW Development Practices)
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);
}
}
@Verssae
Copy link
Author

Verssae commented Nov 21, 2023

You can modify the return type of countLongWords() method to int from void before writing test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment