Sie sind auf Seite 1von 10

http://learn.unisa.edu.au/file.php/54125/assign1sp72011/workspace/ProgFun dAssign1/doc/unisa/util/MathImproved.

htmlskipnavbar_top Overview Package Class Use Tree Deprecated Index Help


PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes

DETAIL: FIELD | CONSTR | METHOD

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

Version: 2.0 Author: GStewartVonItzstein

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

private 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

Constructortocreateaintarraywiththeinitialcontentsofthearray. Parameters: valuesTheintegerarraytocopyintothecurrentarray.

MathImproved
public MathImproved(int size, int largest) int smallest,

Generatesaintarrayofrandomvaluesof"size"rangingfrom"smallest" to"largest" Parameters: sizenumberofelementsinintarray


smallestthesmallestvalueinthearray largestthelargestvalueinthearray

MethodDetail toString
public java.lang.String toString()

ReturnsthestringrepresentationoftheobjectThismethodiscomplete soyoucanseehowitgoestogether. Overrides: toStringinclassjava.lang.Object Returns: Stringrepresentation

append
public boolean append(int[] newElements) Difficulty 1/10 (if your clever)

Appendthenominatedarraytothecontentoftheobject. Parameters: newElementsTheelementstoappendtotheexistingcontentarray. Returns: Trueifsuccessfulfalseotherwise.

valueAt
public int valueAt(int location)

Getthecharacteratthespecifiedindex.Theindexisanintegervalue rangingfrom0to(length1),specifyingthepositionofthecharacterin thecharacterarray.Forexample,"w"hasanindexof6inside"Hello world."


Normally you would use exceptions to report error but in this case we are going to return 999999 in any case where the result will not make sense (e.g. index > than length) Difficulty 2/10

Parameters: locationTheindexofthecharacterrequired. Returns:

Thecharacteratthespecifiedindex.Return\0intheeventofanerror.

contains
public int contains(int valueToFind) Difficulty: 2/10

Checksifthecurrentobjectcontainsthenominatedvalue. Parameters: valueToFindThenominatedvaluetosearchfor. Returns: Thepositionofthelocatedvalueintheobject1otherwise.

deleteValueAt
public boolean deleteValueAt(int delPosition) Difficulty 1/10 (if your clever)

Deletethevalueatthenominatedposition.Indexedfrom1tolength. Parameters: delPositionThepositionofthecharactertodelete. Returns:

Returnstrueifsuccessfulfalseotherwise.

deleteSequence
public int deleteSequence(int start, int finish) Difficulty 5/10

Deletethesequencenominatedbytheindexparameters. Parameters: startThefirstpositiontostartthedeletion.


finishThefirstpositionafterthelastcharactertobedeleted.

Returns: Thestartpositionofthedeletionifsuccessful1otherwise.

increaseArray
private boolean increaseArray(int newSize)

Increasethecapacityofthearraytoaccommodateadifferentsize.This methodisaprivatemethod,tobeusedinternallywheneverthesizeofthe arrayrequiredisdifferentthanthecurrentarray.Thismethodwillnot alterthecontentsofthecurrentcontentarray.Thismethodresizesitto thenewsizespecified.Ifthenewsizeissmallerthanthecurrentsizeit willfail.


Difficulty 3/10

Parameters: newSizeThenewsizeofthearray. Returns: Trueifsuccessfulfalseifnot.

increaseArray
private int[] increaseArray(int newSize, int[] array)

Increasethecapacityofanyint[]arraytoaccommodateadifferentsize. Thismethodisaprivatemethod,tobeusedinternallywheneverthesize ofthearrayrequiredisdifferentthanthecurrentarray.Thismethodwill notalterthecontentsofthearray.Thismethodresizesittothenewsize specified.Ifthenewsizeissmallerthanthecurrentsizeitwillfail.


Difficulty 3/10

Parameters: newSizeThenewsizeofthearray. Returns: thearrayifsuccessful,nullifnot.

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

Findthelastinstanceofthevalueinthearray.Indexedfrom1tolength Parameters: valueThecharactertosearchfor. Returns: Theindexofthelastinstanceofthenominatedcharacter.1otherwise.

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)

Shrinkthecapacityofthearraytoaccommodateadifferentsizearray. Thismethodisaprivatemethod,tobeusedinternallywheneverthesize ofthearrayrequiredisdifferentthanthecurrentarray.Thismethodcan destroythecontentsofthecurrentcharacterarray.Thismethodresizesit tothenewsizespecified.Ifthenewsizeissmallerthanthecurrentsizeit willfail.


Difficulty 3/10

Parameters: newSizeThenewsizeofthearray Returns:

Trueifsuccessfulfalseifnot.

productOf
public int productOf()

Returntheanswertomultiplyingallvaluesinthearraytogether.Ifthe arrayisemptyitshouldreturn0.Difficulty3/10 Returns: theproductofallvaluesinthearray

sumOf
public int sumOf()

Returnthesumofallvaluesinthearray.Ifthearrayisemptyitshould return0.Difficulty3/10 Returns: thetotalofallvaluesinthearray.

addArrays
public void addArrays(int[]... arrayList)

Addallthearraysinthelisttotheexistingarray.Ifanewarrayislonger theinternalarraywillneedtobeenlarged.Difficult5/10 Parameters: arrayListlistofarraystoaddtotheinternalarray.

valuesNotInList
public int[] valuesNotInList(int[] listOfValues)

Returnsalistofallvaluesnotintheninternalcontentarraythatareinthe providedarray.Forexampleifyouhadcreatedyourclasswiththe followingints1,4,5,1,7andcalledthemethodwith3,4,5,9,11itwould returnanarraywith3,9,11.Difficulty10/10 Parameters: listOfValueslistofvaluestocheckagainst. Returns: alistofvaluesthatwerenotinthelistOfValues.Iftherearenoneonthe listitwillreturnanemptyarray.

printArray
private static void printArray(int[] values)

Testmethodtodumpanarraycontentssoyoucanseewhathas happened.Onlyusedfordebugging.

main

public static void main(java.lang.String[] argv)

Mainmethodforinternaltesting. Parameters: argvargumentsfromcommandline.

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

DETAIL: FIELD | CONSTR | METHOD

Das könnte Ihnen auch gefallen