Java Study Notes 17 (Object-Oriented 10: Comprehensive cases) and java Study Notes

Source: Internet
Author: User
Tags class manager

Java Study Notes 17 (Object-Oriented 10: Comprehensive cases) and java Study Notes

At the end of the object-oriented topic

 

Combined with the previous articles, I used many Object-Oriented Knowledge and made a simple case:

Hotel case:

 

Package hotel;/** hotel staff class * Common Features of employees: name, Employee id, Working Method */public class Employee {private String name; private String id; // note: in actual development, you need to provide the user with two sets of constructor // a set of null parameters, one with the parameter public Employee () {} public Employee (String name, String id) {this. name = name; this. id = id;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getId () {return id;} public void setId (String id) {this. id = id ;}}

 

Package hotel;/** hotel VIP service * chefs and waiters */public interface VIP {public abstract void services ();}

 

Package hotel;/** the Chef class * inherits the Employee class and implements the VIP interface */public class Chef extends Employee implements VIP {public Chef () {super ();} public Chef (String name, String id) {super (name, id);} public void work () {System. out. println ("chef in cooking");} public void services () {System. out. println ("exquisite dishes for VIP ");}}

 

Package hotel;/** attendant class: * inherits the Employee class and implements the VIP interface */public class Waiter extends Employee implements VIP {public Waiter () {super ();} public Waiter (String name, String id) {super (name, id);} public void work () {System. out. println ("Waiter Serving");} public void services () {System. out. println ("VIP special service for waiters ");}}

 

Package hotel;/** defines the Manager class: * inherits the Employee class, and does not have the VIP function * has its own bonus attribute */public class Manager extends Employee {public Manager () {super ();} public Manager (String name, String id, double money) {super (name, id); this. money = money;} private double money; public void work () {System. out. println ("Manager in hotel management ");}}

 

 

Package hotel; import javax. swing. text. changedCharSetException; public class Test {public static void main (String [] args) {// create a Manager, two waiters, two chefs Manager m1 = new Manager ("James ", "Manager 001", 6666.66); m1.work (); Waiter w1 = new Waiter ("Xiao Ming", "Waiter 001"); Waiter w2 = new Waiter ("xiao hong ", "attendant 002"); w1.work (); w1.services (); w2.work (); w2.services (); Chef c1 = new Chef ("Li Si", "Chef 001 "); chef c2 = new Chef ("Wang Wu", "Chef 002"); c1.work (); c1.services (); c2.work (); c2.services ();}/* output: the manager is managing the hotel waiter serving the VIP. The waiter is a VIP special service. The waiter is a VIP special service. The cook is cooking the VIP */

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.