Question

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.currentTimeMillis() 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 by using a timer. Also, for ( n = 100 ), display each number in the list before and after sorting. See sample output below.

          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.currentTimeMillis() 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 by using a timer. Also, for ( n = 100 ), display each number in the list before and after sorting. See sample output below.
        
Show more…
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 ov 46877

Added by Hunter K.

Close

Computer Science and Information Technology
Computer Science and Information Technology
Trishna Knowledge Systems 2018 Edition
AceChat toggle button
Close icon
Ace pointing down

Please give Ace some feedback

Your feedback will help us improve your experience

Thumb up icon Thumb down icon
Thanks for your feedback!
Profile picture
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.currentTimeMillis() 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 by using a timer. Also, for ( n = 100 ), display each number in the list before and after sorting. See sample output below.
Close icon
Play audio
Feedback
Powered by NumerAI
Danielle Fairburn Kathleen Carty
Ivan Kochetkov verified

Madhur L and 81 other subject AP CS educators are ready to help you.

Ask a new question

*

Labs

-

Want to see this concept in action?

NEW

Explore this concept interactively to see how it behaves as you change inputs.

View Labs

*

Key Concepts

-
Key Concept
Premium Feature
Explore the core concept behind this problem.
Play button
Key Concept
Premium Feature
Explore the core concept behind this problem.
Your browser does not support the video tag.

*

Recommended Videos

-
from-lab-14aimport-javaiobufferedreaderimport-javaiobufferedwriterimport-javaiofileimport-javaiofilenotfoundexceptionimport-javaiofilereaderimport-javaiofilewriterimport-javaioioexceptionimp-5271

From Lab 14a import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<>(); try (BufferedReader reader = new BufferedReader(new FileReader("data.txt"))) { String line = null; while ((line = reader.readLine()) != null) { int num = Integer.parseInt(line); numbers.add(num); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Sorts.performBubbleSort(numbers); for (int num : numbers) { System.out.println(num); } try (BufferedWriter writer = new BufferedWriter(new FileWriter("sorted_data.txt"))) { for (int num : numbers) { writer.write(num + " "); } } catch (IOException e) { e.printStackTrace(); } } } Sorts.java import java.util.ArrayList; public class Sorts { public static void performBubbleSort(ArrayList<Integer> toBeSorted) { int temp = 0; boolean swapMade = true; for (int i = 0; i < toBeSorted.size() - 1; i++) { if (!swapMade) break; swapMade = false; for (int j = 0; j < toBeSorted.size() - 1 - i; j++) if (toBeSorted.get(j) > toBeSorted.get(j + 1)) { temp = toBeSorted.get(j); toBeSorted.set(j, toBeSorted.get(j + 1)); toBeSorted.set(j + 1, temp); swapMade = true; } } } public static void performInsertionSort(ArrayList<Integer> toBeSorted) { } public static ArrayList<Integer> performMergeSort(ArrayList<Integer> toBeSorted) { return new ArrayList<Integer>(); } private static ArrayList<Integer> merge(ArrayList<Integer> listOne, ArrayList<Integer> listTwo) { return new ArrayList<Integer>(); } } Graded Assignment 5 - Insertion and Merge Sorts Supporting files Both the files from Lab 14a (completed) Assignment objectives Code, test, and use an insertion sort method Code, test, and use a merge sort method Assignment submission All graded assignments must be submitted by 11:59 p.m. on their corresponding due date. Once completed, upload the compressed file to Blackboard. Assignment directions Note: this assignment will build onto lab 14a, so that lab should be completed prior to starting this one. The supporting files are provided here for convenience but they are the same files as those posted in lab 14a. Part 1 - insertion sort 1. In the driver (MyClass), comment out the code associated with the bubble sort (but be sure to leave the code in the file) 2. Write an insertion sort method (i.e. complete the stub provided in the Sorts class) 3. Add code to your driver (MyClass) so that it uses your insertion sort to display the sorted numbers to the screen, and test it to ensure it is still producing a correctly sorted list 4. Add code to your driver (MyClass) so that in addition to displaying the sorted numbers to the screen, it also writes the sorted numbers to a file called "insertion.txt" Part 2 - merge sort 5. In the driver (MyClass), comment out the code associated with the insertion sort (but be sure to leave the code in the file) 6. Write a merge sort method (i.e. complete the stub provided in the Sorts class) 7. Add code to your driver (MyClass) so that it uses your merge sort to display the sorted numbers to the screen, and test it to ensure it is still producing a correctly sorted list 8. Add code to your driver (MyClass) so that in addition to displaying the sorted numbers to the screen, it also writes the sorted numbers to a file called "merge.txt"

Madhur L.

cmsc-215-intermediate-programming-programming-project-4-the-fourth-programming-project-involves-writing-a-program-to-test-the-relationships-between-a-time-intervals-the-program-should-contain-four-cla

For the GUI interface use javafx, and it should look as the one in the diagram

Akash M.

develop-the-java-program-for-the-following-applicationapplicants-to-a-master-program-need-to-be-sorted-according-to-some-attributes-of-applicantsthe-attributes-are-ales-score-undergraduate-g-98003

Develop the Java program for the following application. Applicants to a master program need to be sorted according to some attributes of applicants. The attributes are ALES score, undergraduate GPA, master exam score, and interview scores from two jury members. These attributes of an applicant are processed as explained below, and a weighted average of these scores is calculated, which makes the final score of the applicant. Applicants are sorted according to their final score in descending order. The sorted list is displayed. The final score is computed as follows: ALES scores are between 0 and 100. Undergraduate GPAs are between 0 and 4. Since the minimum graduate point is 2.00, in order to compare all scores, they have to be on the same scale. 4.0 is mapped to 100, and 2.00 is mapped to 50. For example, if the GPA is 3.00 over 4, it is mapped to 75. The exam score is between 0 and 100. Interview points are between 0 and 10 for each jury member. Then the interview score is the average of the two jury points. Map the overall interview score between 0 and 100 as for CPA. After preprocessing all four scores and bringing them to the 0-100 interval, a weighted average is calculated. Define weights properly; not applicant-specific but general characteristics of the Applicant class. For this year, weights are as follows: ALES 0.35, GPA: 0.2, exam: 0.3, and interview 0.15. Write the program for general weights adding to 1.0. Classes in the program: Person: defines the name, last name of the applicant. Applicant: defines applicant ID as a new attribute specific to an applicant. Methods: compareTo method: concrete implementation of the compareTo method in the generic comparable interface. Compares two applicants according to the final score. toString method: prepares a string representation of the applicant benefit from Person's toString method. Define other variables or methods properly. Test class: Generic sort method with ascending and descending order options defined as a boolean parameter, able to sort any type of objects via the implementation of the compareTo methods. Print method: printing any object via toString method. In the main method, applicants are generated and stored in an array. Send the array to the sort method and display the sorted list to the screen. Do not get any information from the screen.

Akash M.


*

Recommended Textbooks

-
Computer Science and Information Technology

Computer Science and Information Technology

Trishna Knowledge Systems 2018 Edition
achievement 1,733 solutions
Introduction to Programming Using Python

Introduction to Programming Using Python

Y. Daniel Liang 1st Edition
achievement 1,120 solutions
Computer Science - An Overview

Computer Science - An Overview

Glenn Brookshear, Dennis Brylow 12th Edition
achievement 1,879 solutions

*

Transcript

-
00:01 Hello students, here is a java code that reads the integer from the file, sorts them using an insertion sort algorithm and then writes the sorted integer to another file.
00:12 So here, an array list of integer number is equal to the new array list.
00:18 As the array list named as the number is created to store the integer read from the file.
00:25 As then the try buffered reader that reader is equal to the new buffer reader.
00:32 Here the buffer reader is used to read the file, read the data from a file named as the data .txt as the data .txt from that the code is enclosed in a try with a resource block to ensure that the reader is properly closed after reading.
00:50 That the string line is equal to null, these line is tries a string variable as line to null, it will be used to read each line of the text from the file.
01:02 Whereas into a while loop, this loop reads the each line from the file using the read line method until the end of the file is reached.
01:12 As int of num, each line reads from the file is converted into an integer assuming that the file contains the valid integer value.
01:22 As the integer num is added to the numbers list, where this sorts as the sorts that perform insertion sort, here method forms this sort class is used to sort the integer in the number list using the insertion sort algorithm, whereby using the for loop, this loop iterates through the sorted integer in the numbers list and prints them to the console...
Need help? Use Ace
Ace is your personal tutor. It breaks down any question with clear steps so you can learn.
Start Using Ace
Ace is your personal tutor for learning
Step-by-step explanations
Instant summaries
Summarize YouTube videos
Understand textbook images or PDFs
Study tools like quizzes and flashcards
Listen to your notes as a podcast
Continue solving this problem
Create a free account to:
  • View full step-by-step solution
  • Ask follow-up questions with Ace AI
  • Save progress and study later
Continue Free
Numerade

Get step-by-step video solution
from top educators

Continue with Clever
or



By creating an account, you agree to the Terms of Service and Privacy Policy
Already have an account? Log In

A free answer
just for you

Watch the video solution with this free unlock.

Numerade

Log in to watch this video
...and 100,000,000 more!


EMAIL

PASSWORD

OR
Continue with Clever