Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Create a class named Module3 that allows users to enter data and perform various operations on the data and display the results. Submit the

Assignment

Create a class named Module3 that allows users to enter data and perform various operations on the data and display the results. Submit the source code (Module3.java). Your class will contain the following data members and methods (note that all data fields and methods are for objects not static excepting the main method):

Data fields:

A Scanner object named reader (your class will need to import the Scanner class)

An array of type int named data, initially sized to zero

Methods:

A main method that, in order: creates a new Module3 object, prints the text starting application to the console, and calls the getCommand method

A method named getCommand containing a loop that:

Prints a prompt to the console for the user to enter one of the following commands: input, display, filter, resize, or exit

Entering input will set data to be the array returned by calling the getInput method with data as an argument

Entering display will call the displayContents method with data as an argument

Entering filter will set data to be the array returned by calling the removeEvens method with data as an argument

Entering resize will set data to be the array returned by calling the resize method with data as an argument

Entering exit will end the program by calling System.exit(0)

After executing a users command, getCommand will prompt the user to enter a new command (i.e., getCommand contains a loop that repeats until the user exits the program)

A method named getInput that accepts as a parameter an array of type int and:

Prints a prompt to the console for the user to enter an integer value, accepts the input using Scanners nextInt() method, resizes the array to be one element larger (while retaining all existing elements in their existing indexes), and sets the arrays last index to the input value

Calls displayContents to display the entered values

Returns the new array

A method named displayContents that accepts as a parameter an array of type int and prints the arrays values in order on a single line, with values separated by commas

A method named removeEvens that accepts as a parameter an array of type int and:

Counts how many odd values the array contains and creates a new int array of that size

Copies the parameter arrays odd values into the new array (maintaining their sequence)

Calls displayContents with the new (filtered) array

Returns the new array

A method named resize that accepts as a parameter an array of type int and:

Prints a prompt to the console for the user to enter an integer value and accepts the input using Scanners nextInt() method, and creates a new int array of that size

Copies the contents of the parameter array into the new array (maintaining their indexes). If the parameter array is larger than the new array, not all will be copied.

Example: if the parameter has ten elements and the new array has size six, only its first six elements will be copied to the new array

Calls displayContents with the new (resized) array

Returns the new array

To avoid the tedium of entering array values by hand, you might also find it useful to temporarily create arrays in your code using contents in braces, which builds an array with the exact number of elements in the sequence you provide, such as:

Int[] x = {0, 1, 2, 3} or int[] y = {-1, -2, 0, -3, 5, 7, 13};

Additional Constraints

The program should be implemented as a single file holding the public class Module3.

Comments should be provided at the start of the class file (i.e., above the class definition) giving the class authors name and the date the program was finished.

No error-checking is required at this point you may assume users only enter valid input.

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

Students also viewed these Databases questions

Question

a. Do team members trust each other?

Answered: 1 week ago

Question

How do members envision the ideal team?

Answered: 1 week ago

Question

Has the team been empowered to prioritize the issues?

Answered: 1 week ago