COSC121 – Assignment A6 Solved

44.99 $

Category: Tags: , , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (3 votes)

Focus: ArrayLists
Q1. [10 marks] Write a method with the following header

public static ArrayList<Integer> noDuplicates(ArrayList<Integer> list)

The method returns a new array list that contains the non-duplicate elements of list.
Write a test program that prompts the user to enter 5 integers to a list and displays the distinct integers.
Sample run

Q2. [15 marks] Write a method that has the following header:
public static void printShuffled(String filename)
The method reads a text file, filename, sentence by sentence into an array list, shuffles the sentences, and then prints out the shuffled contents. Assume sentences end with one of these characters: “.”, “:”, “!” and “?”. Your method should create an array list for storing the sentences. The array list should be created with approximately the correct number of sentences, instead of being gradually expanded as the file is read in.
Write a test program that reads the attached story.txt file and prints its contents using your method.
Hints:
• To read sentences instead of lines or words, use the method useDelimiter(“[.:!?]”)of the Scanner class.
• To determine the approximate number of sentences, divide the file length, representing the size of the file, by an assumed average size of a sentence (let’s say 50 characters).

Sample output

Grading
• 15 % for logic explanation
• 70 % for proper code structure and logic
• 15 % for correct syntax and formatting

Submission Instructions

For programming questions, explain in few, simple sentences the algorithm you used to tackle the problem. Add these sentences as a block comment at the beginning of your program. For coding questions, make sure to use appropriate code formatting and structure (e.g., indentation, brackets, etc.).
For this assignment, you need to do the following:
1- Create a Java project of which name consists of your student number followed by the assignment number, e.g., “1234567_A6”.
2- Create one class for each question and write your answer inside that class. Your classes should have the same name as the question number (e.g., Q1)
3- After solving all questions, open Windows Explorer (or any other file explorer).
4- Navigate to your Java project folder (can be found inside your Eclipse workspace folder).
5- Locate the “src” folder for this project (the folder that includes the source code for all questions).
6- Zip the “src” folder and rename the zipped file to match your project name (e.g., 1234567_A2.zip).
7- Submit the zipped file to Canvas.
Note that you can resubmit an assignment, but the new submission overwrites the old submission and receives a new timestamp.

  • A6-ygfju8.zip