Alright, thanks for all your help!
i look in forums for very long time before i ask something and i couldnt find much info about this topic, so to make it easier for everybody else in the future, here is my finished program.
the program was tested and it works great. ill let you know in a couple of weeks what my grade was
run:
1) 11
2) 82
3) 45
4) 46
5) 77
6) 5
7) 79
8) 11
9) 40
10) 90
11) 97
12) 56
13) 17
14) 27
15) 96
16) 44
17) 34
18) 50
19) 72
20) 27
21) 27
22) 43
23) 33
24) 20
25) 18
26) 22
27) 3
28) 42
29) 56
30) 23
31) 71
32) 94
33) 49
34) 3
35) 48
36) 14
37) 75
38) 54
39) 93
40) 61
41) 1
42) 14
43) 93
44) 35
45) 55
46) 7
47) 93
48) 94
49) 20
50) 43
51) 18
52) 23
53) 65
54) 96
55) 28
56) 95
57) 61
58) 9
59) 54
60) 66
61) 94
62) 81
63) 24
64) 8
65) 18
66) 65
67) 53
68) 77
69) 12
70) 58
71) 28
72) 99
73) 4
74) 27
75) 80
76) 41
77) 58
78) 31
79) 48
80) 92
81) 8
82) 3
83) 99
84) 1
85) 84
86) 60
87) 49
88) 41
89) 87
90) 82
91) 91
92) 2
93) 17
94) 31
95) 78
96) 56
97) 33
98) 70
99) 50
100) 18
Lowest number: 1
Highest number: 99
The sum of all the number is: 4783
The average of all the number is: 47.0
The Management Team would like to knowhow many data items are within One Standard Deviation.
45, 46, 44, 50, 43, 42, 49, 48, 43, 53, 41, 48, 49, 41, 50,
Numbers within one standard diviation: 15
How does this compare with a Normal Distribution?
For a normal distribution "68% of the scores" should be within one standard deviation
Porcentage of scores within one standard diviation %15
BUILD SUCCESSFUL (total time: 0 seconds)
package lab6;
public abstract class DataElement
{
public abstract boolean equals(DataElement otherElement);
public abstract int compareTo(DataElement otherElement);
public abstract void makeCopy(DataElement otherElement);
public abstract DataElement getCopy();
}
package lab6;
public class IntElement extends DataElement
{
private int num = 0;
public IntElement()
{
num = 0;
}
public IntElement(int x)
{
num = x;
}
public IntElement(IntElement otherElement)
{
num = otherElement.num;
}
public void setNum(int x)
{
num = x;
}
public int getNum()
{
return num;
}
@Override
public boolean equals(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
return(num == temp.num);
}
@Override
public int compareTo(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
if (num < temp.num)
return -1;
else
if (num > temp.num)
return 1;
else
return 0;
}
@Override
public void makeCopy(DataElement otherElement)
{
IntElement temp = (IntElement) otherElement;
num = temp.num;
}
@Override
public DataElement getCopy()
{
IntElement temp = new IntElement(num);
return temp;
}
@Override
public String toString()
{
return String.valueOf(num);
}
}
package lab6;
public abstract class ArrayList extends IntElement
{
protected int length;
protected int maxSize;
protected DataElement[] list;
public ArrayList()
{
maxSize = 100;
length = 0;
list = new DataElement[maxSize];
}
public ArrayList(int size)
{
if(size <= 0)
{
System.err.println("The array size must be positive. "
+ "Creating an array of size 100. ");
maxSize = 100;
}
else
{
maxSize = size;
}
length = 0;
list = new DataElement[maxSize];
}
public ArrayList(ArrayList otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;
list = new DataElement[maxSize];
for(int j = 0; j < length; j++)
list[j] = otherList.list[j].getCopy();
}
public boolean isEmpty()
{
return (length == 0);
}
public boolean isFull()
{
return (length == maxSize);
}
public int listSize()
{
return length;
}
public int maxListSize()
{
return maxSize;
}
public void print()
{
for(int i = 0; i < length; i++)
System.out.println(list[i] + " ");
System.out.println();
}
public boolean isItemAtEqual(int location, DataElement item)
{
return (list[location].equals(item));
}
public boolean insertAt(int location, DataElement insertItem)
{
boolean rc = true;
if(location < 0 || location >= maxSize)
{
System.err.println("The position of the item to "
+ "be inserted is out of range");
rc = false;
}
else
if(length >= maxSize)
{
System.err.println("Cannot insert in a full list.");
rc = false;
}
else
{
for(int i = length; i > location; i--)
list[i] = list[i - i];
list[location] = insertItem.getCopy();
length++;
}
return rc;
}
public boolean insertEnd(DataElement insertItem)
{
boolean rc = true;
if(length >= maxSize)
{
System.err.println("Cannot insert in a full list.");
rc = false;
}
else
{
list[length] = insertItem.getCopy();
length++;
}
return rc;
}
public boolean removeAt(int location)
{
boolean rc = true;
if(location < 0 || location >= length)
{
System.err.println("The location of the item to "
+ "be removed is out of range.");
rc = false;
}
else
{
for(int i = location; i < length - 1; i++)
list[i] = list[i + 1];
list[length - 1] = null;
length--;
}
return rc;
}
public DataElement retrieveAt(int location)
{
if(location < 0 || location >= length)
{
System.err.println("The location of the item to be "
+ "retrieved is out of range.");
return null;
}
else
return list[location].getCopy();
}
public boolean replaceAt(int location, DataElement repItem)
{
boolean rc = true;
if(location < 0 || location >= length)
{
System.err.println("The location of the item to "
+ "be replaced is out of range");
rc = false;
}
else
list[location].makeCopy(repItem);
return rc;
}
public void clearList()
{
for(int i = 0; i < length; i++)
list[i] = null;
length = 0;
System.gc();
}
public void copyList(ArrayList otherList)
{
if(this != otherList) //avoid self-copying
{
for(int j = 0; j < length; j++) //destroy this list
list[j] = null;
System.gc();
maxSize = otherList.maxSize;
length = otherList.length;
list = new DataElement[maxSize]; //create the array
for(int j = 0; j < length; j++) //copy otherList
list[j] = otherList.list[j].getCopy();
}
}
public abstract int seqSearch(DataElement searchItem);
public abstract boolean insert(DataElement insertItem);
public abstract void remove(DataElement removeItem);
public abstract boolean insertDup (DataElement InsertItem);
public abstract int getMin ();
public abstract int getMax ();
public abstract int getSum ();
public abstract double getAvg ();
public abstract double getDiviations ();
public abstract int within1StdDev (double getDiviations,double getAvg);
public abstract int CalcNormDistribution (double getDiviations, double getAvg);
}
package lab6;
public class UnsortedArrayList extends ArrayList
{
public UnsortedArrayList()
{
super();
}
public UnsortedArrayList(int size)
{
super(size);
list = new IntElement[size];
length = 0;
}
public UnsortedArrayList (UnsortedArrayList otherList)
{
super(otherList);
}
@Override
public int seqSearch(DataElement searchItem)
{
int loc;
for(loc = 0; loc < length; loc++)
if(list[loc].equals(searchItem))
return loc; //found
return -1;
}
@Override
public boolean insert(DataElement insertItem)
{
boolean rc = true;
if(length == 0)
list[length++] = insertItem.getCopy();
else
if(length == maxSize)
{
System.err.println("Cannot insert in a full list.");
rc = false;
}
else
{
rc = true;
list[length++] = insertItem.getCopy();
}
return rc;
}
@Override
public void remove(DataElement removeItem)
{
int loc;
if(length == 0)
System.err.println("Cannon delete from an empty list");
else
{
loc = seqSearch(removeItem);
if(loc != -1)
removeAt(loc);
else
System.out.println("The item to be deleted is "
+ "not in the list.");
}
}
@Override
public boolean removeAt(int location)
{
boolean rc = true;
if(location < 0 || location >= length)
rc = false;
else
{
for(int i = location; i < length - 1; i++)
list[i] = list[i + 1];
list[length - 1] = null;
length--;
}
return rc;
}
@Override
public boolean insertDup(DataElement insertItem)
{
boolean rc = true;
if(length == 0)
list[length++] = insertItem;
else
if(length == maxSize)
rc = false;
else
list[length++] = insertItem.getCopy();
return rc;
}
@Override
public int getMin()
{
int lowest = 100;
for(int i = 0; i<list.length-1; i++)
{
if(list[i].compareTo(list[i+1]) == -1)
{
IntElement temp = (IntElement)(list[i].getCopy());
if (temp.getNum() < lowest)
lowest = temp.getNum();
}
}
return lowest;
}
@Override
public int getMax()
{
int highest = 0;
for(int i = 0; i<list.length-1; i++)
{
if(list[i].compareTo(list[i+1]) == 1)
{
IntElement temp = (IntElement)(list[i].getCopy());
if (temp.getNum() > highest)
highest = temp.getNum();
}
}return highest;
}
@Override
public int getSum()
{
int sum = 0;
for(int i = 0; i<list.length; i++)
{
IntElement temp = (IntElement)(list[i].getCopy());
sum += temp.getNum();
}
return sum;
}
@Override
public double getAvg ()
{
int avg = 0;
for(int i = 0; i<list.length; i++)
{
IntElement temp = (IntElement)(list[i].getCopy());
avg += temp.getNum();
}
avg /= 100;
return avg;
}
@Override
public double getDiviations ()
{
double getStdDev = 0;
int i;
for( i=0; i<list.length; i++)
{
IntElement temp = (IntElement)(list[i].getCopy());
getStdDev += temp.getNum();
}
getStdDev = Math.sqrt( getStdDev / list.length) ;
return getStdDev;
}
@Override
public int within1StdDev (double getDiviations,double getAvg)
{
int i;
int within1StdDev = 0;
for (i=0; i <list.length ; i++)
{
IntElement temp = (IntElement)(list[i].getCopy());
if ((temp.getNum() > (getAvg - getDiviations)) && (temp.getNum() < (getAvg + getDiviations)) )
{
System.out.print (temp.getNum() + ", ");
within1StdDev++;
}
}
return within1StdDev;
}
@Override
public int CalcNormDistribution (double getDiviations, double getAvg)
{
System.out.println ("For a normal distribution \"68% of the scores\" should be within one standard deviation");
int calcNormDistribuion= 0;
int i;
int within1StdDev =0;
for (i=0; i <list.length; i++)
{
IntElement temp = (IntElement)(list[i].getCopy());
if ((temp.getNum() > (getAvg - getDiviations)) && ( temp.getNum() < (getAvg + getDiviations)) )
within1StdDev++;
calcNormDistribuion = ((within1StdDev * 100) / list.length);
}
return calcNormDistribuion;
}
}