Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Timer Class Design and implement a Java class named Timer, which contains - private instance variables to record start and end time -

image text in transcribedimage text in transcribed

Part 1: Timer Class Design and implement a Java class named Timer, which contains - private instance variables to record start and end time - constructors: default constructor (no argument) and an overloading constructor (2 parameters) that initialize both instance variables. - get and set methods. - start and stop methods: use the current system time to set either start or end time - getElapsedTime method: returns the difference of start and end time. Recall that the System.currentimeMillis() method gives you the current UTC time (from midnight, January 1, 1970) in milliseconds. Part 2: Utility Class Write a Utility class that contains the following methods: - selectionSort: a void method, which takes a list of integers as its parameter, and sorts the list in ascending order using the selection sort algorithm. You must implement the selection sort and must not use any other sort method in Java API. You must understand the differences between different sorting algorithms. Implementing any other sorting algorithm such as bubble sort will receive no credit. Also pay attention that a list is not an array and vice versa. - swap: a private helper void method for the selection sort. The method takes three parameters, i.e., a list and two indices, and swaps the values at the specified indices in the list. Part 3: Test Class Write a Test class to test the following methods: - genList: takes an integer parameter n and returns a list of n random numbers in the value range of [n,2n] (both inclusive). - main: test everything using various n values, e.g., 100 and 100000 and display how long it takes to generate and sort numbers. Also, for n=100, display each number in the list before and after sorting. See sample output below. Sample Output Generated 100 random numbers: 0.001 seconds List before sorting: [197, 106,120,107,198,170,117,167,114,103,194,126,192,152,159,153, 152,130,158,121,165,111,188,150,159,199,114,130,116,152,176,105, 178,100,103,137,186,122,157,119,128,173,167,124,135,162,131, 153,123,113,138,164,180,131,188,144,128,195,112,109,119,132,196, 117,133,186,125,176,127,171,119,191,171,146,124,127,166,139, 152,105,108,189,141,113,147,101,171,136,111,108,172,119,162,122, 163,150,131,109,132,117] Selection sort: 0.003 seconds List after sorting: [100, 101,103,103,105,105,106,107,108,108,109,109,11,1,111,112,113, 113,114,114,116,117,117,117,119,119,119,119,120,121,122,122,123, 124,124,125,126,127,127,128,128,130,130,131,131,131,132,132, 133,135,136,137,138,139,141,144,146,147,150,150,152,152,152,152, 153,153,157,158,159,159,162,162,163,164,165,166,167,167,170, 171,171,171,172,173,176,176,178,180,186,186,188,188,189,191,192, 194,195,196,197,198,199]

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

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What information is relevant to solve this problem and why?

Answered: 1 week ago