Skip to content

Commit f579368

Browse files
PayalModiPayalModi
PayalModi
authored and
PayalModi
committed
Done.
1 parent 5990be8 commit f579368

File tree

4 files changed

+180
-5
lines changed

4 files changed

+180
-5
lines changed
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<testsuite errors="0" failures="0" hostname="Payals-MacBook-Pro-2.local" name="com.flatironschool.javacs.MyArrayListTest" skipped="0" tests="19" time="0.07" timestamp="2016-03-20T20:03:56">
3+
<properties>
4+
<property name="java.vendor" value="Oracle Corporation" />
5+
<property name="sun.java.launcher" value="SUN_STANDARD" />
6+
<property name="env.XPC_SERVICE_NAME" value="0" />
7+
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers" />
8+
<property name="env._system_arch" value="x86_64" />
9+
<property name="env.GEM_HOME" value="/Users/payalmodi/.rvm/gems/ruby-2.3.0" />
10+
<property name="os.name" value="Mac OS X" />
11+
<property name="sun.boot.class.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/classes" />
12+
<property name="env.TMPDIR" value="/var/folders/c4/dd5g2kp16pj0c4s9yyxtqzww0000gp/T/" />
13+
<property name="env.PWD" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU" />
14+
<property name="env.LANG" value="en_US.UTF-8" />
15+
<property name="java.vm.specification.vendor" value="Oracle Corporation" />
16+
<property name="ant.home" value="/usr/local/Cellar/ant/1.9.6/libexec" />
17+
<property name="java.runtime.version" value="1.8.0_74-b02" />
18+
<property name="env.MY_RUBY_HOME" value="/Users/payalmodi/.rvm/rubies/ruby-2.3.0" />
19+
<property name="env.Apple_PubSub_Socket_Render" value="/private/tmp/com.apple.launchd.J7hHF0neyy/Render" />
20+
<property name="env.rvm_version" value="1.26.11 (latest)" />
21+
<property name="user.name" value="payalmodi" />
22+
<property name="env.USER" value="payalmodi" />
23+
<property name="env.SHELL" value="/bin/bash" />
24+
<property name="env.__CF_USER_TEXT_ENCODING" value="0x1F6:0x0:0x0" />
25+
<property name="env._system_type" value="Darwin" />
26+
<property name="env.PATH" value="/Users/payalmodi/.rvm/gems/ruby-2.3.0/bin:/Users/payalmodi/.rvm/gems/ruby-2.3.0@global/bin:/Users/payalmodi/.rvm/rubies/ruby-2.3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/payalmodi/.rvm/bin" />
27+
<property name="user.language" value="en" />
28+
<property name="env.rvm_prefix" value="/Users/payalmodi" />
29+
<property name="sun.boot.library.path" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib" />
30+
<property name="ant.project.default-target" value="build" />
31+
<property name="env.XPC_FLAGS" value="0x0" />
32+
<property name="ant.project.name" value="JavaCS" />
33+
<property name="env.rvm_path" value="/Users/payalmodi/.rvm" />
34+
<property name="env.RUBY_VERSION" value="ruby-2.3.0" />
35+
<property name="java.version" value="1.8.0_74" />
36+
<property name="user.timezone" value="" />
37+
<property name="sun.arch.data.model" value="64" />
38+
<property name="env._system_name" value="OSX" />
39+
<property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16" />
40+
<property name="java.endorsed.dirs" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/endorsed" />
41+
<property name="sun.cpu.isalist" value="" />
42+
<property name="sun.jnu.encoding" value="UTF-8" />
43+
<property name="env.rvm_bin_path" value="/Users/payalmodi/.rvm/bin" />
44+
<property name="file.encoding.pkg" value="sun.io" />
45+
<property name="env.SHLVL" value="3" />
46+
<property name="file.separator" value="/" />
47+
<property name="env._system_version" value="10.11" />
48+
<property name="java.specification.name" value="Java Platform API Specification" />
49+
<property name="java.class.version" value="52.0" />
50+
<property name="user.country" value="US" />
51+
<property name="ant.file.JavaCS" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/build.xml" />
52+
<property name="java.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre" />
53+
<property name="java.vm.info" value="mixed mode" />
54+
<property name="env.LOGNAME" value="payalmodi" />
55+
<property name="ant.file" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/build.xml" />
56+
<property name="os.version" value="10.11.3" />
57+
<property name="env.TERM_PROGRAM_VERSION" value="361.1" />
58+
<property name="path.separator" value=":" />
59+
<property name="java.vm.version" value="25.74-b02" />
60+
<property name="ant.library.dir" value="/usr/local/Cellar/ant/1.9.6/libexec/lib" />
61+
<property name="junit.output.dir" value="junit" />
62+
<property name="env.IRBRC" value="/Users/payalmodi/.rvm/rubies/ruby-2.3.0/.irbrc" />
63+
<property name="java.awt.printerjob" value="sun.lwawt.macosx.CPrinterJob" />
64+
<property name="env.TERM" value="xterm-256color" />
65+
<property name="sun.io.unicode.encoding" value="UnicodeBig" />
66+
<property name="awt.toolkit" value="sun.lwawt.macosx.LWCToolkit" />
67+
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16" />
68+
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16" />
69+
<property name="env.GEM_PATH" value="/Users/payalmodi/.rvm/gems/ruby-2.3.0:/Users/payalmodi/.rvm/gems/ruby-2.3.0@global" />
70+
<property name="user.home" value="/Users/payalmodi" />
71+
<property name="target" value="1.6" />
72+
<property name="java.specification.vendor" value="Oracle Corporation" />
73+
<property name="env.TERM_PROGRAM" value="Apple_Terminal" />
74+
<property name="java.vendor.url" value="http://java.oracle.com/" />
75+
<property name="java.library.path" value="/Users/payalmodi/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:." />
76+
<property name="gopherProxySet" value="false" />
77+
<property name="java.vm.vendor" value="Oracle Corporation" />
78+
<property name="java.runtime.name" value="Java(TM) SE Runtime Environment" />
79+
<property name="java.class.path" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/bin:/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/lib/junit-4.12.jar:/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/lib/hamcrest-core-1.3.jar:/usr/local/Cellar/ant/1.9.6/libexec/lib/ant-launcher.jar:/usr/local/Cellar/ant/1.9.6/libexec/lib/ant.jar:/usr/local/Cellar/ant/1.9.6/libexec/lib/ant-junit.jar:/usr/local/Cellar/ant/1.9.6/libexec/lib/ant-junit4.jar" />
80+
<property name="ant.version" value="Apache Ant(TM) version 1.9.6 compiled on June 29 2015" />
81+
<property name="sun.java.command" value="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner com.flatironschool.javacs.MyArrayListTest skipNonTests=false filtertrace=true haltOnError=false haltOnFailure=false formatter=org.apache.tools.ant.taskdefs.optional.junit.OutErrSummaryJUnitResultFormatter showoutput=false outputtoformatters=true logfailedtests=true threadid=0 logtestlistenerevents=false formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/junit/TEST-com.flatironschool.javacs.MyArrayListTest.xml formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter crashfile=/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/junitvmwatcher6897079354364505166.properties propsfile=/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02/junit6137024398022746698.properties" />
82+
<property name="env.TERM_SESSION_ID" value="93C02555-87F7-4991-B52C-4D5B6F35C9A1" />
83+
<property name="env.JAVA_MAIN_CLASS_71653" value="org.apache.tools.ant.launch.Launcher" />
84+
<property name="ant.file.type.JavaCS" value="file" />
85+
<property name="java.vm.specification.name" value="Java Virtual Machine Specification" />
86+
<property name="ant.file.type" value="file" />
87+
<property name="java.vm.specification.version" value="1.8" />
88+
<property name="sun.os.patch.level" value="unknown" />
89+
<property name="sun.cpu.endian" value="little" />
90+
<property name="env.HOME" value="/Users/payalmodi" />
91+
<property name="debuglevel" value="source,lines,vars" />
92+
<property name="java.io.tmpdir" value="/var/folders/c4/dd5g2kp16pj0c4s9yyxtqzww0000gp/T/" />
93+
<property name="java.vendor.url.bug" value="http://bugreport.sun.com/bugreport/" />
94+
<property name="env.SSH_AUTH_SOCK" value="/private/tmp/com.apple.launchd.Ijsf1gZ9oo/Listeners" />
95+
<property name="os.arch" value="x86_64" />
96+
<property name="java.awt.graphicsenv" value="sun.awt.CGraphicsEnvironment" />
97+
<property name="java.ext.dirs" value="/Users/payalmodi/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java" />
98+
<property name="user.dir" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU" />
99+
<property name="line.separator" value="&#xa;" />
100+
<property name="java.vm.name" value="Java HotSpot(TM) 64-Bit Server VM" />
101+
<property name="basedir" value="/Users/payalmodi/Documents/Other/CodeU/cs-implementing-an-arraylist-lab-codeU/javacs-lab02" />
102+
<property name="ant.java.version" value="1.8" />
103+
<property name="ant.core.lib" value="/usr/local/Cellar/ant/1.9.6/libexec/lib/ant.jar" />
104+
<property name="source" value="1.6" />
105+
<property name="file.encoding" value="UTF-8" />
106+
<property name="env.PKG_CONFIG_PATH" value="/opt/local/lib/pkgconfig:" />
107+
<property name="java.specification.version" value="1.8" />
108+
<property name="ant.project.invoked-targets" value="test" />
109+
</properties>
110+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testToArray" time="0.007" />
111+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testAddIntT" time="0.001" />
112+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testGet" time="0.0" />
113+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testSet" time="0.001" />
114+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testAddAllCollectionOfQextendsT" time="0.0" />
115+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testClear" time="0.0" />
116+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testAddT" time="0.001" />
117+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testSize" time="0.0" />
118+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testLastIndexOf" time="0.0" />
119+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testMyArrayList" time="0.0" />
120+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testContainsAll" time="0.0" />
121+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testRemoveObject" time="0.0" />
122+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testContains" time="0.001" />
123+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testIndexOf" time="0.0" />
124+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testIsEmpty" time="0.0" />
125+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testIterator" time="0.001" />
126+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testRemoveAll" time="0.0" />
127+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testRemoveInt" time="0.0" />
128+
<testcase classname="com.flatironschool.javacs.MyArrayListTest" name="testSubList" time="0.0" />
129+
<system-out><![CDATA[]]></system-out>
130+
<system-err><![CDATA[]]></system-err>
131+
</testsuite>

javacs-lab02/src/com/flatironschool/javacs/MyArrayList.java

+49-5
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,26 @@ public void add(int index, E element) {
6262
if (index < 0 || index > size) {
6363
throw new IndexOutOfBoundsException();
6464
}
65-
// TODO: fill in the rest of this method
66-
}
65+
66+
if (index == size) {
67+
add(element);
68+
return;
69+
}
70+
71+
//copy all elements to temp array
72+
E[] temp = (E[])new Object[array.length];
73+
for (int i = 0; i < size; i++) {
74+
temp[i] = array[i];
75+
}
76+
77+
int numElements = size-index;
78+
array[index] = element;
79+
size = index+1;
80+
81+
for (int i = index; i < index+numElements; i++) {
82+
add(temp[i]);
83+
}
84+
}
6785

6886
@Override
6987
public boolean addAll(Collection<? extends E> collection) {
@@ -112,7 +130,15 @@ public E get(int index) {
112130
@Override
113131
public int indexOf(Object target) {
114132
// TODO: fill in this method
115-
return 0;
133+
// if (target == null)
134+
// return null;
135+
136+
for (int i = 0; i < size; i++) {
137+
if (equals(target, get(i)))
138+
return i;
139+
}
140+
141+
return -1;
116142
}
117143

118144
/** Checks whether an element of the array is the target.
@@ -183,7 +209,20 @@ public boolean remove(Object obj) {
183209
@Override
184210
public E remove(int index) {
185211
// TODO: fill in this method.
186-
return null;
212+
if (index < 0 || index >= size) {
213+
throw new IndexOutOfBoundsException();
214+
}
215+
216+
E temp = array[index];
217+
218+
//shift left
219+
for (int i = index; i < size-1; i++) {
220+
array[i] = array[i+1];
221+
}
222+
array[size] = null;
223+
size--;
224+
225+
return temp;
187226
}
188227

189228
@Override
@@ -203,7 +242,12 @@ public boolean retainAll(Collection<?> collection) {
203242
@Override
204243
public E set(int index, E element) {
205244
// TODO: fill in this method.
206-
return null;
245+
if (index < 0 || index >= size) {
246+
throw new IndexOutOfBoundsException();
247+
}
248+
E temp = array[index];
249+
array[index] = element;
250+
return temp;
207251
}
208252

209253
@Override

0 commit comments

Comments
 (0)