Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

Ask Java Expert


Home >> Java

problem 1: The purpose of this problem is to practice using ArrayLists.prepare a Java client file containing a mainmethod plus other methods as needed to solve the following problem (no class definition file is to be used). (Remember to solve this problem by calling a number of methods, rather than writing large code segments)

A) Generate 30 random numbers between 1 and 1000 inclusive and store these in 2 different Array Lists simultaneously as described below:

a) each ArrayList should be created using the default size (of 10)

b) the first ArrayList should hold the random numbers in the order they are generated (so it will need to automatically expand to accommodate the data)

c) the second ArrayList should hold the random numbers in sorted order. This will be accomplished by inserting each element as it is generated into the second ArrayList using a modified version of the insertion sort code we studied in class

  • make a method that contains your modified insertion sort code.  Your code should work with an ArrayList, not a Comparable[ ].

B) Display the 2 ArrayLists, hopefully demonstrating that your modified insertion sort works (note the first arraylist will display the unsorted data, while the 2ndarraylist should be sorted)

C) Create another method that will perform a selection sort on an arraylist and send it the first (unsorted) arraylist. This method should contain a modified version of the selection sort code we discussed in class; the code is modified to use an arraylist rather than a comparable[ ].

problem 2: The purpose of this problem is to practice using generics.

A) Create a generic class with a type parameter that simulates drawing an item at random out of a box. For ex the box might contain Strings representing names written on a slip of paper, or the box might contain Integers representing a random drawing for a lottery. Include the following methods in your generic class, along with any other methods you’d like:

a) an add( ) method that allows the user to add an object of the specified type.
b) an isEmpty( ) method to determine if the box is empty.
c) adrawItem( ) method that randomly selects an object from the box and returns it.  Return null if the box is empty.

B) In the driver file that tests your class create 2 boxes, one with the names of 7 friends, the other with numbers between 1 and 5 representing the amount of hours of home work you will do before going to the party you’ve been invited to. Use the add( ) methods to populate the 2 boxes, and the drawItem( ) methods for each box to determine i) how many hours of home work you will do before ii) going to the party with the friend you will invite (from the “friends” box)

Java, Programming

  • Category:- Java
  • Reference No.:- M91800

Have any Question? 


Related Questions in Java

Code reviewcan some have this done immediatelypublic class

Code Review Can some have this done immediately public class BankAccount { private double balance; public BankAccount() { balance = 0; } public BankAccount(double initialBalance) { balance = initialBalance; } public void ...

Student class and driverthis student class will be the data

"Student Class and Driver" This Student Class will be the data that will be used for each of the projects assigned and graded this semester. Your Student Class will consist of: Student Attributes: First Name Last Name ID ...

Chapter 1 - challenge 3 - training workshopsyour company

Chapter 1 - Challenge #3 - Training Workshops Your company likes to present training workshops that help people in the information technology industry improve their skills. Your task is to write and object-oriented appli ...

1 problem overviewyou have been asked to design and

1 Problem Overview You have been asked to design and implement a training system for company directors. In the best tradition of economics, we shall start by making things up. The training system is intended to show peop ...

Develop an application in java to accept the number of

Develop an application in Java to accept the number of students in a section for a subject and for each student accept the student number, Student name, prelim marks, midterm marks, final marks. The final grade should be ...

Question 1 illustrate that the nodes of any avl tree t can

Question 1. Illustrate that the nodes of any AVL tree T can be colored "red" and "black" so that T becomes a red-black tree. Question 2. Illustrate that via AVL single rotation, any binary search tree T1 can be transform ...

Pogramming assignmentmickeymouse- x int- y int- size

Programming Assignment MickeyMouse - x : int - y : int - size : int -color: Color + MickeyMouse(): + setLocation (x: int, y: int): void + setSize (size: int): void + setColor(color: Color):void + draw(canvas: Graphics2D) ...

This assignment is based on the principles of clock

This assignment is based on the principles of clock consistency and associated drifts in a distributed system. You have to create a simulation, running on a single machine, of a simple distributed system involving four p ...

Java- object-oriented and concurrent programmingheres a

Java- Object-Oriented and Concurrent Programming Here's a very quick overview of the projects: 1. Read a data file, create the internal data structure, create a GUI to display the structure, and let the user search the s ...

Instructionsi what are the diagrams defined in the uml

Instructions I. What are the diagrams defined in the UML Standard. Give a one or two sentence description of each one. II. Given the following code, how should the toString methods in the classes H2ClassA and H2ClassB be ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate