Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

clocks In this assignment you will work with an array of objects (Clock in this case). You will perform basic operations on the array including

clocks
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
In this assignment you will work with an array of objects (Clock in this case). You will perform basic operations on the array including sorting, searching, retrieving and modifying. You will also get a chance to work with input files and output files. The assignment will require you to write a Clock class, a ClockShop class, and work with an existing class (ClockShopTester) to test the functionality of your ClockShop and Clock classes. Details for each class are given below. Clock Include the following methods in your Clock class Clock(int the Hour, int the Minute, int the Second): Explicit value (parameterized) constructor that is passed the hour, minute, and second of the clock (all type int). Use the set methods specified below to ensure the passed in values are in the proper range Clock(): Default value constructor which defaults to 23:58:00 (two minutes to midnight). This constructor should call the explicit value constructor (via this) and let it do the work. .toString() override-- the method will return a String with the hours, minutes and seconds as follows: hh:mm:ss (ex: 9:49:59) getHour(), getMinute(), and getSecond() which return the appropriate value .setHour(int the Hour) -- set the current hour o if a value is outside the acceptable range of O through 23, throw an IllegalArgumentException that includes information about the incorrect value setMinute(int theMinute) set the current minute o if a value is outside the acceptable range of O through 59, throw an IllegalArgumentException that includes information about the incorrect value setSecond(int the Second) set the current second o if a value is outside the acceptable range of O through 59, throw an IllegalArgumentException that includes information about the incorrect value advanceHour(int theAmount): advance the current hour (a number 0 or greater will be passed in to the object from outside -- the resulting hour should be represented in the range of 0 to 23) (HINT: % is your friend) (any value less than O should throw an exception with an appropriate message) advanceMinute(int theAmount): advance the current minute (a number 0 or greater will be passed in to the object from outside -- the resulting minute should be represented in the range of 0 to 59 *AND* the hour should be updated accordingly) (any value less than 0 should throw an exception with an appropriate message) equals(Object theObject) override -- compare against another Clock object for equality. Once this method confirms the parameter is not null and is a Clock, it should call the compareto method specified below compareTo(Clock theOtherClock) -- implement the Comparable interface and write the associated compareTo method so that the current Clock can be compared against another Clock for order. Your Clock class should have implements Comparable at the end of the class declaration. This method should return a negative value if the current object (this) is less than the object passed in (theOtherClock), a positive value if the current object is greater, and O if the two objects are the same. 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 array (ArrayList is also ok if you wish) of type Clock Include a method called fillClockShop(String theInputFileName) 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. Read through the file and determine how many entries there are. After this, allocate an appropriately sized array of type Clock, then fill the array with Clock objects initialized based on the values in the input file. NOTE: You will most likely need to read through the input file twice. DISCLAIMER: If you decide to use an ArrayList you will only need to read through input file once! Include a method called 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 findClock(Clock theClock) that is passed a Clock object and checks to see if it exists in the Clock array. If it does exist, return the index of where the first one was found. If it does not exist, return a -1. Include a toString method 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 should be separated from the others by a newline ( ). Include a getClock(int index) 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 setClock(Clock theClock, int theIndex) method that is passed a Clock object and an index. The method places the Clock object at the specified index in the array. If the index is outside the range of the array, throw an IllegalArgumentException. Include a writeClocksToFile(String filename) 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

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

what is the most common cause of preterm birth in twin pregnancies?

Answered: 1 week ago

Question

Which diagnostic test is most commonly used to confirm PROM?

Answered: 1 week ago

Question

What is the hallmark clinical feature of a molar pregnancy?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago