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

Programming assignmentyou to write a class named

Programming Assignment You to write a class named WeaklyCalendar. This class must be in a package named pa4. Note that the description of a programming assignment is not a linear narrative and often requires multiple rea ...

Project binary search treesdesign and implement a class for

Project: Binary Search Trees Design and implement a class for a simple infix algebraic equation calculator using any method learned in class (Stacks, Recursion, Binary Trees...) Note: Please provide adequate documentatio ...

1how does java support the concept of encapsulation2

1. How does Java support the concept of encapsulation? 2. Describe the difference between an object and a class. 3. What is the difference between the contents of a Java variable of a primitive type and a Java variable o ...

Consider the following tilde table that could be

Consider the following "tilde table" that could be represented by the file cars.txt for persistence MAKE~MODEL~TYPE~PRICE Toyota~Camry~Sedan~18000 Toyota~Tacoma~Truck~19000 Ford~Mustang~Sport~21000 Chevrolet~Corvette~Spo ...

Questions for java programing answer each question with at

QUESTIONS FOR JAVA PROGRAMING (answer each question with at least 5 sentences) 1. Discuss why it is necessary to use repetitive and selective statement. Use segment codes to demonstrate your understanding. Explain why yo ...

Assignmenta private int data field named volume that

Assignment A private int data field named volume that specifies the volume· Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume. Create a Java class named HeadPhone to repr ...

Module assignment introduction to programming using

Module Assignment: Introduction to Programming Using Java This assignment is to provide practice using arrays and strings along with other Java programming techniques discussed so far in the course. For this assignment, ...

Assignment 1overviewthis is an individual assignment that

Assignment 1 Overview This is an individual assignment that requires you to design, develop and test a small procedural Java program. Timelines and Expectations Learning Outcomes Assessed The following course learning ou ...

Create your own simple java application to generate x

Create your own simple Java application to generate X random Integer values between 0 and Y. Use command line arguments for entry of X and Y. Demonstrate your code compiles and runs without issue using screen captures as ...

Exam program create a class for working with mixed

Exam Program: Create a class for working with mixed fractions. Only 3 private data members are needed: the int whole number part of the fraction, the int numerator of the fraction, and the positive int denominator of the ...

  • 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

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen