Consider the following problems, design and submit the algorithm, along with the source code, and snapshots of the running programs.
Problem 1:
Write a program that initializes an array with ten random integers and then prints out the following:
- Every element at an even index;
- Every even element
- All elements in reverse order;
- Only the first and last elements;
- The minimum and maximum element
- The sum of all elements
- The alternating sum of all elements, where the alternating sum contains all elements at even index added, and the elements at odd index subtracted.
Problem 2:
Write a program that reads a sequence of input values and displays a bar chart of the values in data, using asterisks, like this:
*********************
*************************
*********
**************************
You may assume that all values are positive. First figure out the maximum value in data. That value's bar should be drawn with 40 asterisks. Shorter bars should use proportionally fewer asterisks. Improve your program by adding caption to your bar. Prompt the user for the captions and data values. The output should look like this:
Egypt *********************
France *************************
Norway *********
Germany **************************
Problem 3:
Design and implement an application that reads a sequence of up to 25 pairs of names and postal (ZIP) codes for individuals. Store the data in an object designed to store a first name (string), last name (string), and postal code (integer). Assume each line of input will contain two strings followed by an integer value, each separated by a tab character. Then, after the input has been read in, print the list in an appropriate format to the screen.
Problem 4:
A theater seating chart is implemented as a two-dimensional array of ticket prices like presented below. Write a program that prompts the users to pick either a seat or a price. Mark sold seats by changing the price to zero. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price. Verify that the price is among those offered by the theater.
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
10 10 20 20 20 20 20 20 10 10
20 20 30 30 40 40 30 30 20 20
20 30 30 40 50 50 40 30 30 20
30 40 50 50 50 50 50 50 40 30
Problem 5: 2D Array Operations
Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods:
- getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.
- getAverage. This method should accept a two-dimensional array as its argument and return the average of all the values in the array.
- getRowTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the total of the values in the specified row.
- getColumnTotal. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a column in the array. The method should return the total of the values in the specified column.
- getHighestInRow. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the highest value in the specified row of the array.
- getLowestInRow. This method should accept a two-dimensional array as its first argument and an integer as its second argument. The second argument should be the subscript of a row in the array. The method should return the lowest value in the specified row of the array.
Demonstrate each of the methods in this program.
Submission
You are required to submit the following files for this assignment by clicking the Submit Assignment button above.
- You should create one Java file for each problem and save them all in one folder. Compress the folder as a .zip file and submit it here. Please name your .zip file as P8-Last Name-First Nam.zip. For example, P8-Smith-John.zip.
- A Word document containing the algorithms and the screenshots of the running programs for all of the five problems. Please name your Word document as P8-Last Name-First Name.docx or .doc. For example, P8-Smith-John.docx.