银行家算法JAVA实现--实验3

银行家算法JAVA实现--实验3,第1张

银行家算法JAVA实现--实验3 1.创建一个进程类Process
                                  ---------制作不易,看到即是鼓励
                                  加油!!!!
public class Process {
    int A;
    int B;
    int C;

    String name;

    private int sign=0;



    public Process(int a, int b, int c, String name) {
        A = a;
        B = b;
        C = c;
        this.name = name;

    }

    public int getSign() {
        return sign;
    }

    public void setSign(int sign) {
        this.sign = sign;
    }

    @Override
    public String toString() {
        return "Process{" +
                "A=" + A +
                ", B=" + B +
                ", C=" + C +
                ", name='" + name + ''' +
                ", sign=" + sign +
                '}';
    }
}

2.主方法

资源的数量是可以添加的,这个类可以改变

public class Bank {
    
    public boolean compareProcess(Process a, Process b){
        boolean fage=false;
        if(a.A>=b.A){
            if(a.B>=b.B){
                if(a.C>=b.C){
                    fage=true;
                }
            }
        }
        return fage;
    }

    
    public Process addProcess(Process a,Process b,Process c){
        a.A=b.A+c.A;
        a.B=b.B+c.B;
        a.C=b.C+c.C;
        return a;
    }



    
    public static void main(String[] args) {
        //已经分配
        Process p0=new Process(0,1,0,"p0");
        Process p1=new Process(2,0,0,"p1");
        Process p2=new Process(3,0,2,"p2");
        Process p3=new Process(2,1,1,"p3");
        Process p4=new Process(0,0,2,"P4");

        //Need
        Process pN0=new Process(7,4,3,"pN0");
        Process pN1=new Process(1,2,2,"pN1");
        Process pN2=new Process(6,0,0,"pN2");
        Process pN3=new Process(0,1,1,"pN3");
        Process pN4=new Process(4,3,1,"pN4");

        //Available
        Process pc=new Process(3,3,2,"pc");


        Process [][] list={{p0,pN0,},{p1,pN1},{p2,pN2},{p3,pN3},{p4,pN4}};

        Bank bank=new Bank();


        for (int i=0;i					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5079054.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存