ArrayFun Project: Implementing Methods for Array Manipulation, Exams of Computer Science

A programming project for csc 127 where students are required to write methods for an arrayfun class to solve various array-related problems. The project involves developing and testing seven methods, including sumgreaterthan, numberofvowels, numberofpairs, stringslongerthan, howmany, sortofsort, and evensleft. Each method is described with an example input and output.

Typology: Exams

Pre 2010

Uploaded on 08/31/2009

koofers-user-m09-1
koofers-user-m09-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C Sc 127 A Programming 7: ArrayFun
Collaboration: Solo
Due: 10:00 pm , Thursday 6-Nov via WebCat
This project asks you to solve seven problems requiring arrays. You are asked to write seven methods in one
class named ArrayFun and a test method for each in a unit test named ArrayFunTest. Develop (code and test)
one method at a time.
1) public boolean sumGreaterThan(double[] array, double sum)
Given a filled array of double array elements, return true if the sum of all array elements is greater than sum.
sumGreaterThan( { 1.1, 2.2, 3.3 }, 4.0) true
sumGreaterThan( { 1.1, 2.2, 3.3 }, 6.6) false
2) public int numberOfVowels(char[] array)
Given a filled array of char array elements, return the number of vowels which could be the letters 'a' , 'e', 'i', 'o',
or 'u' in either upper case or lower case.
numberOfVowels({'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U', 'x', 'z'}) 10
numberOfVowels( {'y', 'Y' } ) 0
numberOfVowels( {'a', 'X', 'a' } ) 2
3) public int numberOfPairs(String[] array)
Return the number of times a pair occurs in array. A pair is any two String values that are equal (case sensitive)
in consecutive array elements.
numberOfPairs( {"a", "b", "c" } ) 0
numberOfPairs( {"b", "a", "a", "b"} ) 1
numberOfPairs( {"a", "a", "a"} ) 2
numberOfPairs( {"a", "a", "b", "b" } ) 2
4) public int stringsLongerThan(String[] array, int len)
Write a test method for stringsLongerThan that takes the array of Strings and returns the number of Strings
with a length greater than len.
stringsLongerThan({"a", "ab", "abc"}, 0) 3
stringsLongerThan({"a", "ab", "abc"}, 2) 1
stringsLongerThan({"a","ab","abc","abcd","abcde","abcdef", "abcdefg"}, 3) 4
5) public int howMany(String[] array, String valueToFind)
Complete method howMany to return the number of elements in an array of Strings that equals valueToFind.
howMany( { "A", "a", "A", "a" }, "A") 2
howMany( {"And", "there", "goes", "another"}, "another") 1
howMany( {"And", "there", "goes", "another"}, "Not Here") 0
pf2

Partial preview of the text

Download ArrayFun Project: Implementing Methods for Array Manipulation and more Exams Computer Science in PDF only on Docsity!

C Sc 127 A Programming 7: ArrayFun

Collaboration: Solo

Due: 10:00 pm , Thursday 6-Nov via WebCat

This project asks you to solve seven problems requiring arrays. You are asked to write seven methods in one

class named ArrayFun and a test method for each in a unit test named ArrayFunTest. Develop (code and test)

one method at a time.

1) public boolean sumGreaterThan(double[] array, double sum)

Given a filled array of double array elements, return true if the sum of all array elements is greater than sum.

sumGreaterThan( { 1.1, 2.2, 3.3 }, 4.0) true sumGreaterThan( { 1.1, 2.2, 3.3 }, 6.6) false

2) public int numberO f Vowels(char[] array)

Given a filled array of char array elements, return the number of vowels which could be the letters 'a' , 'e', 'i', 'o',

or 'u' in either upper case or lower case.

numberOfVowels({'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U', 'x', 'z'}) 10 numberOfVowels( {'y', 'Y' } ) 0 numberOfVowels( {'a', 'X', 'a' } ) 2

3) public int numberOfPairs(String[] array)

Return the number of times a pair occurs in array. A pair is any two String values that are equal (case sensitive)

in consecutive array elements.

numberOfPairs( {"a", "b", "c" } ) 0 numberOfPairs( {"b", "a", "a", "b"} ) 1 numberOfPairs( {"a", "a", "a"} ) 2 numberOfPairs( {"a", "a", "b", "b" } ) 2

4) public int stringsLongerThan(String[] array, int len)

Write a test method for stringsLongerThan that takes the array of Strings and returns the number of Strings

with a length greater than len.

stringsLongerThan({"a", "ab", "abc"}, 0) 3 stringsLongerThan({"a", "ab", "abc"}, 2) 1 stringsLongerThan({"a","ab","abc","abcd","abcde","abcdef", "abcdefg"}, 3) 4

5) public int howMany( String [] array, String valueToFind)

Complete method howMany to return the number of elements in an array of Strings that equals valueToFind.

howMany( { "A", "a", "A", "a" }, "A") 2 howMany( {"And", "there", "goes", "another"}, "another") 1 howMany( {"And", "there", "goes", "another"}, "Not Here") 0

6) public void sortOfSort( int [] array)

Write method sortOfSort that modifies the parameter array to place the largest integer at index n-1 and the

smallest integer at array[0]. The others elements must still be in the array, but not in any particular order. You

must modify the given array argument by changing array in method sortOfSort.

Original Array Modified Array { 4, 3, 2, 0, 1, 2 } { 0, 3, 2, 1, 2, 4 } { 4, 3, 2, 1 } { 1, 3, 2, 4 } { 1, 3, 2, 4 } { 1, 3, 2, 4 }

7) public void evensLeft( int [] array)

(A Nick Parlante Javabat problem) Modify the parameter array so it still contains the exact same numbers as

the given array, but rearranged so that all the even numbers come before all the odd numbers. Other than that,

the numbers can be in any order. You must modify the array arguments by changing array in method

evensLeft.

Original Array Modified Array {1, 0, 1, 0, 0, 1, 1 } { 0, 0, 0, 1, 1, 1, 1 } {3, 3, 2} { 2, 3, 3 } {2, 2, 2} { 2, 2, 2 }

Grading Criteria

___/ 80 Correctness and code coverage on WebCat (code coverage * correctness * 80 pts)

___/ 10 Grader Discretion

___ / +2 Included your name on both files

___ / +2 Include description of what the class does

___ / +2 Used meaningful identifiers for local variables (e.g. year instead of y)

___ / +2 Used consistent spacing/indentation (Eclipse Source > Format or Ctrl+Shift+S)

___ / +2 Otherwise good style and design