ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 12 Weeks Ago, 5 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 28 Apr 2017 My Price 11.00

Create a Java program that reads 10 numbers from the console

Create a Java program that reads 10 numbers from the console (Scanner input = new Scanner(System.in);)

Store the numbers as Floats in the array.

Create static methods to perform the following actions on the array and returns the result.

  1. Add all the items in the array and return the result. Name this method "add"
  2. Subtract all the items in the array and return the result. Name this method "sub
  3. Multiply all the items in the array and return the result. Name this method "multiply"
  4. Divide all the items in the array and return the result. Name this method "divide"

 

 

Create a Java program that reads 10 numbers from the console
(Scanner input = new Scanner(System.in);)
Store the numbers as Floats in the array.
Create static methods to perform the following actions on the
array and returns the result.
1. Add all the items in the array and return the result. Name this method "add"
2. Subtract all the items in the array and return the result. Name
this method "sub
3. Multiply all the items in the array and return the result. Name
this method "multiply"
4. Divide all the items in the array and return the result. Name this
method "divide" import java.util.ArrayList;
import java.util.Random; public class Driver { public static void main(String args) { // Create an array variable
int arrayVar; // Current value is null // Instantiate the array
arrayVar = new int[10000]; // Fill the array with data from a random object
fillArray( arrayVar ); // Add an item to the array
arrayVar = addItemToArray( arrayVar ); // Remove an item from the array
arrayVar = removeItemFromArray( arrayVar ); printArray( arrayVar ); // Performance test between Arrays and ArrayLists
System.out.print( "\nrunning...");
long startTime = System.nanoTime();
for( int i = 0; i < 1000000; i++ ) {
addItemToArray( arrayVar );
}
long endTime = System.nanoTime();
System.out.println( "done"); System.out.println( ( endTime - startTime ) / 1000 / 1000 / 1000 + " seconds"); //
seconds (we hope) // Create an arraylist
ArrayList arrayList; // Instantiate an arraylist
arrayList = new ArrayList(); // Fill the arraylist
for( int i = 0; i < 10000; i++ ) {
arrayList.add(random.nextInt());
} // Test the performance by adding data
// Performance test between Arrays and ArrayLists System.out.print( "\nrunning..."); startTime = System.nanoTime();
for( int i = 0; i < 1000000; i++ ) {
arrayList.add(random.nextInt());
}
endTime = System.nanoTime();
System.out.println( "done"); System.out.println( ( endTime - startTime ) / 1000 / 1000 / 1000 + " seconds"); //
seconds (we hope) } private static int removeItemFromArray(int arrayVar) { int length = arrayVar.length;
int newArray = new int[length-1];
int newArrayLength = newArray.length; for( int i = 0; i < newArrayLength; i++ ) {
newArray[i] = arrayVar[i];
} return newArray;
} static Random random = new Random( 145646 ); private static int addItemToArray(int arrayVar) { // Efficient Way
/*
int newArray = new int[ arrayVar.length ];
for( int i = 0; i < arrayVar.length; i++ ) {
newArray[i] = arrayVar[i];
}
newArray[arrayVar.length] = random.nextInt();
return newArray;
*/ // This is the class way
int length = arrayVar.length; int newArray = new int[length+1]; for( int i = 0; i < length; i++ ) {
newArray[i] = arrayVar[i];
} newArray[newArray.length-1] = random.nextInt(); return newArray;
} private static void fillArray(int arrayVar) {
int length = arrayVar.length; Random random = new Random( 465454568 );
for( int i = 0; i < length; i++ ) {
arrayVar[i] = random.nextInt();
} } private static void printArray( int arrayVar ) {
int length = arrayVar.length;
for( int i = 0; i < length; i++ ) {
System.out.print( arrayVar[i] );
System.out.print(",");
} } }

Attachments:

Answers

(11)
Status NEW Posted 28 Apr 2017 07:04 AM My Price 11.00

-----------

Attachments

file 1493365900-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)