Part 1 Create a UML class diagram for the Time class as described below: The class will have two integer instance variables representing hours and minutes. These will be stored in standard 24-hour time. The class must have the following methods: a default constructor that sets the time to midnight • a constructor that takes two integer variables representing the hours in 24- hour time (0-23) and the minutes in the range 0-59. This constructor will validate the constructor inputs and will set the time to midnight if either value is outside of the needed range. • a constructor that takes two integers and a string. The string must be either "AM" or "PM", and the integer will be the hours in the range 1-12 and the minutes in the range 0-60. Again, the constructor will validate the constructor inputs and will set the time to midnight if either value is outside of the needed range or the String is not "AM", "am", "PM", or "pm". • getters and setters for the hours and minutes. The setters must validate the input values and will not change the time unless the value is in valid 24 hour time range. • an equals method .toString-returns a String with the time in the form hh:mm, where hh can range from 00 to 23. • get 12 HourTime - returns a String with the time in the form hh:mm AM or hh:mm PM Create test data for 2 different Time objects (in addition to the samples below) and the results of calling methods with various inputs. Have at least 2 different method calls each for the setters, equals, toString, and get 12HourTime methods, trying to test different situations. You may use the sample objects below in your own tests. Sample test data: Code: Time timel new Time (2,30); Expected result: timel object created with hours: 2 and minutes: 30 Code: Time time2= new Time (2,45, "PM"); Expected result: timel object created with hours: 14 and minutes: 45 Code: Time time3= new Time (14,45); Expected result: timel object created with hours: 14 and minutes: 45 Code: Time time4 = new Time (25,50); 1 Espected result: time4 object created with hours: 0 and minutes: 0 (midnight - because of invalid. input) Code: time3.setMinutes (68); Expected result: time3 object not changed because of invalid input. Code: System.out.println(time3.equals(time2)); Expected result: true printed to console Code: System.out.println(time3); // calls time3.toString() automatically Expected result: 14:45 printed to console Code: Expected result: 2:45 PM printed to console 2 System.out.println(time3.get12Hour Time());

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
|||
Part 1
Create a UML class diagram for the Time class as described below:
The class will have two integer instance variables representing hours and minutes.
These will be stored in standard 24-hour time.
The class must have the following methods:
• a default constructor that sets the time to midnight
a constructor that takes two integer variables representing the hours in 24-
hour time (0-23) and the minutes in the range 0-59. This constructor will
validate the constructor inputs and will set the time to midnight if either
value is outside of the needed range.
a constructor that takes two integers and a string. The string must be either
"AM" or "PM", and the integer will be the hours in the range 1-12 and the
minutes in the range 0-60. Again, the constructor will validate the
constructor inputs and will set the time to midnight if either value is outside
of the needed range or the String is not "AM", "am", "PM", or "pm".
getters and setters for the hours and minutes. The setters must validate the
input values and will not change the time unless the value is in valid 24 hour
time range.
an equals method
.toString returns a String with the time in the form hh:mm, where hh can
range from 00 to 23.
get 12 HourTime - returns a String with the time in the form hh:mm AM or
hh:mm PM
Create test data for 2 different Time objects (in addition to the samples below) and
the results of calling methods with various inputs. Have at least 2 different method
calls each for the setters, equals, toString, and get 12HourTime methods, trying to
test different situations. You may use the sample objects below in your own tests.
Sample test data:
Code:
Time time1 new Time (2,30);
Expected result:
timel object created with hours: 2 and minutes: 30
Code:
Time time2 new Time (2,45, "PM");
Expected result:
timel object created with hours: 14 and minutes: 45
Code:
Time time3= new Time (14,45);
Expected result:
timel object created with hours: 14 and minutes: 45
Code:
Time time4 new Time (25,50);
1
Espected result:
time4 object created with hours: 0 and minutes: 0 (midnight - because of invalid
input)
Code:
time3.setMinutes (68);
Expected result:
time3 object not changed because of invalid input.
Code:
System.out.println(time3.equals(time2));
Expected result:
true printed to console
Code:
System.out.println(time 3); // calls time3.toString() automatically.
Expected result:
14:45 printed to console
Code:
Expected result:
2:45 PM printed to console
2
System.out.println(time3.get12Hour Time());
O
2
Transcribed Image Text:||| Part 1 Create a UML class diagram for the Time class as described below: The class will have two integer instance variables representing hours and minutes. These will be stored in standard 24-hour time. The class must have the following methods: • a default constructor that sets the time to midnight a constructor that takes two integer variables representing the hours in 24- hour time (0-23) and the minutes in the range 0-59. This constructor will validate the constructor inputs and will set the time to midnight if either value is outside of the needed range. a constructor that takes two integers and a string. The string must be either "AM" or "PM", and the integer will be the hours in the range 1-12 and the minutes in the range 0-60. Again, the constructor will validate the constructor inputs and will set the time to midnight if either value is outside of the needed range or the String is not "AM", "am", "PM", or "pm". getters and setters for the hours and minutes. The setters must validate the input values and will not change the time unless the value is in valid 24 hour time range. an equals method .toString returns a String with the time in the form hh:mm, where hh can range from 00 to 23. get 12 HourTime - returns a String with the time in the form hh:mm AM or hh:mm PM Create test data for 2 different Time objects (in addition to the samples below) and the results of calling methods with various inputs. Have at least 2 different method calls each for the setters, equals, toString, and get 12HourTime methods, trying to test different situations. You may use the sample objects below in your own tests. Sample test data: Code: Time time1 new Time (2,30); Expected result: timel object created with hours: 2 and minutes: 30 Code: Time time2 new Time (2,45, "PM"); Expected result: timel object created with hours: 14 and minutes: 45 Code: Time time3= new Time (14,45); Expected result: timel object created with hours: 14 and minutes: 45 Code: Time time4 new Time (25,50); 1 Espected result: time4 object created with hours: 0 and minutes: 0 (midnight - because of invalid input) Code: time3.setMinutes (68); Expected result: time3 object not changed because of invalid input. Code: System.out.println(time3.equals(time2)); Expected result: true printed to console Code: System.out.println(time 3); // calls time3.toString() automatically. Expected result: 14:45 printed to console Code: Expected result: 2:45 PM printed to console 2 System.out.println(time3.get12Hour Time()); O 2
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education