Assign 1
Assign 1
unisa.util
Class MathImproved
java.lang.Object unisa.util.MathImproved
public class MathImproved extends java.lang.Object This class represents a math array and provide functionalities need to do basic processing. It contains an array of integers, representing a list of values. Overview You are to create a class that stores a list of integers and allows you to carry out tasks on that list. Your mission is to create a Class with some clever features. You will also need to ensure that your program is bug free. Your Class should be uncrashable as possible. If your code detects faulty/incorrect input it should handle it as instructed in this java API Data Structure To make your life easier you will be provided with an API specification (just like the JavaDocs you use for your programming). You must use an array to store your values in your Class. You are not permitted to use any other Classes/Methods unless otherwise listed in this assignment. You will need to implement the entire class based on the API specification. This class will encapsulate all the functionality required. Testing A test program is also provided for you to use. Please read it carefully as you will be expected to generate your own in assignment 2. Use the test driver as a starting point to test your Class as thoroughly as possible. Note that the marker reserves the right to test more conditions if they think of them. How to Do The Assignment I suggest you do your assignment in the following order CreateallthemethodsignaturesintheClass.Eachmethodshouldjustbe
blank(withareturnnullor1ifnecessary). Compileandmakesurethattheprogramworks(well,technicallyitwon't becausethemethodsareempty,butmakesureitcompileswithnoerror). Writetheconstructors.Test. Writethelengthmethod.Test. WritethevalueAtmethod.Test. WritethelastIndexOfmethod.Test. WritetheincreaseArraymethods.Test(notethereisnoprovidedtestyou willneedtodoit). WritetheshrinkArraymethod.Test(notethereisnoprovidedtestyou willneedtodoit). Writethecontainsmethod.Test.
Writetheinsertmethod.Test. Writetheappendmethod.Test. WritethedeleteValueAtmethod.Test. WritethedeleteSequencemethod.Test. WritetheproductOfmethod.Test. WritethesumOfmethod.Test. WritetheaddArraysmethod.Test. WritethevaluesNotInListmethod.Test. Note that when you add functionality you may have to add test scenarios to other test methods to ensure you have covered all the possibilities. Additional Requirement. In addition to what is above there are a number of requirements for this assignment. Most of these are to introduce interesting problems for you to solve and must be obeyed. Asyouareprogrammingyouwillalsoneedtocommentyourcode
thoroughlyineachofyourmethods. Thearrayinyourstructuremustalwayshaveonlythespacethatis required. Youarenotpermittedtouseanymethods/classesfromtheJavaAPIin thisclassunlessspecificallyallowed.Ifyouuseamethodyouwillgetzero fortheoffendingmethod. ListofallowedJavaAPImethods. AnymethodintheRandomclass ArrayLengthMethod 25%ofthisassignmentisbasedonstyle.Thingstolookforonstyle. Omittingbracesonsinglelineblocks(egforwithout{}) InsufficientCommenting Commentingattheendoflines Indentingscrewedup(youcanfixindentingineclipsewithakeystroke) Strange/vaguevariablenames Methoddefinitionstoolong
How We Will Mark Your Assignment. WewillrunjavadoconyourcodetoseeifyourcodegeneratestheAPI
correctly.
Wewillreadyourcodetolookforstyleandcommentingproblems. Wewillusethetestdrivertotestyourtestingcode. Marking Scheme 75 Percent for it working totally correct (eg no issues with the testing system) 25 Percent for commenting/style of code etc... Hint: Many of the more complicated methods can use the easier methods to do part of their job. For instance if you have a method to delete some value you can use contains and delete (by index) together to achieve your aim. Date 20111201
FieldSummary
(package private) int[]
content Thestoragefortheintegersintheclass.
ConstructorSummary
MathImproved() Constructortocreateaintarraywiththeinitialcontentsofnothing. MathImproved(int[] values) Constructortocreateaintarraywiththeinitialcontentsofthearray. MathImproved(int size, int smallest, int largest) Generatesaintarrayofrandomvaluesof"size"rangingfrom"smallest" to"largest"
MethodSummary
void
addArrays(int[]... arrayList) Addallthearraysinthelisttotheexistingarray. append(int[] newElements) Appendthenominatedarraytothecontentofthe object. contains(int valueToFind) Checksifthecurrentobjectcontainsthenominated value. deleteSequence(int start, int finish) Deletethesequencenominatedbytheindex parameters. deleteValueAt(int delPosition) Deletethevalueatthenominatedposition. increaseArray(int newSize) Increasethecapacityofthearraytoaccommodatea differentsize.
boolean
int
int
boolean
private
boolean
private
int[]
increaseArray(int newSize, int[] array) Increasethecapacityofanyint[]arrayto accommodateadifferentsize. insert(int[] insertionValueArray, int index) Insertthenominatedintarrayattheindex. lastIndexOf(int value) Findthelastinstanceofthevalueinthearray. length() Returnsthelengthofthearray. main(java.lang.String[] argv) Mainmethodforinternaltesting. printArray(int[] values) Testmethodtodumpanarraycontentssoyoucansee whathashappened. productOf() Returntheanswertomultiplyingallvaluesinthe arraytogether. shrinkArray(int newSize) Shrinkthecapacityofthearraytoaccommodatea differentsizearray. sumOf() Returnthesumofallvaluesinthearray. toString() ReturnsthestringrepresentationoftheobjectThis methodiscompletesoyoucanseehowitgoestogether. valueAt(int location) Getthecharacteratthespecifiedindex. valuesNotInList(int[] listOfValues) Returnsalistofallvaluesnotintheninternalcontent arraythatareintheprovidedarray.
boolean
int
int
static void
int
private
boolean
int
java.lang.String
int
int[]
Methodsinheritedfromclassjava.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
FieldDetail content
int[] content
Thestoragefortheintegersintheclass.
ConstructorDetail MathImproved
public MathImproved() Difficulty 1/10
Constructortocreateaintarraywiththeinitialcontentsofnothing.
MathImproved
public MathImproved(int[] values) Difficulty 1/10
MathImproved
public MathImproved(int size, int largest) int smallest,
MethodDetail toString
public java.lang.String toString()
append
public boolean append(int[] newElements) Difficulty 1/10 (if your clever)
valueAt
public int valueAt(int location)
Thecharacteratthespecifiedindex.Return\0intheeventofanerror.
contains
public int contains(int valueToFind) Difficulty: 2/10
deleteValueAt
public boolean deleteValueAt(int delPosition) Difficulty 1/10 (if your clever)
Returnstrueifsuccessfulfalseotherwise.
deleteSequence
public int deleteSequence(int start, int finish) Difficulty 5/10
Returns: Thestartpositionofthedeletionifsuccessful1otherwise.
increaseArray
private boolean increaseArray(int newSize)
increaseArray
private int[] increaseArray(int newSize, int[] array)
insert
public boolean insert(int[] insertionValueArray, int index)
Insertthenominatedintarrayattheindex.
Difficulty 7/10
Parameters:
insertionValueArrayThearrayofvaluestoinsertintotheobject. indexThepositiontoinsertat.
Returns: Trueifsuccessfulfalseotherwise.
lastIndexOf
public int lastIndexOf(int value) Difficulty 3/10
length
public int length()
Returnsthelengthofthearray.Thelengthofthearrayisthenumberof values,inthearray.Forexample,"1,2,3,4,5"hasalengthof5.
Difficulty: 1/10
Returns: Thelengthoftheobjectsarray.
shrinkArray
private boolean shrinkArray(int newSize)
Trueifsuccessfulfalseifnot.
productOf
public int productOf()
sumOf
public int sumOf()
addArrays
public void addArrays(int[]... arrayList)
valuesNotInList
public int[] valuesNotInList(int[] listOfValues)
printArray
private static void printArray(int[] values)
Testmethodtodumpanarraycontentssoyoucanseewhathas happened.Onlyusedfordebugging.
main
http://learn.unisa.edu.au/file.php/54125/assign1sp72011/workspace/ProgFun dAssign1/doc/unisa/util/MathImproved.htmlskipnavbar_bottom Overview Package Class Use Tree Deprecated Index Help
PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes