Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Computer Science 223 Laboratory Exercise: Inheritance in Java Inheritance in Java This laboratory exercise provides practice defining an interface in Java, implementing that interface through a Java class, and then extending that class. Example: Lists of Integers (as described during class) In class, we discussed unordered and ordered lists as an example of interfaces and inheritance. The following files (found in directory ~walker/java/lists/) provide some details: ListNode.java provides definitions for a simple node. List.java defines a very simple collection of list operations. SimpleList.java implements List.java, adding a few additional functions. OrderedList.java extends SimpleList.java by changing the insert method to maintain an ordered list. These files review various details of interfaces, implementation, and inheritance, and you may wish to use these as models for the latter parts of this lab. Copy these files to your account, compile them (in the order listed above), and then run both SimpleList and OrderedList. Compare the methods defined in List.java with those implemented in SimpleList.java. Be sure all methods specified in List.java are implemented. Does SimpleList.java implement any additional public or private methods? If so, identify which new methods are defined. Temporarily delete the isin method from SimpleList.java and recompile. Explain any error message(s) you encounter. (When you are done with this part, restore SimpleList.java to its original form.) Review the testing section of SimpleList.java, and describe a likely testing strategy that led to this sequence. Review OrderedList.java, and explain how the insert method works. While testing in SimpleList.java includes printing after each list insertion, testing in OrderedList.java performs a sequence of insertions before printing. Do you think this abbreviated testing for OrderedList.java is sufficiently complete? Briefly explain your answer. Appointments During the semester, we have considered a hierarchy of appointments as part of our class project: Using the above list programs as examples, one way to translate the appointment hierarchy into Java code would be to utilize interfaces and inheritance. In this hierarchy, Appointment could be an interface, AvailableAppt and UnchangeableAppt implementations, and the remaining three classes could extend AvailableAppt. While folks working on appointment classes will need to work out the actual labs, this lab provides practice with some three operations: constructor, make an appointment, and print the appointment on the system's output. A sample interface is given in Appointment.java. (This and other class files for the appointment hierarchy in this lab may be found in directory ~walker/java/schedule/.) A simple implementation of Appointment.java is given by UnchangeableAppt.java. In this implementation, only the owner can adjust appointment data. Also, printing content depends upon the nature of the user. Copy Appointment.java and UnchangeableAppt.java to your account, compile these classes, and run UnchangeableAppt.java. Review the code to be sure you know how it runs. Write a class AvailableAppt that implements the Appointment for appointments for which folks might sign up for meetings. (Each of these methods might be patterned on UnchangeableAppt, although editing of some text in printing may be appropriate.) Compile and test AvailableAppt. Implement classes WalkInAppt, SignUpAppt, and RestrictedAppt. These classes may inherit the printing method from AvailableAppt. Making appointments should proceed according to the following table. Class Owner Logged-in User Unknown User WalkInAppt Can make changes Told to drop in Told to drop in SignUpAppt Can make changes Can sign up if comment field is null or says "office hours"; otherwise told time taken Told e-mail request will be sent if comment field is null or says "office hours"; otherwise told time taken RestrictedAppt Can make changes Told e-mail request will be sent Told e-mail request will be sent In your implementation (for now), you need not try to actually send e-mail. Instead, just make the appointment (assuming the owner will approve the request), but return a message indicating e-mail was sent. Test your implementations individually and thoroughly. This document is available on the World Wide Web as http://www.walker.cs.grinnell.edu/courses/223.sp02/lab-java-inheritance.html created March 14, 2002 last revised March 15, 2002 For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.