Advertisement
jaVer404

level13.lesson11.home05

May 24th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.javarush.test.level13.lesson11.home05;
  2.  
  3. /* Neo
  4. 1. Реализовать интерфейс DBObject в классе User.
  5. 2. Реализовать метод initializeIdAndName так, чтобы программа работала и выводила на экран "User has name Neo, id = 1".
  6. 3. Метод toString и метод main менять нельзя.
  7. 4. Подумай, что должен возвращать метод initializeIdAndName в классе User.
  8. */
  9.  
  10. public class Solution
  11. {
  12.     public static void main(String[] args) throws Exception
  13.     {
  14.         System.out.println(Matrix.NEO);
  15.     }
  16.  
  17.  
  18.     static class Matrix
  19.     {
  20.        public static DBObject NEO = new User().initializeIdAndName(1, "Neo");
  21.     }
  22.  
  23.     interface DBObject
  24.     {
  25.         DBObject initializeIdAndName(long id, String name);
  26.     }
  27.  
  28.     static class User implements DBObject
  29.     {
  30.         long id;
  31.         String name;
  32.  
  33.         @Override
  34.         public String toString()
  35.         {
  36.             return String.format("User has name %s, id = %d", name, id);
  37.         }
  38.         public DBObject initializeIdAndName(long id, String name) {
  39.             User user = new User();
  40.             user.id = id;
  41.             user.name = name;
  42.             return user;
  43.         }
  44.     }
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement