Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Description Arrays were the first data structure introduced in your beginning Java class and understanding how to manipulate arrays is an important skill. Let's

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Assignment Description Arrays were the first data structure introduced in your beginning Java class and understanding how to manipulate arrays is an important skill. Let's 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), you will perform a simple writing to and reading from a file. Specifications You are free to use any IDE. If you want to use Eclipse and haven't already setup Eclipse up, please see the document in Canvas in the Assignments module under Eclipse Environment Setup. - Open the document named Environment Setup.docx - Follow the steps in the document to setup your development environment. - After environment setup, you will be at section Creating a Java Program in Eclipse around p.14. - Read the details in the Creating a Java Program in Eclipse section when doing \#1 and \#2 below 1. Create a Java project called cs1450 a. File New Java Project b. This project is created once and is where all your programming assignments will be stored. 2. Create a Java class (File->New->Class) called LastNameFirstNameAssignment1 within the project a. For example, I would name my java class file GonzalezMickeyAssignment1 b. Please use this naming convention on all assignments. 3. Be sure to include an initial comment with: a. Your name b. Class name: CS1450(M/W) or (T/R) c. Due date d. Assignment \# e. Short description of what the assignment is about This initial comment is required on all assignments. This initial comment should be the first lines in your java file, before any code. 4. The Lectures and Assignments modules in Canvas contain helpful documents in these sections: a. For help with files: Review Object Oriented Programming and Files b. For help with assignment requirements: Programming Assignments Policy c. For help with design notebook and an example for this assignment: Design Notebook 5. For this assignment, there are 4 tasks. See output section below for each task's expected output. Task 1: Place 20 randomly generated integers between 10 and 40 into an array. 1) Display each randomly generated value when placing into array Task 2: Compute and display the following for the values in the array: 1) Sum 2) Average 3) Median a. The median is the middle value in the array. b. DO NOT hard code the array location of the median value. c. Use the Arrays.sort method to help find the median. d. The values in the array will be in sorted order after obtaining the median. 4) Largest value and number of times the largest appears in the array Task 3: Place the values in the 1D array into a 2D array. For help with 2D arrays, see Must Do and Tips below. Note at this point the values in the 1D array are in sorted order 1) Create a 2D array with this specific size: 4 rows and 5 columns 2) Move the values in the 1D array into the 2D array row by row and display the values a. Row by row means, fill the 2D array's row 0 first, then fill row 1 , etc. b. Print each value in 2D array i. Values must be in sorted order - see output below for an example. Task 4: After the array-based tasks in steps 1-3 are complete, perform the following file tasks: For help with files, in Canvas see section: Review Object Oriented Programming and Files 1) In your code create a file named assignment1.txt. a. Correct: File fileName = new File("assignment1.txt"); i. The file will be created in your current working directory. b. Incorrect: File fileName = new File("C:/Dev/assignment1.txt"); i. Incorrect because it includes the path name when creating the file 2) Open the file for writing. a. PrintWriter outputFile = new PrintWriter(fileName); 3) Write the values stored in the 2D array to the file in increasing order. a. Write one value on each line in the file. 4) Close the file. a. Make sure assignment1.txt appears on your hard drive in the workspace directory b. See Must Do and Tips section for help with finding the file on your hard drive. 5) Reopen the file for reading. a. Scanner readFile = new Scanner (fileName); Must Do and Tips Must Do: Create a design notebook - This assignment and all remaining require a design notebook worth 15% of your grade. - See the example design notebook that was created for this assignment on Canvas. - From the example, you may copy step 1 (problem statement) and step 3 (design sketch). - You must provide your own thoughts in step 2 (understandings), step 4 (pseudocode), and step 5 (lessons learned). Must Do: General - All code can be in main() - that is - methods and classes are not required. - You must use an array, not an ArrayList. - The purpose for manually working with arrays is to develop a stronger understanding. Must Not Do - Do not include path names with the file. Use only the name assignment1.txt - File fileName = new File("assignment1.txt"); Tip: Finding the median and largest value - To make this task easier, sort the array. - You are allowed to use Array.sort() method. Tip: Working with 2D arrays - Once you have learned to use 1D arrays, 2D arrays are an easy extension to the 1D concept. - See the provided FAQ on 2D arrays for help on creating a 2D array and manipulating the values. Tips: Finding the file on your system - To help find the assignment1.txt file that is created, add the following line of code after you create the PrintWriter or at the end of the code: System.out.printin("File is in directory: " + fileName.getAbsolutePath()); Tips: Exceptions - You may have learned about exceptions and try/catch blocks in your Java class. - Exceptions are important, but they add complexity to code to is not helpful right now. - To eliminate this added complexity and the need to use try/catch blocks, have main throw an IOException. public static void main(String[] args) {} Output Your output will look like the following except with different random numbers. Sum =502.0 Average =25.1 Median =27 Largest value =40 which occurred 3 times Values placed into 2D array 1010101315161821212127282934343738404040 Random values stored in file in sorted order 10 10 10 13 File is in directory: C:IDevleclipse_workspacelCS1450lassignment1.txt Where the file is located on my hard drive See Tips for the code to display this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Describe the factors influencing of performance appraisal.

Answered: 1 week ago