第一题
import java. awt. * ;
import java. awt. geom. AffineTransform ;
import java. awt. geom. PathIterator ;
import java. awt. geom. Point2D ;
import java. awt. geom. Rectangle2D ;
import java. util. Scanner ;
public static void main ( String [ ] args) { Scanner scanner = new Scanner ( System . in) ; double radius = scanner. nextDouble ( ) ; double length = scanner. nextDouble ( ) ; double width = scanner. nextDouble ( ) ; Circle circle = new Circle ( radius) ; Rectangle rectangle = new Rectangle ( length, width) ; System . out. println ( circle. getAcreage ( ) ) ; System . out. print ( rectangle. getAcreage ( ) ) ; } abstract class shape{ public abstract void getAcreage ( ) ;
} class Circle implements Shape { private double radius; public Circle ( ) { } public Circle ( double radius) { this . radius = radius; } public double getRadius ( ) { return radius; } public void setRadius ( double radius) { this . radius = radius; } @Override public java. awt. Rectangle getBounds ( ) { return null ; } @Override public Rectangle2D getBounds2D ( ) { return null ; } @Override public boolean contains ( double x, double y) { return false ; } @Override public boolean contains ( Point2D p) { return false ; } @Override public boolean intersects ( double x, double y, double w, double h) { return false ; } @Override public boolean intersects ( Rectangle2D r) { return false ; } @Override public boolean contains ( double x, double y, double w, double h) { return false ; } @Override public boolean contains ( Rectangle2D r) { return false ; } @Override public PathIterator getPathIterator ( AffineTransform at) { return null ; } @Override public PathIterator getPathIterator ( AffineTransform at, double flatness) { return null ; } public double getAcreage ( ) { return 3.1415926 * getRadius ( ) * getRadius ( ) ; }
} class Rectangle implements Shape { private double length; private double width; public double getLength ( ) { return length; } public void setLength ( double length) { this . length = length; } public double getWidth ( ) { return width; } public void setWidth ( double width) { this . width = width; } public Rectangle ( ) { } public Rectangle ( double length, double width) { this . length = length; this . width = width; } @Override public java. awt. Rectangle getBounds ( ) { return null ; } @Override public Rectangle2D getBounds2D ( ) { return null ; } @Override public boolean contains ( double x, double y) { return false ; } @Override public boolean contains ( Point2D p) { return false ; } @Override public boolean intersects ( double x, double y, double w, double h) { return false ; } @Override public boolean intersects ( Rectangle2D r) { return false ; } @Override public boolean contains ( double x, double y, double w, double h) { return false ; } @Override public boolean contains ( Rectangle2D r) { return false ; } @Override public PathIterator getPathIterator ( AffineTransform at) { return null ; } @Override public PathIterator getPathIterator ( AffineTransform at, double flatness) { return null ; } public double getAcreage ( ) { return getLength ( ) * getWidth ( ) ; }
}
第二题
public static void main ( String [ ] args) { Scanner scanner = new Scanner ( System . in) ; String name = scanner. next ( ) ; String birth = scanner. next ( ) ; String position = scanner. next ( ) ; double salary = scanner. nextDouble ( ) ; Salary employee = new Salary ( name, birth, position, salary) ; employee. introduction ( ) ; }
class Employee { private String name; private String birth; private String position; public Employee ( ) { } public Employee ( String name, String birth, String position) { this . name = name; this . birth = birth; this . position = position; } public String getName ( ) { return name; } public void setName ( String name) { this . name = name; } public String getBirth ( ) { return birth; } public void setBirth ( String birth) { this . birth = birth; } public String getPosition ( ) { return position; } public void setPosition ( String position) { this . position = position; }
} class Salary extends Employee { private double salary; public double getSalary ( ) { return salary; } public void setSalary ( double salary) { this . salary = salary; } public Salary ( String name, String birth, String position, double salary) { super ( name, birth, position) ; this . salary = salary; } public void introduction ( ) { System . out. println ( "员工姓名:" + getName ( ) + " 出生年月:" + getBirth ( ) + " 职位:" + getPosition ( ) + " 薪水:" + getSalary ( ) ) ; }
}
第三题
public static void main ( String [ ] args) { Animal cat = new Cat ( ) ; Animal dog = new Dog ( ) ; cat. eat ( ) ; cat. work ( ) ; dog. eat ( ) ; dog. work ( ) ; } abstract class Animal { abstract void eat ( ) ; abstract void work ( ) ;
}
class Cat extends Animal { @Override public void eat ( ) { System . out. println ( "吃鱼" ) ; } @Override public void work ( ) { System . out. println ( "抓老鼠" ) ; } } class Dog extends Animal { @Override public void eat ( ) { System . out. println ( "吃骨头" ) ; } @Override public void work ( ) { System . out. println ( "看家" ) ; } }