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());
    }

    }

  • 相关阅读:
    JavaWeb网上图书商城完整项目--day02-3.regist页面输入框失去焦点进行校验
    JavaWeb网上图书商城完整项目--day02-2.regist页面输入框得到焦点隐藏label
    JavaWeb网上图书商城完整项目--27.注册页面之注册按钮图片切换实现
    关于js中值的比较规则问题
    说说null和undefined的那些事
    对象、数组转换字符串
    函数的形参与实参
    switch判断注意点
    删除数组值
    数组的一个强大函数splice,[增,删,改]
  • 原文地址:https://www.cnblogs.com/hell/p/5369237.html
Copyright © 2011-2022 走看看