zoukankan      html  css  js  c++  java
  • 作业

    class Employer{
    private String name;
    private int age;
    private char sex;
    public Employer(){
    }
    public Employer(String name,int age,char sex){
    super();
    this.name=name;
    this.age=age;
    this.sex=sex;
    }
    public String toString(){
    return "雇员姓名:"+this.name+" 年龄:"+this.age+
    " 性别:"+this.sex;
    }
    }
    class Manager extends Employer{
    private String job;
    private double income;
    public Manager(){
    }
    public Manager(String name,int age,char sex,String job,double income){
    super(name,age,sex);
    this.job=job;
    this.income=income;
    }
    public String toString(){
    return super.toString()+" 职位:"+this.job+" 年薪:"+this.income;
    }
    }
    class Staff extends Employer{
    private String dept;
    private double salary;
    public Staff(){
    }
    public Staff(String name,int age,char sex,String dept,double salary){
    super(name,age,sex);
    this.dept=dept;
    this.salary=salary;
    }
    public String toString(){
    return super.toString()+" 部门:"+this.dept+" 月薪:"+this.salary;
    }
    }
    public class per03 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Employer ea=new Manager("小刘",22,'男',"经理",100000.0);
    Employer eb=new Staff("小崔",23,'男',"销售",3000.0);
    System.out.println(ea);
    System.out.println(eb);
    }
    }

    abstract class Shape{
    public abstract double area();
    public abstract double perimeter();
    }
    class Rectangle extends Shape{
    private double wide;
    private double longs;
    public Rectangle(){
    }
    public Rectangle(double wide,double longs){
    super();
    this.wide=wide;
    this.longs=longs;
    }
    public double area(){
    return this.longs*this.wide;
    }
    public double perimeter(){
    return (this.longs +this.wide)*2;
    }
    }
    class Triangle extends Shape{
    private double edgea;
    private double edgeb;
    private double edgec;
    public Triangle(){
    }
    public Triangle(double edgea,double edgeb,double edgec){
    super();
    this.edgea=edgea;
    this.edgeb=edgeb;
    this.edgec=edgec;
    }
    public double area(){
    return this.edgea*this.edgeb/2;
    }
    public double perimeter(){
    return this.edgea+this.edgeb+this.edgec;
    }
    }
    class Round extends Shape{
    private double radius;
    public Round(){
    }
    public Round(double radius){
    super();
    this.radius=radius;
    }
    public double area(){
    return this.radius*this.radius*Math.PI;
    }
    public double preimeter(){
    return this.radius*2*Math.PI;
    }
    @Override
    public double perimeter() {
    // TODO Auto-generated method stub
    return 0;
    }
    }
    public class per04 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Shape rectangle=new Rectangle(12.5,30.6);
    Shape triangle=new Triangle(12.4,30.2,40.3);
    Shape round=new Round(40.4);
    System.out.println("矩形面积:"+rectangle.area()+" 矩形周长:"+rectangle.perimeter());
    System.out.println("三角形面积:"+triangle.area()+" 三角形周长:"+triangle.perimeter());
    System.out.println("圆形面积:"+round.area()+" 圆形周长:"+round.perimeter());
    }

    }

  • 相关阅读:
    VMware VSAN 设计规则
    通过命令行给 XenServer 打补丁
    XenServer 根分区空间满的解决办法
    sftp命令不被识别
    windows cmd窗口提示“telnet”命令不能内部或外部命令,也不是可运行的程序
    Eclipse安装ModelGoon控件(ModelGoon控件反向生成UML)
    WINDOWS8.1安装ORACLE客户端及配置
    CentOs下安装maven
    centos下安装java8
    mono支持gb2312
  • 原文地址:https://www.cnblogs.com/hell/p/5369237.html
Copyright © 2011-2022 走看看