Create a package called "operations" by adding the following line at the top of your Java file:
Copy code
package operations;
Create a class called "Calculator" that contains methods for performing basic arithmetic operations. For example:
Copy code
public class Calculator {
public static int add(int a, int b) {
return a + b;
}
public static int subtract(int a, int b) {
return a - b;
}
public static int multiply(int a, int b) {
return a * b;
}
public static int divide(int a, int b) {
return a / b;
}
}
Create a class called "StringUtils" that contains methods for manipulating strings. For example:
Copy code
public class StringUtils {
public static String reverse(String s) {
return new StringBuilder(s).reverse().toString();
}
public static int countVowels(String s) {
int count = 0;
for (char c : s.toCharArray()) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}
return count;
}
}
To use these classes in another Java file, you can import the package and call the methods like this:
Copy code
import operations.*;
public class Main {
public static void main(String[] args) {
int result = Calculator.add(5, 7);
System.out.println(result); // prints 12
String reversed = StringUtils.reverse("Hello World");
System.out.println(reversed); // prints "dlroW olleH"
}
}
This is just one way to structure a Java package with classes that perform various operations. You can add more classes and methods to the package as needed to meet the specific requirements of your project.