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: 103 Weeks Ago, 3 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 02 May 2017 My Price 11.00

Create a new file (name it EnhancedArray.java)

Please provide a solution to document 4 in java, I've attached the work i've done so far.

 

 

Part A
1. Create a new file (name it EnhancedArray.java) and add an empty class called
EnhancedArray.
2. In the EnhancedArray class define the following attributes.
a. An array variable of type double, call it myarray
b. An integer variable called currentSize, and initialize it to zero.
3. In the EnhancedArray class create a static method with the following
definition
public static EnhancedArray EnhancedArrayFactory(int size)
The method should do the following:
I. create a new EnhancedArray object using the new operator and store
it in a temporary variable called temp.
II. create a new array of type double and size ‘size’, and assign its
reference to the array variable temp.myarray
III. Initialize the variable temp.currentSize to the value 0.
IV. Return a reference to the newly created object (i.e. the EnhancedArray
object temp)
4. Create an instance method in the class EnhancedArray with the follow
definition
public void fillArrayLinearAscending()
The method should initialize the array myarray (which is an attribute variable
of the class EnhancedArray) to values from 1 up to the size of the array. For
example myarray [0]= 1, myarray [1] = 2, myarray[2] = 3, and so on.
5. Create an instance method in the class EnhancedArray with the following
definition
public void print()
The method should print all the element in the array myarray (see previous
assignment)
6. Create an instance method in the class EnhancedArray with the follow
definition
public double sum ()
The method should add all elements in the array myarray and return its total.
7. Create an instance method in the class EnhancedArray with the follow
definition
public double average ()
The method should calculate the average of all elements in the array myarray
and return the result. 8. Create an instance method in the class EnhancedArray with the follow
definition
public double max ()
The method should find the maximum value in the array and return its value.
9. Create an instance method in the class EnhancedArray with the follow
definition
public double maxIndex ()
The method should find the maximum value in the array and return the index
to the cell which this value is found.
10. public double min ()
The method should find the minimum value in the array and return its value.
11. Create an instance method in the class EnhancedArray with the follow
definition
public double minIndex ()
The method should find the minimum value in the array and return the index
to the cell which this value is found.
12. Create an instance method in the class EnhancedArray with the follow
definition
public int find(doube key)
This method should search the array myarray and return the array index
where the value ‘key’ is found in the array. If the value key is not in the array,
then the method should return the value-1
13. Create an instance method in the class EnhancedArray with the follow
definition
public void addNext (doube newvalue)
This method should add the value ‘newvalue’ in the next available spot in the
array myarray. For example, myarray[currentIndex] = newvalue. Don’t forget
to update the currentIndex variable to reflect this change.
14. Create an instance method in the class EnhancedArray with the follow
definition
public void addAt (int index, double newvalue)
This method should add the value ‘newvalue’ in myarray[index]. Make sure
that you first shift all element from position index to the end of the array by
one position. (See lecture notes) 15. Create an instance method in the class EnhancedArray with the follow
definition
public void remove (int index)
This method should remove the value at cell index of myarray. Make sure
that you keep the relative order of the remaining element intact. (See lecture
notes)
16. Create an instance method in the class EnhancedArray with the follow
definition
public void expand ()
This method should create a new temporary array which is twice the current
size of array myarray. Then, the method should copy all element from
myarray to this new array. Finally, the method should assign the reference of
the new array to the variable myarray (See lecture notes) Part B.
17. Create a second file, EnhancedArrayTester.java and define a empty main
method.
18. In the main method of EnhancedArrayTester.java define a new variable of
type EnhancedArray, and name it rosterGrades. Then call the static
method EnhancedArrayFactory to obtain a reference to a new
EnhancedArray Object. Specify the initial size of the array to be 5 (see
example code).
19. Use the instance methods of the rosterGrades variable to perform the
following.
20. Add the values 10,20,30 to rosterGrades. Print rosterGrades.
21. Add the value 15 between the values of 10 and 20. Print rosterGrades..
22. Add the value 100 before the value 10, Print rosterGrades.
23. Add the value 200 after the value 30. Print rosterGrades. What happens?
24. Calculate the sum of all element in the array and print the result.
25. Calculate the average of all element in the array and print the result
26. Find the maximum value in the array, print the result.
27. Find the minimum value in the array, print the result.
28. Expand the rosterGrades enhancedArray, Print rosterGrades.
29. Add the value 200 after the value 30. Print rosterGrades.
30. Find if the value 100 is in the array.
31. Remove the value 100 from rosterGraders. Print rosterGrades.
32. Remove the value 200 from the array. Print rosterGrades.
33. Remove the value 15 from the array. Print roster
34. Expand the rosterGrades enhanced array again, print
35. Use the fillArrayLinearAscending method to fill in the rosterGrades
enhancnedArray.
36. Print the rosterGraders Array. 37.
38.
39.
40. Expand the rosterGrades enahced array again, print.
Add the value 1400,2 300 to the rosterGrades enhancedArray, then print.
Remove the maximum value from rosterGrades enhancedArray, then print.
Remove the minimum value from rosterGrades enhancedArray, then print.

public class EnhancedArray {
//
//
// private attribues for the class double myarray;
int currentSize = 0; //
// Factory method for creating arrays
public static EnhancedArray EnhancedArrayFactory(int size) {
EnhancedArray temp = new EnhancedArray();
temp.myarray = new double[size];
temp.currentSize = 0;
return temp;
} values /**
* The method should initialize the array myarray
* (which is an attribute variable of the class EnhancedArray) to * from 1 up to the size of the array. For example myarray [0]= 1,
myarray [1] = 2, myarray[2] = 3, and so on.
*/
public void fillArrayLinearAscending() {
int values = new int[11];
for (int i = 0; i < values.length; i++) {
values[i] = i * i; }
}
public void print(){
System.out.println(myarray);
}
public void sum(){
double total = 0;
for (int i = 0; i < myarray.length; i++){
total = total + myarray[i];
}
}
public double average() {
double average = 0, total = 0;
if (myarray.length > 0) {
average = total / myarray.length; }
return average;
}
public double max(){
double largest = myarray[0];
for (int i = 1; i < myarray.length; i++) {
if (myarray[i] > largest) {
largest = myarray[i]; }

public class EnhancedArrayTester {
public static void main(String args) {
EnhancedArray rosterGrades = EnhancedArray.EnhancedArrayFactory(10);
}
}

Attachments:

Answers

(11)
Status NEW Posted 02 May 2017 02:05 AM My Price 11.00

-----------

Attachments

file 1493691293-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)