Java基础黑马程序员教材案例4-5..图形的面积与周长计算程序、案例4-7经理与员工工资代码

一、 4-5图形的面积与周长计算程序

import java.util.Scanner;
import java.math.*;
public class areaCount {
     
    public  void menu () {
     
        System.out.println ("输入1计算圆的周长、面积");
        System.out.println ("输入2计算长方形的周长、面积");
        Scanner scanner = new Scanner (System.in);
        int choice = scanner.nextInt ();
        if (choice == 1) {
     
            yuan yuan = new yuan ();
            System.out.println ("输入圆的周长");
            double r = scanner.nextDouble ();
            yuan.areaCount ( r);
            yuan.zhouchangCount (r);
        } else if (choice == 2) {
     
            changfangxing changfangxing = new changfangxing ();
            System.out.println ("依次输入长方形的长和宽");
            double  length=scanner.nextDouble ();
            double width=scanner.nextDouble ();
            changfangxing.areaCount (length,width);
            changfangxing.zhouchangCount (length,width);
        }
    }
    public static void main (String[] args) {
     
      areaCount areaCount=new areaCount ();
      areaCount.menu ();
    }


    abstract class graph {
     
        double area = 0;
        double zhouchang = 0;
    }

    class yuan extends graph {
     
        double r = 0;

        public void areaCount (double r) {
     
            area = 3.14 * (r * r);
            System.out.print ("面积是:");
            System.out.println (area);
        }

        public void zhouchangCount (double r) {
     
            zhouchang = 2 * 3.14 * r;
            System.out.print ("周长是:");
            System.out.println (zhouchang);
        }
    }

    class changfangxing extends graph {
     
        double length = 0;
        double width = 0;

        public void areaCount (double length,double width) {
     
            area = length * width;
            System.out.print ("面积是:");
            System.out.println (area);
        }

        public void zhouchangCount (double length,double width) {
     
            zhouchang = (length + width) * 2;
            System.out.print ("周长是:");
            System.out.println (zhouchang);
        }
    }
}


二、案例4-7经理与员工工资代码

public class salary {
     
    public static void main (String[] args) {
     
        jingli guan=new jingli ();
        guan.salary=10000000;
        normal zjw=new normal ();
        zjw.salary=100000000;
        guan.work ();
        zjw.work ();
        System.out.println ("经理工资"+guan.salary);
        System.out.println ("普通员工工资"+zjw.salary);
    }
}
class  Person{
     
    String name;
    String address;
    int id;
    int salary;
    int age;
    public  void work(){
     

    }
}
class jingli extends Person{
     
    @Override
    public  void  work(){
     
        salary+=0.2*salary;
    }


}
class normal extends Person{
     
    @Override
    public  void work(){
     
        salary+=0.1*salary;
    }


}

你可能感兴趣的