Question

In: Computer Science

The project requires you to implement 4 functions of your choice in a file called Utilities.java....

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.

Solutions

Expert Solution

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


Related Solutions

You first needs to create a file called “myJS.js” in your project directory. Then, include the...
You first needs to create a file called “myJS.js” in your project directory. Then, include the AngularJS library and myJS.js in the header of the index.html page. Now, you need to define your angular application and a controller in this file such that the controller has the following variables with these initial values: name = "Alex Cool"; faculty= "Faculty of Busienss and IT"; university = {name:"University of Ontario Institute of Technology", url:"http://www.uoit.ca"}; contacts = {email:"[email protected]", phone:"xxx-xxx-xxxx"}; skills = [ {name:...
C coding • Implement, using structures and functions as appropriate, a program which requires you to...
C coding • Implement, using structures and functions as appropriate, a program which requires you to enter a number of points in 3 dimensions. The points will have a name (one alphanumeric character) and three coordinates x, y, and z. Find and implement a suitable way to stop the input loop. The program, through an appropriate distance function, should identify the two points which are the furthest apart. Another function should calculate the centre of gravity of the point cloud...
Based on this player.h file, could you make a player.c file which defines the 4 functions?...
Based on this player.h file, could you make a player.c file which defines the 4 functions? Thanks. player.h: #ifndef PLAYERH #define PLAYERH #define MAX_ITEMS 10 typedef struct Player { int location; int num_items; int mitems[MAX_ITEMS] }t_player; void player_init_player(t_player *player, int location); //initialize player void player_add_item(t_player *player, int item); void player_remove_item(t_player *player, int item); int player_has_item(t_player *player, int item); //returns -1 if no item exists #endif
Project 4 – The Nearest Neighbors Classification Algorithm This project will require you to implement a...
Project 4 – The Nearest Neighbors Classification Algorithm This project will require you to implement a version of the Nearest Neighbors classification algorithm. This version, the Three Nearest Neighbors (or 3NN for short), is one of the more intuitive classification algorithms, and one of the easier ones to code. This Nearest Neighbors family of algorithms is useful because it does not require any special “training” to work. You simply need previous data to compare to. What is classification? With classification,...
Implement the following functions in a module called arrayfunctions.py. You must use the booksite modules stdarray...
Implement the following functions in a module called arrayfunctions.py. You must use the booksite modules stdarray and stdio to implement the functions.   print1Darray() takes a one dimensional integer array argument and prints it (field width for each element should be 5). print2Darray() takes a two dimensional integer array argument and prints it (field width for each element should be 5 - should be printed as a m x n matrix). add2Darrays() takes 2, two dimensional integer array arguments. You can...
This assignment requires you to look at one interface for a product of your choice, identify...
This assignment requires you to look at one interface for a product of your choice, identify what it was developed for, and then trace back its history (to the origin if possible) to look for similar solutions. This way you'll be clearer what the original problem is and how human through out history has managed it. You'll see that whole or part of the very early solutions seem to stay in most of the newer solutions, and you'll be able...
Please use excel file to solve You are evaluating a project for your company. The project...
Please use excel file to solve You are evaluating a project for your company. The project will require equipment that has a purchase price of $500,000, and will need to include $60,000 for delivery costs and $70,000 for installation related expenses. The equipment will be depreciated using MACRS as a 10 year class asset. Assume you expect a salvage value of $50,000 at the end of the projects life. In addition, land will need to be purchased for $1,500,000. The...
For problems 3 and 4, consider the following functions that implement the dequeue operation for a...
For problems 3 and 4, consider the following functions that implement the dequeue operation for a priority queue that is implemented with a heap. int[] pQueue; int length; int dequeue() { int node = 1; int value = pQueue[--length]; int maxValue = pQueue[node]; int location = sift(node * 2, value); pQueue[location] = value; return maxValue; } int sift(int node, int value) { if (node <= length) { if (node < length && pQueue[node] < pQueue[node + 1]) node++; if (value...
Using JavaScript You must submit a file called, called pass.js pass.js: Validator of passwords Your task...
Using JavaScript You must submit a file called, called pass.js pass.js: Validator of passwords Your task this week will be to program a valid password validator. A password is safe only if it satisfies the following constraints: - It has from 5 to 10 characters (inclusive) - It contains at least one lowercase letter, at least one capital letter and at least one number - The first character is different from the last Once the password is entered and validated,...
Question 1: You are currently evaluating a new project for your company. The project requires an...
Question 1: You are currently evaluating a new project for your company. The project requires an initial investment in equipment RM 90,000 and an investment in working capital of RM10,000 at the beginning (t=0). The project is expected to produce sales revenues of RM120, 000 for three years. Manufacturing costs are estimated to be 60% of the revenues. The asset is depreciated over the project’s life using straight-line depreciation method. At the end of the project (t=3), you can sell...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT