栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java入门第三季 7-1 《扑克牌游戏》

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java入门第三季 7-1 《扑克牌游戏》

package com.exam;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;

 public class PTest {
 private List pokerList = new ArrayList();//创建扑克List
 private List peopleList = new ArrayList();//创建玩家List
 	
 public  void creatcard(){
 String[] num={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};	
 String[] type={"红桃","方块","梅花","黑桃"};
 String[] other={"大王","小王"};
 int sum=0;//统计总牌数量
 int sum1=0;//每四个换一行数量
 System.out.println("----创建扑克牌----");
 for(int i=0;i0) {
for (People1 people : peopleList) {
System.out.println("---玩家"+people.getName()+"-拿牌");
people.cards.add(pokerList.get(j));
j++;
sum++;
if(sum==54){
break;
}
}
i--;
}
System.out.println("------发牌结束!-------");
System.out.println("玩家各自的手牌为:");
for (People1 people : peopleList) {
System.out.println(people.getName()+":"+people.cards.toString());
}}
public static void main(String[] args) {
// TODO Auto-generated method stub
PTest go = new PTest();
go.creatcard();
go.upsetPoker();
go.createPeople();
go.issuePoker();
System.out.println("");
}
}
package com.exam;
public class Card {
private String num;
private String type;
private String other;
public Card(String num,String type,String other){
this.num=num;
this.type=type;
this.other=other;
}
public String getOther() {
return other;
}
public void setOther(String other) {
this.other = other;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;	
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
 public String toString() {
 return num + type + other;
 }
 }
package com.exam;

import java.util.ArrayList;
import java.util.List;
public class People1 {
private Integer id;
private String name;
public List cards;
public People1 (Integer id, String name) {
 super();
  this.id = id;
  this.name = name;
   this.cards = new ArrayList();
    }
    public Integer getId() {
    return id;
    }
    public void setId(Integer id) {
    this.id = id;
    }
    public String getName() {
    return name;
    }
    public void setName(String name) {
    this.name = name;
    }
    }

小测试一枚,java基础看了好多遍,要泪崩了!!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/239771.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号