Java作业4-3

第一题

import java.util.Scanner;
public class Triangle {
    private double sideA;
    private double sideB;
    private double sideC;
    public int flag;

    public Triangle(double sideA, double sideB, double sideC) {
        this.flag = this.checked_all_data(sideA, sideB, sideC);
    }

    public Triangle() {

    }

    public double getterA() {
        return this.sideA;
    }

    public double getterB() {
        return this.sideB;
    }

    public double getterC() {
        return this.sideC;
    }

    public void setterA(double data) {
        this.flag = check_one_data(data);
        this.sideA = this.flag == 1 ? data:this.sideA;
    }

    public void setterB(double data) {
        this.flag = check_one_data(data);
        this.sideB = this.flag == 1 ? data:this.sideA;
    }

    public void setterC(double data) {
        this.flag = check_one_data(data);
        this.sideC = this.flag == 1 ? data:this.sideA;
    }
    
    
    public int check_one_data(double data) {
        if (data >= Double.MAX_VALUE) {
            System.out.println("您这是算全国总面积呢");
            return 0;
        }

        if (data <= 0) {
            System.out.println("你是猪吧三角形三边长度还有不是正的");
            return 0;
        }
        return 1;
    }

    public int checked_all_data(double sideA, double sideB, double sideC) {

        if (sideA >= Double.MAX_VALUE || sideB >= Double.MAX_VALUE || sideB >= Double.MAX_VALUE) {
            System.out.println("您这是算全国总面积呢");
            return 0;
        }

        if (sideA <= 0 || sideB <= 0 || sideB <= 0) {
            System.out.println("你是猪吧三角形三边长度还有不是正的");
            return 0;
        }
        if ((sideA + sideB > sideC) && (sideA + sideC > sideB) && (sideC + sideB > sideA)) {
            this.sideA = sideA;
            this.sideB = sideB;
            this.sideC = sideC;
            return 1;
        }
        System.out.println("牛逼,带数学家");
        return 0;
    }

    public void modifySides(double sideA, double sideB, double sideC) {
        this.flag = this.checked_all_data(sideA, sideB, sideC);
    }

    public double Area() {
        double S = 1.0 / 4 * Math.sqrt((this.sideA + this.sideB + this.sideC) * (this.sideA + this.sideB - this.sideC)
                * (this.sideA - this.sideB + this.sideC) * (this.sideB - this.sideA + this.sideC));
        return S;
    }

    public void getArea() {
        
        if (this.flag == 1) {
            this.flag = this.checked_all_data(this.sideA, this.sideB, this.sideC);
        }
        
        if (this.flag == 0) {
            System.out.println("算不来,臭猪");
        } else {
            System.out.printf("你好棒!面积是:%.2f",this.Area());
        }
    }

    public static void main(String[] args) {

//      Scanner reader = new Scanner(System.in);
//
//      Triangle triangle = new Triangle(1, 1, 1);
//      int num = 0;
//      while (reader.hasNextDouble() && num <= 2) {
//          num++;
//          if (num == 1) {
//              triangle.setterA(reader.nextDouble());
//          } else if (num == 2) {
//              triangle.setterB(reader.nextDouble());
//          } else if (num == 3) {
//              triangle.setterC(reader.nextDouble());
//              break;
//          }
//      }
//      if (num < 3) {
//          System.out.println("连数字都不知道是啥了么,臭猪猪!!");
//      } else {
//          triangle.getArea();
//      }
        Triangle triangle = new Triangle(6, 6, 6);
        triangle.getArea();
    }
}



第二题

public class MainClass {
    public static void main(String[] args) {
        Employe employee1 = new Employe("小昕",5,6166);
        Employe employee2 = new Employe("小贤",9,5866);
        Employe employee3 = new Employe("小楼",15,5666);
        Hrstaff hrstaff = new Hrstaff("小陶");
        System.out.println("月初大家开始工作了~~~~~~~");
        employee1.work();
        employee2.work();
        employee3.work();
        hrstaff.work();
        System.out.println("月末发工资了~~~~~~~~~~~~~");
        hrstaff.pySalary(employee1);
        hrstaff.pySalary(employee2);
        hrstaff.pySalary(employee3);
        hrstaff.setSalary(6166);
        hrstaff.pySalary(hrstaff);
    }
}
package com.my_test._4_3_inclass2;

public class Hrstaff extends Employe {

    public Hrstaff() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Hrstaff(String name) {
        super(name,5,5000);
        // TODO Auto-generated constructor stub
    }
    public void pySalary(Employe employee) {
        int level = employee.getLevel();
        if(level>=1 && level<=5) System.out.println(employee.getName()+"的薪水是:"+ (employee.getSalary()+500));
        else if(level>=6 && level<=9) System.out.println(employee.getName()+"的薪水是:"+(employee.getSalary()+800));
        else if(level>=10 && level<=15) System.out.println(employee.getName()+"的薪水是:"+(employee.getSalary()+1000));
        else System.out.println("不存在对应的职级,无法发放额外浮动薪水");
    }
}


public class Employe {
    private String name;
    private int level;
    private int salary;
    
    public Employe() {
        this.name = "员工";
        this.level = 1;
        this.salary = 100;
    }

    public Employe(String name, int level, int salary) {
        this.name = name;
        this.level = level;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }
    
    public void work() {
        System.out.println(this.name + "做好了本职工作!");
    }
    
}


你可能感兴趣的:(Java作业4-3)