import java.util.Scanner;
public class user {
Scanner sc = new Scanner(System.in);
String username;
String password;
static int usercount = 0;
public user(){
usercount++;
}
public user(String username){
this.username = username;
usercount++;
}
public user(String username ,String password){
this.username = username;
this.password = password;
usercount++;
}
public void setUsername() {
System.out.println("请输入用户名:");
username = sc.nextLine();
}

public void setPassword() {
System.out.println("请输入密码:");
password = sc.nextLine();
}

public void account() {
System.out.println("你是第"+usercount+"个用户"+"你的用户名是:" + username + ",你的密码是:" + password);
}

public static void main(String[] args) {
user u1 = new user();
u1.setUsername();
u1.setPassword();
u1.account();
user u2 = new user("w");
u2.setPassword();
u2.account();
user u3 = new user("e","123");
u3.account();
}
}

 

 

 

 

public class Poker {
private String[] decor = {"黑桃", "红桃", "方块", "梅花"};
private int[] point = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
private Card[] cards;

public Poker() {
cards = new Card[52];
for (int i = 0; i < decor.length; i++) {
for (int j = 0; j < point.length; j++) {
cards[i * 13 + j] = new Card(decor[i], point[j]);
}
}
}

public void shuffle() {
int len = cards.length;
for (int i = 0; i < len; i++) {
int index = (int) (Math.random() * len);
Card temp = cards[index];
cards[index] = cards[i];
cards[i] = temp;
}
}

public class Card {
private String decor;
private int point;

public Card(String decor, int point) {
this.decor = decor;
this.point = point;
}

public String toString() {
String pointStr;
switch (point) {
case 1:
pointStr = "A";
break;
case 11:
pointStr = "J";
break;
case 12:
pointStr = "Q";
break;
case 13:
pointStr = "K";
break;
default:
pointStr = String.valueOf(point);
}
return decor + pointStr;
}
}
public Card getCard(int index) {
return cards[index];
}
}
class test {
public static void main(String[] args) {
Poker p = new Poker();
p.shuffle();
Poker.Card c = p.getCard(1);
System.out.println(c);
}
}

 

 

 



版权声明:本文为星∗原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xinxiangl/p/16062208.html