Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java please Assignment Description Arrays were the first data structure introduced in your beginning Java class and knowing how to manipulate arrays is an

in java please image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Assignment Description Arrays were the first data structure introduced in your beginning Java class and knowing how to manipulate arrays is an important skill. We'll review arrays by filling an array with random values and then performing a few operations on the array. You may also have learned to use files which is another important skill we will use throughout the semester. To review files (or learn for the first time), we will perform a simple writing to and reading from a file. Specifications 1. If using Eclipse, create a Java project called CS1450 a. File -> New -> Java Project 2. Create a Java class (File->New-Class) within that project called LastName FirstNameAssignment1 a. Please use this naming convention on all assignments. b. For example, I would name my file Gonzalez Mickey Assignment 3. The following modules on Canvas contain several helpful documents: a. Review: Object Oriented Programming and File for help with files. b. Programming Assignments Policy for help with assignment requirements. c. Design Notebook for help with design notebook and an example for this assignment. 4. For this assignment, all code can be in main() - that is - methods and classes are not required. Task 1: perform the following array processing tasks: a. Generate and display two random numbers - sizel and size2 - between 1 and 10. i. The values sizel and size2 will be used in step 2 as the size of each array, b. Generate sizel random integers between 1 and 25 and write them to the l' array c. Generate size2 random integers between 1 and 25 and write them to the 2 array d. Sort each array using the sort method in the Arrays class e. After each array is sorted, display the values in each array Task 2: perform the following file and array-based tasks: a. In your code create a file named assignment1.txt. i. Correct: File fileName = new File("assignment 1.txt"); i. Do not include any path names when creating the file. ii. The file will be placed in your current warlic directory ii. The file will be placed in your current working directory. ii. Incorrect: File fileName = new File("C:/Dev/assignment.txt"); b. Open the file for writing. i. Print Writer results File = new Print Writer (fileName); c. Write the values in the two arrays in sorted order to the file. i. See the output below where it shows Writing values to file for an example. ii. Display each value as you write it to the file d. Close the file. Task 3: perform the following file and array-based tasks: a. Reopen the file for reading. i. Scanner readFile new Scanner (fileName): b. Read values from file and place into an array, removing duplicates as you read the values. c. Display the array containing the sorted list of values without duplicates. Must Do and Tips Must Do You must use an array, not an array list. Must Not Do Do not include path names for the file. Use only the name assignmentl.txt o File fileName = new File("assignment.txt"); To create the file of sorted values, DO NOT move the values in the two arrays into another array, sort, then write to the file. That process requires little array manipulation. . Instead, you must write code that walks through the arrays and writes one value at a time to the file - that is - manually combine the array values into the file. This process requires you to perform array manipulation. o See the tips below for one way to write this code. Tips The assignment 1.txt file will be overwritten cach time your code is run. Merging the two arrays manually into the file requires two steps: Merging the two arrays manually into the file requires two steps: Step 1: write a while loop to take values from the arrays in sorted order and write them to the file. . This while loop completes when all values in one of the arrays have been written to the file. . Since the array sizes are randomly created, in most cases the arrays will be different sizes. This means, in most cases, one array will have all it values written to the file while the other array still contains values that need to be written to the file. o Step 2: after the above while loop completes, determine which array still contains values and write those remaining values to the file. while (more values in Arrayl to write to file) // Write remaining values in arrayl to file while (more values in Array2 to write to file) { // Write remaining values in array2 to file Output Your output should look like the following except with different random numbers. Output - Example sizel = 4 size2 - 3 First array with 4 sorted random values Output Your output should look like the following except with different random numbers. Output - Example sizel = 4 size2 = 3 First array with 4 sorted random values Second array with 3 sorted random values 12 25 Writing values to the file Note: When writing the file, they are written in Writing: 7 Writing: 8 values to the Writing: 10 sorted order. Writing: 12 Writing: 12 from the file and placed Writing: 24 array, 12 shows up once. Writing: 25 When the values are read into a new no-duplicates Array with no duplicate values

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

Write a Python program to check an input number is prime or not.

Answered: 1 week ago

Question

explain what is meant by experiential learning

Answered: 1 week ago

Question

identify the main ways in which you learn

Answered: 1 week ago