If it is not explicitly told in following recipe, setting up services are described for Ubuntu 16.04 server, but applications are described for Ubuntu 16.04 and/or Lubuntu 16.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

7. Abstract classes and Interfaces

Tasks

General info

  1. Review presentation Abstract classes and Interfaces
      
  2. Review notes about practical exercise
      
  3. Investigate jtm.activity06 package

Create Human class

Create Human class which implements Humanoid interface:

  1. Right-click on package main.java.jtm.activity06 and select New — Class
  2. Enter class name: Human
  3. Press Add.. in interfaces section and select Humanoid in main.java.jtm.activity06 package
  4. For section Which method stubs would you like to create? select Inherited abstract methods
  5. Press Finish

Create Martian class

Create Martian class, which implements Humanoid, Alien and Cloneable interfaces:

  1. Right-click on package main.java.jtm.activity06 and select New — Class
  2. Enter class name: Martian
  3. Press Add.. in interfaces section and select:
    1. Humanoid from main.java.jtm.activity06 package,
    2. Alien from main.java.jtm.activity06 package,
    3. Cloneable from java.lang package.
  4. For section Which method stubs would you like to create? select Inherited abstract methods
  5. Press Finish

Implement methods of Martian and Human classes

Implement methods according to the required logic, which is described in interface definitions and expected results from unit tests.

error Notes:

  1. When Humanoid is hungry, it eats and gains weight. If Alien eats Humanoid it kills it.
    1. Implementation of Humanoid eat() should accept Integer, but implementation of Alien eat() should accept Object.
  2. When Humanoid vomits, it loses weight of eaten item.
    1. Human vomit() only Integer, but Alien vomit any Object.
  3. When clone() is called for Martian, its structure should be cloned recursively for content of all stomaches. You can do it by implementing internal method clone(Object) like this:

    /*
     * Implementation of Object clone() method for Cloneable interface
     * @see https://docs.oracle.com/javase/7/docs/api/java/lang/Cloneable.html
     */
    @Override
        public Object clone() throws CloneNotSupportedException {
        return clone(this);
    }

    private Object clone(Object current) {
        // TODO implement cloning of current object
        // and its stomach
    }
  4. Implement toString() method for Human and Martian classes in following format:

    @Override
    public String toString() {
    return "ClassName: " + weight + " [" + stomach + "]";
    }

    where ClassName is Human for human and Martian for martian.
    For example, if current object is martian and its stomach contains another martian and then human with 3 in its stomach, it should show:

    [Martian: 3 [Martian: 4 [Human: 5 [3]]]

Optional information


  
Tags:
Created by Valdis Vītoliņš on 2020-05-28 13:55
Last modified by Valdis Vītoliņš on 2020-05-28 13:58
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License