Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
package cloude;

import java.io.*;
import java.lang.management.*;
import java.text.*;
import java.util.*;


public class Cloude6 {

    static int dir, row = 10, col = 12, r = -1;
    static int dcr[][];
    static int dc[][] = {{8, 7, 5, 7, 8, 5, 9, 7, 8, 6, 6, 7}, {5, 7, 9, 5, 4, 8, 4, 9, 4, 8, 8, 5}, 
                         {9, 6, 8, 7, 9, 5, 6, 9, 7, 6, 7, 7}, {8, 7, 4, 3, 6, 3, 2, 6, 5, 4, 6, 4}, 
                         {6, 3, 2, 4, 7, 8, 5, 3, 5, 5, 4, 5}, {8, 6, 9, 7, 9, 7, 5, 8, 8, 7, 8, 7}
                        };
    static DecimalFormat df = new DecimalFormat("#.##");
    static double fcr[][];
    static int low, max, row1;
    static ArrayList l1 = new ArrayList();
    static ArrayList low1 = new ArrayList();
    static HashSet i1 = new HashSet();
    static ArrayList i2 = new ArrayList();
    static int g = 0;
    static ArrayList fuzzy = new ArrayList();
    static int user, g1 = 0;
    static double fin[];

    public static void main(String[] args) {
        ThreadMXBean TMB = ManagementFactory.getThreadMXBean();
        long time = new Date().getTime() * 1000000;
        long cput = TMB.getCurrentThreadCpuTime();
        double cpuperc = -1;
        long lStartTime = new Date().getTime();
        try {
            getDirectory();
            for (int p = 1; p <= dir; p++) {
                l1.removeAll(l1);
                low1.removeAll(low1);
                i1.removeAll(i1);
                i2.removeAll(i2);
                
                showValues();
                for (int j = 0; j < col; j++) {
                    findLowest(j);
                }
                System.out.println(l1);
                for (int j = 0; j < col; j++) {
                    showEquals(j);
                }
                i2.addAll(i1);
                System.out.println(i2);
                selectedMatrix();
                showUpdated();
                fcr = new double[row1][col];
                for (int i = 0; i < col; i++) {
                    findMax(i);
                }
                showFinal();
                for (int i = 0; i < row1; i++) {

                    additionFcr(i);
                }
            }

            System.out.println(fuzzy);
            usersInput();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        if (TMB.isThreadCpuTimeSupported()) {
           
            cpuperc = (TMB.getCurrentThreadCpuTime() - cput) / (new Date().getTime() * 1000000.0 - time) * 100;
            System.out.println("Cpu Utilization: " + cpuperc);
        } else {
            cpuperc = -2;
        }

        long lEndTime = new Date().getTime(); //end time

        long difference = lEndTime - lStartTime; //check different

        System.out.println("Elapsed milliseconds: " + difference);
    }

    public static void usersInput() throws IOException {
        user=5;
        System.out.println("Enter the Number of Users" + user );
   
        for (int x = 1; x <= user; x++) {
            int d = fuzzy.size();
            fin = new double[d];
            Object ob[] = fuzzy.toArray();
            for (int a = 0; a < ob.length; a++) {
                String str = ob[a].toString();
                fin[a] = Double.valueOf(str).doubleValue();
            }
            double ss = fin[0];
            for (int i = 0; i < ob.length; i++) {
                if (ss < fin[i]) {
                    ss = fin[i];
                    g1 = i;
                }
            }
            System.out.println("User " + x + "  =  " + ss);
            fuzzy.remove(ss);
            System.out.println(fuzzy);
        }
    }

    public static void additionFcr(int a) throws IOException {
        double x = 0;
        for (int j = 0; j < col; j++) {
            x += fcr[a][j];
        }
        fuzzy.add(x);
        System.out.println("This is The Final Fuzzy Value " + a + " = " + df.format(x) + "\t");
    }

    public static void showFinal() throws IOException {
        System.out.println("Information About CSP & Parameters");
        for (int i = 0; i < row1; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(df.format(fcr[i][j]) + "\t\t");
            }
            System.out.println();
        }
    }

    public static void findMax(int a) throws Exception {
        max = dcr[0][a];
        for (int i = 0; i < row1; i++) {
            if (max < dcr[i][a]) {
                max = dcr[i][a];
            }
        }
        System.out.println("The Best Service Provided in col " + a + " = " + max);

        for (int j = 0; j < row1; j++) {
            fcr[j][a] = (float) dcr[j][a] / max;
        }

    }

    public static void showUpdated() throws IOException {
        System.out.println("Information About CSP & Parameters");
        System.out.println("The Twelve Non-funtional Parameters like Virtualization, Application Security, Data Operation, Legal Issues,"
                + "Risk Management, Compliance and Audit, Interperability and Portability, "
                + "Business Continuity and Disaster Recovery, Data Center Operations, Incident Resposne, "
                + "Key Management, Identity Entitlement and Access Management ");
        for (int i = 0; i < row1; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(dcr[i][j] + "\t");
            }
            System.out.println();
        }
    }

    public static void selectedMatrix() throws IOException {
        int a = i1.size();
        int x = 0, n = 0, w = 0;
        row1 = row - a;
        dcr = new int[row1][col];
        outer:
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                for (int k = 0; k < a; k++) {
                    n = (Integer) i2.get(k);
                    if (n == i) {
                       
                        continue outer;
                    }
                }
                dcr[x][j] = dc[i][j];
            }
            x++;
        }
    }

    public static void showEquals(int a) throws IOException {
        Object x = low1.get(a);
        for (int i = 0; i < row; i++) {
            if (dc[i][a] == x) {
                i1.add(i);
            }
        }
    }

    public static void findLowest(int a) throws Exception {
        low = dc[0][a];
        for (int i = 0; i < row; i++) {
            if (low > dc[i][a]) {
                low = dc[i][a];
                r = i;
            }
        }
        if (r == -1) {
            r = 0;
        }
        if (r != -1) {
            l1.add(r);
            low1.add(low);
        }
        r = -1;
        System.out.println("The Thrashold Value in col " + ++a + " = " + low);
    }

    public static void showValues() throws IOException {
        System.out.println("Information About CSP & Parameters");
         System.out.println("The Twelve Non-funtional Parameters like Virtualization, Application Security, Data Operation, Legal Issues,"
                + "Risk Management, Compliance and Audit, Interperability and Portability, "
                + "Business Continuity and Disaster Recovery, Data Center Operations, Incident Resposne, "
                + "Key Management, Identity Entitlement and Access Management ");
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                System.out.print(dc[i][j] + "\t");
            }
            System.out.println();
        }
    }


What I have tried:

Java
if (dc[i][a] == x)


This statement shown an error bad operand types for operating system ==. first type int; second type object.
Posted
Updated 19-Mar-18 7:44am
v3
Comments
Leo Chapiro 19-Mar-18 11:59am    
Apparently says this error message that you can't compare an "int" to an "object" so what?

1 solution

The error message is pretty clear: you can't compare an Object with an int.
If you are sure the low1 collection actually contain ints, then cast it properly, e.g.
int x = (int)low1.get(a);
for (int i = 0; i < row; i++) {
  if (dc[i][a] == x) {
    i1.add(i);
  }
}

By the way it would better using the generic collections (that is ArrayList<E>[^]).
 
Share this answer
 
v3
Comments
Member 11104762 20-Mar-18 2:13am    
int x = (int)low1.get(a); by using this error is object cannot be converted into int.
CPallini 20-Mar-18 4:52am    
What version of Java are you using?
Member 11104762 20-Mar-18 2:59am    
Thank u sir by using ArrayList sloved this error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900