public class Module4 {
void displayContents(int arr[])//diplay content
{
for(int i=0;i<arr.length;i++)
System.out.println(arr[i]);
}
int[] removeNegatives(int arr[])//remove -ves
{int count_negatives=0;
for(int i=0;i<arr.length;i++)//count -ves
if(arr[i]<0)
count_negatives++;
int new_arr[]=new int[arr.length-count_negatives];//create
array
int k=0;
for(int i=0;i<arr.length;i++)
if(arr[i]>=0)//if +ve then keep in new array
new_arr[k++]=arr[i];
return new_arr;
}
int[][] arrayProduct(int x[] ,int y[])
{
int Array_2d[][]=new int[x.length][y.length];
for(int i=0;i<x.length;i++)//compute product
for(int j=0;j<y.length;j++)
Array_2d[i][j]=x[i]*y[j];
return Array_2d;
}
}
//test
public class test {//test Module4
public static void main(String args[])
{ int x[]={0,1,2,3},y[]={-1,-2,0,-3,5,7,13},z[][];
Module4 m=new Module4();
m.displayContents(x);
m.displayContents(y);
System.out.println("After removing -ves in array y");
m.displayContents(m.removeNegatives(y));
z=m.arrayProduct(x, y);
System.out.println("Array Product is:");
for(int i=0;i<x.length;i++)
{for(int j=0;j<y.length;j++)
System.out.print(z[i][j]+"\t");
System.out.println();}
}
}
JAVA HELP (ARRAYS) Assignment Create a class named Module4 containing the following data members and methods...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
You must create a Java class named TenArrayMethods in a file named TenArrayMethods.java. This class must include all the following described methods. Each of these methods should be public and static.Write a method named getFirst, that takes an Array of int as an argument and returns the value of the first element of the array. NO array lists. Write a method named getLast, that takes an Array of int as an argument and returns the value of the last element...
Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...
Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...
Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An instance variable named x of type int. An instance variable named y of type int. Declare a method named toString() Returns a string representation of the point. Constructor that accepts values of all data members as arguments. Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point....
Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...
Given the following construct a UML diagram for Java: Design a class named location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximum value and its indices in a two-dimensional array with row and column as int types and maxValue as double type. Write the following method that returns the location of the largest element in two-dimensional array: Public static Location locateLargest(double[][] a)...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
Java arrays Create method named repeatedN that takes two integer parameters named range and n and returns an integer array Method should return an integer array that has numbers 0 - range repeated in order n times If range is less than or equal to 0; return an array that has 0 repeated n times Create a second method named printArray that takes an integer array as a parameter. The method should print out every element on the same line...
I need assistance writing the following Java class. Design a class named Location for locating a maximal value and its location in a two-dimensional array. The class contains public data fields row, column, and maxValue that store the maximal value and its indices in a two-dimensional array with row and column as int types and maxValue as a double type. Write the following method that returns the location of the largest element in a two-dimensional array: public static Location locateLargest(double[][]...