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

Posted MR.SEEEKS

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
    }


}

以上是关于Java基础黑马程序员教材案例4-5..图形的面积与周长计算程序案例4-7经理与员工工资代码的主要内容,如果未能解决你的问题,请参考以下文章

Java基础黑马程序员教材 案例3-2银行存取款,3-4学生投票代码详解

java基础案例教程黑马程序员案例答案,真香

MySQL常用图形管理工具 | 黑马程序员

黑马程序猿——————java基础

黑马程序员Java教程学习笔记

黑马程序员Java教程学习笔记