public static void main(String args[]) throws Exception {

    String age, income, student, credit;
    BufferedReader bri = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Enter age(<=30,31-40,>40):");
    age = bri.readLine();

    System.out.println("Enter income(high,medium,low):");
    income = bri.readLine().toLowerCase();

    System.out.println("Enter student(yes/no):");
    student = bri.readLine().toLowerCase();

    System.out.println("Enter credit:(fair,excellent)");
    credit = bri.readLine().toLowerCase();

    File f = new File("C:\\Users\\Nitish\\Downloads\\Bay\\data.txt");
    double no,
        yes,
        pyes,
        pno,
        agey,
        agen,
        incomey,
        incomen,
        studenty,
        studentn,
        credity,
        creditn,
        py,
        pn;
    no =
        yes =
            pyes =
                pno =
                    agey =
                        agen =
                            incomey =
                                incomen = studenty = studentn = credity = creditn = py = pn = 0.0;
    BufferedReader br = new BufferedReader(new FileReader(f));
    String st = "";

    st = br.readLine();
    String str[];
    while ((st = br.readLine()) != null) {
      System.out.println(st);
      str = st.split("\t");
      if (str[5].equals("no")) no++;
      else yes++;

      if ((str[5].equals("yes")) && (str[1].equals(age))) agey++;

      if ((str[5].equals("no")) && (str[1].equals(age))) agen++;

      if ((str[5].equals("yes")) && (str[2].equals(income))) incomey++;

      if ((str[5].equals("no")) && (str[2].equals(income))) incomen++;

      if ((str[5].equals("yes")) && (str[3].equals(student))) studenty++;

      if ((str[5].equals("no")) && (str[3].equals(student))) studentn++;

      if ((str[5].equals("yes")) && (str[4].equals(credit))) credity++;

      if ((str[5].equals("no")) && (str[4].equals(credit))) creditn++;
    }
    pyes = yes / (yes + no);
    pno = no / (yes + no);

    py = pyes * (agey / yes) * (incomey / yes) * (studenty / yes) * (credity / yes);
    pn = pno * (agen / no) * (incomen / no) * (studentn / no) * (creditn / no);

    java.text.DecimalFormat df = new java.text.DecimalFormat("#.####");

    System.out.println("Probability of Computer buyer = yes:" + df.format(py));
    System.out.println("Probability of Computer buyer = yes:" + df.format(pn));

    if (py > pn) {
      System.out.println("Computer buyer = yes");
    } else {
      System.out.println("Computer buyer = no");
    }
  }
Beispiel #2
0
  public String displayNONUTF() {
    List<BasicEmotion> sortedemotions = new ArrayList<BasicEmotion>(_components.size());
    String resultstring = "";

    // build ArrayList sorted by percentages

    for (BasicEmotion basicemotion : _components.keySet()) {
      if (sortedemotions.size() == 0 && _components.get(basicemotion) != 0) { // was >0
        sortedemotions.add(basicemotion);
      } else {
        boolean done = false;
        int index = sortedemotions.size();
        for (int i = 0; i < sortedemotions.size(); i++) {
          BasicEmotion sortedbasicemotion = sortedemotions.get(i);
          double current_perc = _components.get(basicemotion);
          double running_perc = _components.get(sortedbasicemotion);
          if (current_perc <= running_perc && done == false) {
            index = i;
            done = true;
          }
        }

        if (_components.get(basicemotion) != 0) // >0
        {
          sortedemotions.add(index, basicemotion);
        }
      }
    }

    for (BasicEmotion basicemotion : sortedemotions) {
      String symbol = "";
      if (basicemotion.getTheory() == EmotionTheory.PLUTCHIK) {
        PlutchikBasicEmotion pbe = (PlutchikBasicEmotion) basicemotion;
        switch (pbe) {
          case JOY:
            symbol = "joy";
            break;
          case FEAR:
            symbol = "fear";
            break;
          case SADNESS:
            symbol = "sad";
            break;
          case SURPRISE:
            symbol = "!";
            break;
          case ANTICIPATION:
            symbol = "anticip";
            break;
          case TRUST:
            symbol = "trust";
            break;
          case ANGER:
            symbol = "anger";
            break;
          case DISGUST:
            symbol = "disgust";
            break;
        }
      }
      if (basicemotion.getTheory() == EmotionTheory.EKMAN) {
        EkmanBasicEmotion pbe = (EkmanBasicEmotion) basicemotion;
        switch (pbe) {
          case AMUSEMENT:
            symbol = "amus.";
            break;
          case ANGER:
            symbol = "ang.";
            break;
          case CONTEMPT:
            symbol = "contempt";
            break;
          case CONTENTMENT:
            symbol = "contentm.";
            break;
          case DISGUST:
            symbol = "disg.";
            break;
          case EMBARASSMENT:
            symbol = "emb.";
            break;
          case EXCITEMENT:
            symbol = "exc.";
            break;
          case FEAR:
            symbol = "fear";
            break;
          case GUILT:
            symbol = "guilt";
            break;
          case PRIDEINACHIEVEMENT:
            symbol = "pr.ach.";
            break;
          case RELIEF:
            symbol = "rel.";
            break;
          case SADNESSDISTRESS:
            symbol = "sadn.dis.";
            break;
          case SATISFACTION:
            symbol = "sat.";
            break;
          case SENSORYPLEASURE:
            symbol = "sens.pleas.";
            break;
          case SHAME:
            symbol = "shame";
            break;
        }
      }
      // resultstring = symbol + String.valueOf(_components.get(basicemotion)) + " " + resultstring;
      java.text.DecimalFormat df = new java.text.DecimalFormat(".000");
      if (_components.get(basicemotion) == 0) {
      } else {
        resultstring =
            symbol
                + " "
                + String.valueOf(df.format(_components.get(basicemotion)))
                + " "
                + resultstring;
      }
    }

    return resultstring;
  }