我目前学习遇到的问题是,用如下代码写出的程序,最后输出的结果是Hashcoad(),为什么呢?我是新手不太理解,哪位可以帮我解答一下,附图,我的运行问题
扑克类
package com.ljb.study01;
public class PuKe {
public String hs;
public String sz;
//定义一个扑克集(花色,数字)
PuKe(String sz,String hs) {
this.hs=hs;
this.sz=sz;
}
public PuKe() {
}
}
玩家类
package com.ljb.study01;
import java.util.List;
public class People {
public int id;
public String name;
public PuKe puk;
public People(int id , String name,PuKe puk) {
this.id=id;
this.name=name;
this.puk=puk;
}
}
功能类
package com.ljb.study01;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class PuKeTest {
Scanner scanner = new Scanner(System.in);
//创建一个扑克集
public List pukeji;
public PuKeTest() {
this.pukeji=new ArrayList();
}
//创建两个人的全局变量数组
public List<People> pp1 = new ArrayList<People>();
int id1;
String name1;
PuKe puk1;
public List<People> pp2 = new ArrayList<People>();
int id2;
String name2;
PuKe puk2;
//创建扑克内容
public void pukejiAddTest() {
//黑桃
for(int i = 1 ; i < 14 ; i++) {
if(i<11) {
PuKe pk1= new PuKe(""+i,"黑桃");
pukeji.add(pk1);
}else if(i==11) {
PuKe pk1= new PuKe("J","黑桃");
pukeji.add(pk1);
}else if(i==12) {
PuKe pk1= new PuKe("Q","黑桃");
pukeji.add(pk1);
}else if(i==13) {
PuKe pk1= new PuKe("K","黑桃");
pukeji.add(pk1);
}
}
for(int i = 1 ; i < 14 ; i++) {
if(i<11) {
PuKe pk1= new PuKe(""+i,"红桃");
pukeji.add(pk1);
}else if(i==11) {
PuKe pk1= new PuKe("J","红桃");
pukeji.add(pk1);
}else if(i==12) {
PuKe pk1= new PuKe("Q","红桃");
pukeji.add(pk1);
}else if(i==13) {
PuKe pk1= new PuKe("K","红桃");
pukeji.add(pk1);
}
} for(int i = 1 ; i < 14 ; i++) {
if(i<11) {
PuKe pk1= new PuKe(""+i,"梅花");
pukeji.add(pk1);
}else if(i==11) {
PuKe pk1= new PuKe("J","梅花");
pukeji.add(pk1);
}else if(i==12) {
PuKe pk1= new PuKe("Q","梅花");
pukeji.add(pk1);
}else if(i==13) {
PuKe pk1= new PuKe("K","梅花");
pukeji.add(pk1);
}
} for(int i = 1 ; i < 14 ; i++) {
if(i<11) {
PuKe pk1= new PuKe(""+i,"方片");
pukeji.add(pk1);
}else if(i==11) {
PuKe pk1= new PuKe("J","方片");
pukeji.add(pk1);
}else if(i==12) {
PuKe pk1= new PuKe("Q","方片");
pukeji.add(pk1);
}else if(i==13) {
PuKe pk1= new PuKe("K","方片");
pukeji.add(pk1);
}
}
System.out.println("已经准备好扑克!这是牌库请过目:");
int size= pukeji.size();
for (int i = 0 ; i < size ; i++) {
PuKe pk1 = (PuKe) pukeji.get(i);
System.out.print(pk1.hs+pk1.sz);
System.out.print(" ");
}
System.out.println(" ");
}
//欢迎界面,并创建人物及
public void hyTest() {
System.out.println("欢迎来到XXXX:");
System.out.println("您好!请输入您的会员号:");
id1=scanner.nextInt();
System.out.println("您好!请输入您的姓名");
name1 = scanner.next();
pp1.add(new People(id1,name1,null));
System.out.println("欢迎您:"+name1+",我们尊贵的客人!");
System.out.println("您好!请输入您的会员号:");
id2=scanner.nextInt();
System.out.println("您好!请输入您的姓名");
name2 = scanner.next();
pp2.add(new People(id2,name2,null));
System.out.println("欢迎您:"+name2+",我们尊贵的客人!");
}
//洗牌
public void shuffleTest() {
Collections.shuffle(pukeji);
System.out.println("牌已经洗好!");
//查看牌库洗乱后的顺序
int size= pukeji.size();
for (int i = 0 ; i < size ; i++) {
PuKe pk1 = (PuKe) pukeji.get(i);
System.out.print(pk1.hs+pk1.sz);
System.out.print(" ");
}
System.out.println(" ");
}
//发牌
public void beginTest() {
//创建两个人的牌库
System.out.println("请选择一人发几张牌:");
int i = scanner.nextInt();
int k=0;
for(int j = 0 ; j<i ; j++) {
if(j==0) {
pp1.set(j, new People(id1,name1,(PuKe) pukeji.get(k)));
k++;
pp2.set(j, new People(id2,name2,(PuKe) pukeji.get(k)));
k++;
}else {
pp1.add( new People(id1,name1,(PuKe) pukeji.get(k)));
k++;
pp2.add( new People(id2,name2,(PuKe) pukeji.get(k)));
k++;
}
}
//查看底牌
for (People people : pp1) {
System.out.print(people.puk);
}
System.out.println("");
for (People people : pp2) {
System.out.println(people.puk);
}
}
//手中牌进行排序
public void cardTest() {
}
public static void main(String[] args) {
PuKeTest pkt = new PuKeTest();
pkt.hyTest();
pkt.pukejiAddTest();
pkt.shuffleTest();
pkt.beginTest();
}
}//类
热门评论
求大佬帮助zsbdzsbd