Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help, will thumbs up 100% if works exactly. Collections methods Use class collection methods to manipulate some data structure elements. Create a main class

Please help, will thumbs up 100% if works exactly.

Collections methods

Use class collection methods to manipulate some data structure elements.

Create a main class named CollectionMethods

Create array variable with the name whotCards and fill the array with the following string elements in any order of your choice: Star, Circle, Plus, Square and Triangle - Print out the whotCards elements as:

Sorted data

Unsorted data

Shuffled data

(Hint: You will need sort and shuffle collection methods to do these)

Print out the whotCards elements that come first and last if arranged in alphabetical order (Hint: use max and min collection methods)

Implement a List interface of an ArrayList class with an integer data type

Use for-loop, fill the ArrayList class object with numbers from 1 to 1000 that are divisible by 2, 3 and 5

Print out the elements in the ArrayList class object in:

Reversed order

Ascending order

(use reversedOrder and sort collection methods)

Print out the maximum and minimum integer elements in the ArrayList class object (Hint: use max and min collection methods)

Complete file: CollectionMethods

This is what i have so far, fix whatever is needed to perfectly follow guidlines.

import java.util.List;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Arrays;

public class CollectionMethods{

public static void main(String[] args) {

String[] whotCards = {"Star", "Circle", "Plus", "Square" , "Triangle"};

List order= new ArrayList(Arrays.asList(whotCards));

//unassorted elements

System.out.printf("%nUnsorted array of elements : %s%n", order);

// sorted elements

Collections.sort(order);

System.out.printf("%nSorted array of elements: %s%n", order);

// shuffled elements

Collections.shuffle(order);

System.out.printf("%nCards shuffled : %s%n", order);

// new array list of ArrayList with Integer

List list= new ArrayList();

// for loop 1- 1000, divisible by 2, 3 and 5--> needs Collections.reversedOrder()

System.out.printf("%nInteger elements in reversed order: %n");

for (int i=1; i

{

if (i%2==0 && i%3==0 && i%5==0)

System.out.printf(i +", ");

}

// for loop 1- 1000, divisible by 2, 3 and 5--> needs Collections.sort()

System.out.printf("%n%nSorted integer elements: %n");

for (int i=1; i

if (i%2==0 && i%3==0 && i%5==0)

System.out.printf(i +", ");

}

//Print out the maximum and minimum integer elements in the ArrayList class object

//(Hint: use max and min collection methods)

System.out.printf("%nThe maximum number from 1 to 1000 divisible by 2, 3, and 5 is: 950");

System.out.printf("%nThe minimum number from 1 to 1000 divisible by 2, 3, and 5 is: 30");

}

}

Please assist, i have most code i believe. but it isnt correct, so please fix anything needed, thank you-- will thumbs up if its perfect~

image text in transcribed

Sample output Unsorted arrayelenenEs: [Star, Cirele, Cross, Siare. Triangle Sorted arEay elements: [Cirele, CEoss. Square, Star, Trianglel Card shuffled: [CEoss. Triangle. Square.Circle. Star Last vord, t artanged in alphabitical ordet: Tiangle FLESt vord. it arzanged in alphabitieal order: CiECle Integer Ele,ent n Eeversed order 90, s60, 30, 900 , 870 510, 480, 450, 420, 390, 840 , 010 , 700, 7S0 , 7=0, ESO, 660 , 630, 600 , 570, S40 360, 330, 300, -70 , 4D , -10, 180, 150, 1 0 , 0, EO, 30 ] Sorted integer elenents: 30 60 90 120 150 180 210 240 270 300 330 360 390 420 450 480 510 540 570 600 630 The max inn. numbeE fEom 1 to 1000 divisible by,3 and S is:990

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago