/**
An interface for methods that return
the perimeter and area of an object.
@author Frank M. Carrano
@version 4.0
*/
public interface Measurable
{
/** Gets the perimeter.
@return The perimeter. */
public double getPerimeter();
/** Gets the area.
@return The area. */
public double getArea();
} // end Measurable
/**
An interface for a class of names.
@author Frank M. Carrano
@version 4.0
*/
public interface NameInterface
{
public void setName(String firstName, String lastName);
public String getName();
public void setFirst(String firstName);
public String getFirst();
public void setLast(String lastName);
public String getLast();
public void giveLastNameTo(NameInterface aName);
public String toString();
} // end NameInterface
/**
A class that represents a circle.
@author Frank M. Carrano
@version 4.0
*/
public class Circle implements Circular
{
private double radius;
public void setRadius(double newRadius)
{
radius = newRadius;
} // end setRadius
public double getRadius()
{
return radius;
} // end getRadius
public double getArea()
{
return Math.PI * radius * radius;
} // end getArea
} // end Circle
/**
An interface for objects that have a radius.
@author Frank M. Carrano
@version 4.0
*/
public interface Circular
{
public void setRadius(double newRadius);
public double getRadius();
} // end Circular
/**
@author Frank M. Carrano
@version 4.0
*/
public interface Callable extends Nameable
{
public void come(String petName);
} // end Callable
/**
@author Frank M. Carrano
@version 4.0
*/
public interface Capable
{
public void hear();
public void respond();
} // end Capable
/**
@author Frank M. Carrano
@version 4.0
*/
public interface Trainable extends Callable, Capable
{
public void sit();
public void speak();
public void lieDown();
} // end Trainable
/**
An interface of public constants.
@author Frank M. Carrano
@version 4.0
*/
public interface ConstantsInterface
{
public static final double INCHES_PER_CENTIMETER = 0.39370079;
public static final double FEET_PER_METER = 3.2808399;
public static final double MILES_PER_KILOMETER = 0.62137119;
} // end ConstantsInterface
/**
@author Frank M. Carrano
@version 4.0
*/
public class Demo implements ConstantsInterface
{
public static void main(String[] args)
{
System.out.println(FEET_PER_METER);
System.out.println(ConstantsInterface.MILES_PER_KILOMETER);
} // end main
} // end Demo
标签:chapter,end,String,double,void,算法,interface,数据结构,public
From: https://blog.51cto.com/u_15892225/11993459