Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please fix my code. I finished it but it still fails. the failing result the instructions In the Test class lic class Time private int

Please fix my code. I finished it but it still fails.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

the failing result

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

the instructions

image text in transcribedimage text in transcribedimage text in transcribed

In the Test class

image text in transcribed

lic class Time private int hours; private int minutes; private int seconds; public Time(int hours, int minutes, int seconds) super(); this.hours = hours; this.minutes = minutes; this.seconds = seconds; \} public Time() \{ super(); hours =9; minutes =00; seconds =00; \} public int getHours() \{ return hours; public String toString() \{ String str = (h"; if (hours ) str = " 0 "; _test94412.java: 16: error: cannot find symbol time.incrementSeconds (; ; symbol: method incrementSeconds() location: variable time of type Time _test94413.java: 17: error: cannot find symbol time incrementSeconds(); symbol: method incrementSeconds() Iocation: variable time of type Time _test94764.java:17: error: cannot find symbol time.incrementSeconds(); symbol: method incrementSeconds() Iocation: variable time of type Time _test94765.java:12: error: cannot find symbol time. incrementMinutes(); symbol: method incrementMinutes() Iocation: variable time of type Time _test94766.java:12: error: cannot find symbol time.incrementHours(); symbol: method incrementHours() Iocation: variable time of type Time _test94767.java:12: error: cannot find symbol time.incrementHours(); symbol: method incrementHours() location: variable time of type Time 6 errors _test94412.java: 16: error: cannot find symbol time.incrementSeconds(); symbol: method incrementHours() Iocation: variable time of type Time 6 errors _test94412.java:16: error: cannot find symbol time.incrementSeconds(); symbol: method incrementSeconds() Iocation: variable time of type Time 1 error _test94413.java:17: error: cannot find symbol time.incrementSeconds(); symbol: method incrementSeconds() Iocation: variable time of type Time 1 error _test94764.java:17: error: cannot find symbol time incrementSeconds(); symbol: method incrementSeconds() Iocation: variable time of type Time 1 error test94765.java: 12: error: cannot find symbol time. incrementMinutes(); symbol: method incrementMinutes() location: variable time of type Time 1 error test94766.java:12: error: cannot find symbol time incrementHours(); symbol: method incrementHours() Iocation: variable time of type Time 1 error test94767.java:12: error: cannot find symbol time.incrementHours(); symbol: method incrementivinutes() Iocation: variable time of type Time 1 error _test94766.java:12: error: cannot find symbol time.incrementHours(); symbol: method incrementHours() Iocation: variable time of type Time 1 error _test94767.java:12: error: cannot find symbol time.incrementHours(); symbol: method incrementHours() Iocation: variable time of type Time 1 error A Time object contains values for hours, minutes, and seconds using military time (hours is a value in 0 to 23). The operations include getters for each field, methods that increment each of the fields, a method for comparing two Time objects for equality and a method that gives the string representation of the time. Implement the Time class as follows: a. Declare the hours field as follows: private int hours; Similarly, declare the minutes and seconds fields. b. Have Eclipse generate the constructors as described below by using Source > Generate Constructors Using Fields... (have it also generate comments) - Include a constructor that allows the client to provide initial values for all three fields. We will not do any error checking on the parameters in this assignment - Include a default constructor (no parameters). This constructor should initialize the fields to the time 09:00:00. - Make sure to add appropriate explanatory information to the auto-generated comments for each of your constructors c. Have Eclipse generate getter methods for each of the fields by clicking in the editor window and selecting Source -> Generate Setters and Getters... (also generate comments). Do not generate setter methods for this class. Add appropriate explanatory information to the comments. d. Have Eclipse generate a toString method with Source -> Generate toString()... Note that the generated method uses a predefined format for the fields. Modify this to display the time in the form hrs:mins: secs (put colon characters between each time component). e. Write an incrementSeconds method to simply add 1 to the seconds field. Note that just adding is not going to be correct in all cases, but leave it like that for now. We'll fix this later. Write similar methods for incrementMinutes and incrementHours. a. A problem occurs in incrementseconds when 59 seconds is incremented, and the seconds value reached 60 it should roll over to 0 . Change incrementSeconds to do this. Save your changes and run the test again by clicking in the JUnit view. Did this fix the problem? Did it create any new problems? What else should have occurred when seconds reached 60? Fix this, save the changes and run the test again. More tests should work now, but other problems still exist. Go on to fix the incrementminutes method. Test to be sure this is working properly before fixing the incrementhours method. b. Everything should be working now except the equals method (and maybe tostring ()). The problem is that the equals method from the object class is being used and it doesn't know about hours, minutes, and seconds. You can try writing your own equals method to override the default one or have Eclipse write it for you with Source > Generate hashCode( ) and equals()... We don't actually need the hashCode () method so ignore it. The tests should now succeed with the generated equals method. If the test for tostring () fails, make the necessary changes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions