Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

P 2 0 . 2 Program 1 : List Methods Objectives Create a user - defined Java class that performs various operations with 1 -

P
20.2 Program 1: List Methods
Objectives
Create a user-defined Java class that performs various operations with 1-dimensional arrays.
Use a static main method in a separate file to test the class methods.
Develop programs using an IDE.
Upload both the user-defined class and the driver class for grading.
Background Reading
ZyBooks: 5. Arrays, 6. Methods
Header comment section
Recall that each file you code should contain the following header information.
/**
* Program #
*1-2 Line Description of class/program
* CS160-Section#
* Date
* @author Student Name
*/
and the ID string method
The sole purpose of these methods is just as it says: to identify you as the author of the code. No matter what else is required in your program, the "no-arg" version of this method must also be included in all programs you write this semester.
getInfo() should return a string in the form of the following where your name is substituted for "Student Name".
Program #, Student Name
Instructions
You are to write an application ("application" is used here to mean "program") called ListMethods.java that does some useful things with arrays. In addition to the getInfo() method, your program should have the following methods.
public int findMin() that accepts a one-dimensional array as a parameter and returns the smallest value in the array. If the array is empty (size 0) it returns Integer.MIN_VALUE.
public int findMinIndex() that accepts a one-dimensional array as a parameter and returns the index of the smallest value in the array. If the array is empty (size 0) it returns -1.
public void reverse() that accepts a one-dimensional array as a parameter and reverses order of the array values. Hint: there are two approaches to this: (1) swap the array values--but stop half way or you'll swap them back to their original position, or (2) create a new array and copy the values into it in the reverse order from the original array, then copy the new reversed array back into the original array.
public boolean shiftUp() that accepts a one-dimensional array as a parameter and moves all values in the array from their current index to current index minus 1. Note that the value in position 0 is overwritten. The highest index is not overwritten (i.e., the value at array[array.length-1] will be duplicated in array[array..length-2]. The method should return true unless the array size is zero.
public boolean shiftDown() that accepts a one-dimensional array as a parameter and moves all values in the array from their current index to current index plus 1. Note that the value in array[array.length-1] is overwritten. The lowest index is not overwritten (i.e., the value at array[0] will be duplicated in array[1]. The method should return true unless the array size is zero.
Making a main method to test your stuff
The array methods do not have the word "static" in the method header. The way to access non-static methods from main (a static context) is to create an instance of our ListMethods class and call the methods using the object reference. Like this:
public static void main(String[] args){
ListMethods app = new ListMethods();
int[] testData ={67,43,1,9,44,12,66,91,18,17,4};
int min = app.findMin(testData);
System.out.println("Smallest value is "+ min);
// Add more calls to the other methods here, possibly using different arrays.
}20.2 Program 1: List Methods
Objectives
Create a user-defined Java class that performs various operations with 1-dimensional arrays.
Use a static main method in a separate file to test the class methods.
Develop programs using an IDE.
Upload both the user-defined class and the driver class for grading.
Background Reading
ZyBooks: 5. Arrays, 6. Methods
Header comment section
Recall that each file you code should contain the following header information.
/**
* Program #
*1-2 Line Description of class/program
* CS160-Section#
* Date
* @author Student Name
*/
and the ID string method
The sole purpose of these methods is just as it says: to identify you as the author of the code. No matter what else is required in your program, the "no-arg" version of this method must also be included in all programs you write this semester.
getInfo() should return a string in the form of the following where your name is substituted for "Student Name".
Program #, Student Name
Instructions
You are to write an application ("application" is used here to mean "program") called ListMethods.java that does some useful things with arrays. In addition to the getInfo() method, your program should have the following methods.
public int findMin() that accepts a one-dimensional array as a parameter and returns the smallest value in the array. If the array is empty (size 0) it returns Integer.MIN_VALUE.
public int findMinIndex() that accepts a one-dimensional array as a parameter and returns the index of the smallest value in the array. If the array is empty (size 0) it returns -1.
public void reverse() that accepts a one-dimensional array as a parameter and reverses order of the array values. Hint: there are two approaches to this: (1) swap the array values--but stop half way or you'll swap them back to their original position, or (2) create a new array and copy the values into it in the reverse order from the original array, then copy the new reversed array back into the original array.
public boolean shiftUp() that accepts a one-dimensional array as a parameter and moves all values in the array from their current index to current index minus 1. Note that the value in position 0 is overwritten. The highest index is not overwritten (i.e., the value at array[array.length-1] will be duplicated in array[array..length-2]. The method should return true unless the array size is zero.
public boolean shiftDown() that accepts a one-dimensional array as a parameter and moves all values in the array from their current index to current index plus 1. Note that the value in array[array.length-1] is overwritten. The lowest index is not overwritten (i.e., the value at array[0] will be duplicated in array[1]. The method should return true unless the array size is zero.
Making a main method to test your stuff
The array methods do not have the word "static" in the method header. The way to access non-static methods from main (a static context) is to create an instance of our ListMethods class and call the methods using the object reference. Like this:
public static void main(String[] args){
ListMethods app = new ListMethods();
int[] testData ={67,43,1,9,44,12,66,91,18,17,4};
int min = app.findMin(testData);
System.out.println("Smallest value is "+ min);
// Add more calls to the other methods here, possibly using different arrays.
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

why teacher are underpaid? and why sport athletes are overpaid?

Answered: 1 week ago