About class member access illustrated in fig08_03: o Test this example code and explain why the program cannot get o Make necessary changes on the test class MemberAccessTest to i.e., initialize the Timel object time with the same provided value the hour-minute-second values through the object time. o Take a screenshot of your updated code segment in the test class (not the output of the execution). o You may no do any changes on the class Timel.

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

// Fig. 8.3: MemberAccessTest.java
// Private members of class Time1 are not accessible.
public class MemberAccessTest {
public static void main(String[] args) {
Time1 time = new Time1(); // create and initialize Time1 object

time.hour = 7; // error: hour has private access in Time1
time.minute = 15; // error: minute has private access in Time1
time.second = 30; // error: second has private access in Time1
}
}

 

 

// Fig. 8.1: Time1.java
// Time1 class declaration maintains the time in 24-hour format.

public class Time1 {
private int hour; // 0 - 23
private int minute; // 0 - 59
private int second; // 0 - 59

// set a new time value using universal time; throw an
// exception if the hour, minute or second is invalid
public void setTime(int hour, int minute, int second) {
// validate hour, minute and second
if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 ||
second < 0 || second >= 60) {
throw new IllegalArgumentException(
"hour, minute and/or second was out of range");
}

this.hour = hour;
this.minute = minute;
this.second = second;
}

// convert to String in universal-time format (HH:MM:SS)
public String toUniversalString() {
return String.format("%02d:%02d:%02d", hour, minute, second);
}

// convert to String in standard-time format (H:MM:SS AM or PM)
public String toString() {
return String.format("%d:%02d:%02d %s",
((hour == 0 || hour == 12) ? 12 : hour % 12),
minute, second, (hour < 12 ? "AM" : "PM"));
}
}

About class member access illustrated in fig08_03:
o Test this example code and explain why the program cannot get compiled.
o Make necessary changes on the test class MemberAccessTest to make it work,
i.e., initialize the Timel object time with the same provided values and then print
the hour-minute-second values through the object time.
o Take a screenshot of your updated code segment in the test class for submission
(not the output of the execution).
You may no do any changes on the class Timel.
Transcribed Image Text:About class member access illustrated in fig08_03: o Test this example code and explain why the program cannot get compiled. o Make necessary changes on the test class MemberAccessTest to make it work, i.e., initialize the Timel object time with the same provided values and then print the hour-minute-second values through the object time. o Take a screenshot of your updated code segment in the test class for submission (not the output of the execution). You may no do any changes on the class Timel.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
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
  • SEE MORE 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