Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package customer;
  6.  
  7. /**
  8.  *
  9.  * @author hw003669
  10.  */
  11. public class Customer {
  12.  
  13.         private String name;
  14.         private Address homeAddress, workAddress;
  15.  
  16.         public String getName(){
  17.  
  18.         return this.name;
  19.         }
  20. //        public class Address {
  21. //
  22. //            private int number;
  23. //            private String street;
  24. //
  25. //            public Address(int no, String street) {
  26. //                number = no;
  27. //                this.street = street;
  28. //            }
  29. //
  30. //            public String toString() {
  31. //                return "the address of " + name + " is " + number + " " + street;
  32. //            }
  33. //        }
  34.  
  35. //            private class Address {
  36. //
  37. //            private int number;
  38. //            private String street;
  39. //
  40. //            public Address(int no, String street) {
  41. //                number = no;
  42. //                this.street = street;
  43. //            }
  44. //
  45. //            public String toString() {
  46. //                return "the address of " + name + " is " + number + " " + street;
  47. //            }
  48. //        }
  49.  
  50.             public static class Address {
  51.  
  52.             private int number;
  53.             private String street;
  54.  
  55.             public Address(int no, String street) {
  56.                 number = no;
  57.                 this.street = street;
  58.             }
  59.  
  60.             public String toString() {
  61.                 return "the address of " + name + " is " + number + " " + street;
  62.             }
  63.             // none static variable cannot be referenced from a static context
  64.         }
  65.  
  66.         public Customer(String name, int houseNumber, String homeStreet) {
  67.             this.name = name;
  68.             homeAddress = new Address(houseNumber, homeStreet);
  69.         }
  70.  
  71.         public String toString(){
  72.  
  73.             if (homeAddress == null){
  74.              return "Home Address is null";
  75.             }
  76.             if (workAddress == null){
  77.             return "work address is null";
  78.             }
  79.  
  80.           return name + homeAddress + workAddress;
  81.     }
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement