Assignment 5 - Ten A
ay Methods
CSE 110 Principles of Programming with Java
Spring 2021
Due April 10th 2021, 11:59PM Arizona Time
1 Assignment Objectives & Requirements
1.1 Assignment Objectives
After completing this assignment the student should be able to:
• Declare and instantiate a
ays
• Access a
ay elements by index
• Use loops and decisions to manipulate a
ays and a
ay elements
• Write methods that manipulate a
ays
• Write methods that take a
ay arguments
• Write methods that return a
ay references
1.2 Assignment Requirements
For this assignment you are given the following file -
Assignment5.java (you must complete this file).
2 Problem Description and Given Information
Within the Assignment5.java file, you must define the following static methods. In the main() method, you may
write any code that wish to test the methods you have been asked to define.
1. Write a public static method named printA
ay(), that takes two arguments. The first argument is an A
ay
of int and the second argument is a String. The method should print out a list of the values in the a
ay, each
separated by the value of the second argument.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
printA
ay(myA
ay, ”,”) will print out 1,22,333,400,5005,0
printA
ay(myA
ay, ”-”) will print out XXXXXXXXXX
2. Write a public static method named getFirst(), that takes an A
ay of int as an argument and returns the
value of the first element of the a
ay.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
getFirst(myA
ay) will return 1
3. Write a public static method named getLast(), that takes an A
ay of int as an argument and returns the
value of the last element of the a
ay.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
getLast(myA
ay) will return 0
4. Write a public static method named getAllButFirst(), that takes an A
ay of int as an argument and and
creates and returns a new a
ay with all of the values in the argument a
ay except the first value.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
getAllButFirst(myA
ay) will return an a
ay of int with these values {22,333,400,5005,0}
1
5. Write a public static method named getIndexOfMin(), that takes an A
ay of int as an argument and returns
the index of the least value in the a
ay.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
getIndexOfMin(myA
ay) will return 5
6. Write a public static method named getIndexOfMax(), that takes an A
ay of int as an argument and
eturns the index of the maximum value in the a
ay.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
getIndexOfMax(myA
ay) will return 4
7. Write a public static method named swapByIndex(), that takes three arguments. The first argument is an
A
ay of int, and the second and third arguments are int indexes. This method will swap the values at the
two given index arguments in the a
ay and display the a
ay after the swap is complete.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
swapByIndex(myA
ay,0,5) will display {0, 22, 333, 400, 5005, 1};
8. Write a public static method named removeAtIndex(), that takes two arguments. The first argument is an
A
ay of int, and the second is an int index. This method creates and returns a new a
ay with all of the
values in the argument a
ay except the value at the argument index.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
emoveAtIndex(myA
ay,1) will return an a
ay containing {0, 333, 400, 5005, 1};
9. Write a public static method named insertAtIndex(), that takes three arguments. The first argument is an
A
ay of int, the second is an int index, and the third is an int value. This method creates and returns a new
a
ay with all of the values in the argument a
ay including the third argument value inserted at the second
argument index.
Example:
int myA
ay[ ] = {1, 22, 333, 400, 5005, 0};
insertAtIndex(myA
ay,1,12) will return an a
ay containing {0, 12, 22, 333, 400, 5005, 1};
10. Write a public static method named isSorted(), that takes an A
ay of int as an argument. This method
should return the boolean value true if all the element values in the a
ay are in ascending order; otherwise
the method should return the boolean value false.
Example:
int myA
ay[ ] = { 22, 323433, 400, 524005, 0};
isSorted(myA
ay) will print out false
3 Method Template
Here is a template that you may use or refer to when defining your methods. All of your five methods will follow
this template; you must provide the components designated by the angle
ackets ¡ ¿.
static < returnType
methodName > (< parameters >)
{
methodBody
}
2
4 To Do
After reading the problem description, you may follow the given steps to starting your assignment -
1. Create a new project in your IDE called Assignment5
2. Create a new source file called Assignment5.java inside the project
3. Copy the contents of the source file provided for this assignment into the one created by you
4. Follow the comment sections along with the requirements listed in section 2 to complete your code
5. Compile and run your program to check for e
ors
6. Make sure you submit your source code file Assignment5.java to the submission link by the deadline
5 Submission Guidelines
Please follow the guidelines listed below prior to submitting your source code file Assignment5.java on Canvas -
1. Make sure that your source code file is named Assignment5.java prior to submitting.
2. Make sure that your input and output matches the format shown in section 2
3. Make sure that you have completed the comment section at the top of the source code file
4. Submit your Assignment5.java file only to the Canvas link for Assignment 5 by April 10th 2021, 11:59PM
Arizona Time.
6 Grading Ru
ic
Criteria Points
All required files are submitted 10
Each file includes the comment head section completed.
Code is neat and well organized 10
Good naming conventions for all identifiers
Good use of whitespace
Descriptive comments
Partial credit can be awarded
Code compiles with no syntax e
ors 20
No Partial credit can be awarded
No credit will be awarded for structure or logic if your code does not compile
Code passes structure tests 30
Code outputs results
Code passes logic tests 30
Partial credit is awarded based on number of tests passed
No credit will be awarded for logic if your code does not pass all structure tests
TOTAL 100
3
Assignment Objectives & Requirements
Assignment Objectives
Assignment Requirements
Problem Description and Given Information
Method Template
To Do
Submission Guidelines
Grading Ru
ic