In: Computer Science
The project requires you to implement 4 functions of your choice in a file called Utilities.java. The functions may relate to statistics, graphics/animation, audio, text, or image applications.
Deliverables (files that need to be submitted):
1. A word document that briefly describes the functions that were implemented and the API.
2. Utilities.java file with the 4 functions and a Test.java file that provides examples of using the functions in Utilities.java.
Test.Java Code
package test_package;
import java.io.Console;
import java.util.Scanner;
public class Test extends utilities {
public static void Find_Average_Function()
{utilities u = new utilities();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of array ");
int a = sc.nextInt();
int [ ] number = new int [a]; // instantiate the array
int i;
int sum=0;
for ( i = 0; i < a; i++ ) // fill the array
number[ i ] = sc.nextInt();
float suma = u.find_average(number, a); // invoke the method
System.out.println("The average is" +suma + ".");
}
public static void Find_Sum_Function()
{utilities u = new utilities();
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of array ");
int a = sc.nextInt();
int [ ] number = new int [a]; // instantiate the array
int i;
int sum=0;
for ( i = 0; i < a; i++ ) // fill the array
number[ i ] = sc.nextInt();
float suma = u.find_sum(number, a); // invoke the method
System.out.println("The sum is" +suma + ".");
}
public static void Check_Pallindrome()
{
utilities u = new utilities();
System.out.println("Enter the String");
Scanner next = new Scanner(System.in);
String text = next.next();
if(u.isPalindrom(text))
{
System.out.print("It is Pallindrome");
}
else
{
System.out.print("It is not pallindrome");
}
}
public static void Number_Of_Vowels()
{
utilities u = new utilities();
System.out.println("Enter the String");
Scanner next = new Scanner(System.in);
String text = next.next();
System.out.println("The number of vowels are "+ u.Number_Of_Vowels(text));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("Enter the Choice of Function you want to Execute :");
System.out.println("1: Find Average Of Numbers");
System.out.println("2: Check if The String is Pallindrome or not");
System.out.println("3: Find Sum of Numbers");
System.out.println("4: Find The number of Vowels");
int choice = input.nextInt();
if(choice == 1)
{
Find_Average_Function();
}
else if(choice == 2)
{
Check_Pallindrome();
}
else if(choice == 3)
{
Find_Sum_Function();
}
else if(choice == 4)
{
Number_Of_Vowels();
}
}
}
Utilities.Java Code
package test_package;
public class utilities {
//Find Average of Numbers
public static float find_average(int [ ] numbers,int size) //method definition to find Average of numbers
{
float total = 0;
int i;
for(i=0; i< size; i++)
{
total = total + numbers[ i ];
}
return (total/size);
}
public static int find_sum(int [ ] numbers,int size) //method definition to find Sum of numbers
{
int total = 0;
int i;
for(i=0; i< size; i++)
{
total = total + numbers[ i ];
}
return (total);
}
//find if the String is pallindrome or not
public static Boolean isPalindrom(String text)
{
String reverse = "";
int length = text.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + text.charAt(i);
if (text.equals(reverse))
return true;
else
return false;
}
public static int Number_Of_Vowels(String str)
{
int count = 0;
for (int i = 0; i < str.length(); i++)
{
if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i'|| str.charAt(i) == 'o' || str.charAt(i) == 'u')
{
count++;
}
}
return count;
}
}
OutPut ScreenShot
Word File Explaining 4 Functions :
find_average - This Function Takes Two
Parameters . One is Array and Other is Size of Array .It returns
the Average of numbers passed as parameteres
Find_Sum : This Function Takes Two
Parameters . One is Array and Other is Size of Array . It returns
The Sum of numbers passed as parameters
Check Pallindrome : This Function
Takes a string and Check Wether that string is a pallindrome string
or not . It return True if string and reverse of that string return
equal
Number_of_Vowels : This Function Takes a String and
return the number of Vowels in that string