Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Specifications 1. If using Eclipse, create a Java project called CS1450 2. Create a Java class (File->New->Class) within that project called LastNameFirstNameAssignment1 a. Please use

image text in transcribedimage text in transcribed

Specifications 1. If using Eclipse, create a Java project called CS1450 2. Create a Java class (File->New->Class) within that project called LastNameFirstNameAssignment1 a. Please use this naming convention. b. For example, for name Bill Smith the name of the file would be Smith BillAssignment1 3. Follow "CS1450 Programming Assignments Policy" 4. See the Canvas document Review: Files for help with files. 5. See the Canvas document Design Notebook Example for help with creating the design notebook. 6. For this assignment, all code can be in main() that is methods and classes are not required. Task 1: perform the following file-based tasks: a. In your code create a file named assignment1.txt. i. Correct: File fileName = new File("assignment1.txt"); i. Do not include any path names when creating the file. ii. The file will be placed in your current working directory. ii. Incorrect: File fileName = new File("C:/Dev/assignment1.txt"); b. Open the file for writing. c. Generate 25 random integers between 1 and 100. d. Write each value to the file, one value on each line. e. Display each value on the console as it is written to the file. f. Close the file. Task 2: perform the following array processing tasks: a. Reopen the file for reading. b. Read each value from the file and place into an array. Display each value AFTER it is placed into the array (i.e. access value from array to display). C. d. Find and display the largest two distinct numbers in the array. a. It is possible for the array to contain duplicates ch causes 1st largest = 2nd largest. b. Skip duplicates for 2nd largest! See tips section for details. a. e. Sort the array into descending order (largest to smallest). When performing this sort: You can use the sort method in the Arrays class b. You cannot use the reverse Order method on the Collections class c. You must manually sort the values into descending order. d. Manually sorting means you must write the code that does the sorting without using any methods other than Arrays.sort() f. Display the updated array after manually sorting into descending order. Must Do and Tips Must Do You must use an array, not an array list. You must write the code to manually sort the array. You may use Arrays.sort method but all other code must be manual array manipulation. . Must Not Do Do not include path names for the file. Use only assignment1.txt Do not use Collections.reverse Order method to sort array into descending order . Tips . O In the output below, 100 is the largest number and it was generated three times. Ignore duplicates when looking for 2nd largest value. 1st largest = 100, skip the duplicate, 2nd largest = 97. Use a temporary array to help you sort the values in the original array into descending order. The assignment1.txt file will be overwritten each time your code is run. o Output Your output will look like the following except with different random numbers. Largest value is 100 It was generated three times! When finding and largest, don't count the duplicate as 2nd largest, skip it Output - Example Generating random values and writing to a file Writing to file: 75 Writing to file: 12 Writing to file: 68 Writing to file: 45 Writing to file: 86 Writing to file: 5 Writing to file: 19 Writing to file: 5 Writing to file: 32 Writing to file: 6 Writing to file: 100 Writing to file: 54 Writing to file: 71 Writing to file: 87 Writing to file: 97 Writing to file: 11 Writing to file: 100 Writing to file: 96 Writing to file: 85 Writing to file: 25 Writing to file: 33 Writing to file: 27 Writing to file: 45 Writing to file: 68

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions