Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here's some code from Clock.java that I was able to get running Just need ClockShop.java ASAP please. Thank you! ClockShop This class will hold an

image text in transcribed
Here's some code from Clock.java that I was able to get running
image text in transcribed
Just need ClockShop.java ASAP please. Thank you!
ClockShop This class will hold an array of Clock objects. It will provide behaviors (methods) that allow for sorting, searching, retrieving, and printing the Clocks it contains. Specifics for this class are as follows: - Declare a private field that is an ArrayList of type Clock called myClocks - private ArrayList myClocks; - Include a default constructor (public ClockShop()) that is used to create an empty ArrayList of Clock and assign it to your myClocks field - Include a method called public void fillClockShop(final String thelnputFileName) which is passed the name of a file. The method opens the file specified in the parameter to the method for input. This file will contain times for clocks, one per line, in the following format: hour:minute:second (e.g. 11:29:45). There will be at least one entry in the file, guaranteed. Read through the file and fill myClocks with Clock objects initialized based on the values in the input file. NOTE: You can modify the Scanner object you are using to read from the file and use a colon ':' as the delimiter by calling the useDelimiter(String pattern) method on your Scanner if you wish. - Include a method called public void sortClocks that sorts the Clocks in ascending (smallest time to largest time) order. You must write the code to sort the array of Clocks (meaning calls to the Java API to do this are not allowed). Your sort code must utilize the compareTo method provided by the Clock class. - Include a method called public int findClock(final Clock theClock) that is passed a Clock object and checks to see if it exists in the Clock ArrayList. If it does exist, return the index of where the first one was found. If it does not exist, return a 1. - Include a public String toString method (which is an override of the toString method inherited from Object) that builds a String containing each Clock object in String format (via the toString in the Clock class) and returns that String. Each Clock object must be followed by a newline ( ). - Include a public Clock getClock(final int thelndex) method that is passed an integer index of which Clock to retrieve from the array of Clocks. If the index is outside the range of the array, throw an IllegalArgumentException. If the index falls within the array, return the Clock object at that index. - Include a public void setClock(final Clock theClock, final int thelndex) method that is passed a Clock object and an index. The method places the Clock object at the specified index in the array (replacing the Clock that was there before). If the index is outside the range of the array, throw an IllegalArgumentException. - Include a public void writeClocksToFile(final String theFilename) method that is passed the name of a file, opens a file by that name, then writes the contents of the array of Clocks to the file. It then closes the file. NOTE: take advantage of the toString method you wrote for this class

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

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Comment should this MNE have a global LGBT policy? Why/ why not?

Answered: 1 week ago