Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Only 3b) is assessed. C0520 Class 1 - Collections Important: One of the exercises in this class is selected as part of the Assignment 1

image text in transcribed
Only 3b) is assessed.
C0520 Class 1 - Collections Important: One of the exercises in this class is selected as part of the Assignment 1 for this module. You should aim to complete the assessed task and submit your answer using the link on Moodle before the deadline. A mark of zero will be awarded for late or non submission of the assessed work. Part A - ArrayList 1. Define a function that takes 2 parameters of type int and returns an ArrayList containing a given number of random integers between 1 and a given upper bound. 2. Write Java code to create an ArrayList containing 20 random numbers between 1 and 100 (inclusive) using the function defined in Task 1 and then print out all the numbers in an ascending order. Part B - HashMap 3. Part of the lyrics of "Sing a Song" by The Carpenters is stored in the string lyrics below: String lyrics - "Sing, sing a song/Let the world sing along/" + "Sing of love there could be/Sing for you and for me," + "Sing, sing a song/Make it simple to last/" + "Your whole life long/Don't worry that it's not/" + "Good enough for anyone/Else to hear/" + "Just sing, sing a song"; Write the Java code to a) Find out the total number of words in lyrics. Hint: Use the methods of String class to covert lyrics in lower case, remove any punctuations and extra spaces before splitting lyrics using the split() method with white space as delimiter. b) [Assessed] Calculate the frequency of each unique word in lyrics and then print out the words and their frequencies that occur more than once. Hint: Use a HashMap

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

Students also viewed these Databases questions