- package xiaihomework;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class producer {
- public static void main(String[] args) throws IOException {
- String[] types={"♠","♥","♣","♦"};
- String[] value={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
- String[] king={"JOKER","joker"};
- List<String> cards=new ArrayList<String>();
- for(int i=0;i<types.length;i++){
- for(int j=0;j<value.length;j++){
- cards.add(types[i]+value[j]);
- }
- }
- cards.add(king[0]);
- cards.add(king[1]);
- System.out.println(" --------------------------WELCOME------------------------------\\n");
- System.out.println("\\n\\t\\t*********************************************************");
- System.out.println ("\\t\\t**simple REVEALED PREFERENCE Model with poker cards **");
- System.out.println ("\\t\\t*********************************************************");
- System.out.println ("\\t\\t 高丙吉(博) 刘奇 " );
- System.out.print("\\n ARE YOU READY?(Plesae input y to start the programme)-------\\n");
- @SuppressWarnings("resource")
- Scanner input = new Scanner(System.in);
- @SuppressWarnings("unused")
- String con = input.next();
- System.out.println("Generate the product space for this simple model------------------------------\\n");
- int m=0;
- for(String str:cards)
- {
- System.out.print(str+"\\t");
- m++;
- if(m%13==0)
- System.out.println();
- }
- Collections.shuffle(cards);
- m=0;
- System.out.println("\\n\\nShuffle the product space-----------------------------------------------------\\n");
- for(String str:cards)
- {
- System.out.print(str+"\\t");
- m++;
- if(m%13==0)
- System.out.println();
- }
- if(cards != null && cards.size() > 3){
- cards = cards.subList(0, 27);
- }
- int randomNum=(int)Math.rint(Math.random()*26+1);
- System.out.println("\\n\\nTake out 21 product combinations from the product space randomly--------------\\n");
- for(String str:cards)
- System.out.print(str+" ");
- System.out.print("\\nComputer,as a consumer, will choose ONE card as its PREFERENCE\\n" );
- String a1=cards.get(randomNum);
- System.out.println("The computer's PREFERENCE is "+a1);
- List<String> SUITA = new ArrayList<String>();
- List<String> SUITB = new ArrayList<String>();
- List<String> SUITC = new ArrayList<String>();
- for (int i=0;i<2; i++){
- for (int j = 0; j < 9; j++) {
- SUITA.add(cards.remove(0));
- SUITB.add(cards.remove(0));
- SUITC.add(cards.remove(0));
- }
- System.out.println("\\n\\nDeal the pack to 3 suits,each suit represent a specimengroup------------------\\n");
- System.out.println("SPECIMEN1:" + SUITA);
- System.out.println("SPECIMEN2:" + SUITB);
- System.out.println("SPECIMEN3:" + SUITC);
- System.out.println("\\n\\ncomputer,as a consumer,will shoose which specimen group it prefer most\\n");
- if(SUITA.contains(a1)){
- SUITB.addAll(SUITA);
- SUITB.addAll(SUITC);
- System.out.println("\\n\\nComputer,as a CONSUMER, choose SPECIMEN1--------------------------------------\\n");
- System.out.println("\\n\\nAssemble the 3 SPECIMEN groups------------------------------------------------\\n");
- for(String str:SUITB)
- System.out.print(str+" ");
- cards = SUITB;
- SUITA.clear();
- SUITC.clear();
- }else if(SUITB.contains(a1)){
- SUITA.addAll(SUITB);
- SUITA.addAll(SUITC);
- System.out.println("\\n\\nComputer,as a CONSUMER, choose SPECIMEN2---------------------------------------\\n");
- System.out.println("\\n\\nAssemble the 3 SPECIMEN groups-------------------------------------------------\\n");
- for(String str:SUITA)
- System.out.print(str+" ");
- cards = SUITA;
- SUITB.clear();
- SUITC.clear();
- }else if(SUITC.contains(a1)){
- SUITA.addAll(SUITC);
- SUITA.addAll(SUITB);
- System.out.println("\\n\\nComputer,as a CONSUMER, choose SPECIMEN3--------------------------------------\\n");
- System.out.println("\\n\\nAssemble the 3 SPECIMEN groups------------------------------------------------\\n");
- for(String str:SUITA)
- System.out.print(str+" ");
- cards = SUITA;
- SUITB.clear();
- SUITC.clear();
- }
- }
- List<String> SUITD = new ArrayList<String>();
- List<String> SUITE = new ArrayList<String>();
- List<String> SUITF = new ArrayList<String>();
- for (int i = 0; i < 9; i++) {
- SUITD.add(cards.remove(0));
- SUITE.add(cards.remove(0));
- SUITF.add(cards.remove(0));
- }
- System.out.println("\\n\\nDeal the pack to 3 suits,each suit represent a specimengroup for the last time-\\n");
- System.out.println("SPECIMEN1:" + SUITD);
- System.out.println("SPECIMEN2:" + SUITE);
- System.out.println("SPECIMEN3:" + SUITF);
- System.out.println("\\n\\ncomputer,as a consumer,will shoose which specimen group it prefer most\\n");
- if(SUITD.contains(a1)){
- if(SUITD != null && SUITD.size() >= 2){
- System.out.println("\\n\\ncomputer,as a CONSUMER, choose SPECIMEN1--------------------------------------\\n");
- System.out.println("The CONSUMER's PREFERENCE deep in the heart is "+SUITD.get(4));
- }
- }else if(SUITE.contains(a1)){
- if(SUITE != null && SUITE.size() >= 2){
- System.out.println("\\n\\ncomputer,as a CONSUMER, choose SPECIMEN2--------------------------------------\\n");
- System.out.println("The CONSUMER's PREFERENCE deep in the heart is "+SUITE.get(4));
- }
- }else if(SUITF.contains(a1)){
- if(SUITF != null && SUITF.size() >= 2){
- System.out.println("\\n\\ncomputer,as a CONSUMER, choose SPECIMEN3--------------------------------------\\n");
- System.out.println("The CONSUMER's PREFERENCE deep in the heart is "+SUITF.get(4));
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2208201410293.html
来源: http://www.codesnippet.cn/detail/2208201410293.html