今天在斗地主原有的代码基础上添加了排序的部分,具体代码如下:
import java.awt.;
import java.awt.List;
import java.util.
;

public class DiZhu2 {
public static void main(String[] args){
//1.拿牌
Map<Integer,String> poker=new HashMap<>();
String[] nums={“A”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“J”,“Q”,“K”};
String[] colors={“黑桃”,“红心”,“梅花”,“方块”};
int index=0;
for(String color:colors){
for(String num:nums){
String pai=color+num;
index=index+1;
poker.put(index,pai);
}
}
System.out.println(index);
index++;
poker.put(index,“大王”);
index++;
poker.put(index,“小王”);
System.out.println(poker);
//2.洗牌
List pokerIndexs=new ArrayList<>();
Set integers = poker.keySet();
// System.out.println(integers);
for(Integer i:poker.keySet()){
pokerIndexs.add(i);
}
Collections.shuffle(pokerIndexs);
System.out.println(pokerIndexs);
//3.留三张牌
Set dipaiInds=new TreeSet<>();
dipaiInds.add(pokerIndexs.remove(0));
dipaiInds.add(pokerIndexs.remove(0));
dipaiInds.add(pokerIndexs.remove(0));
System.out.println(dipaiInds);
System.out.println(pokerIndexs);
//4.发牌
Set ct=new TreeSet<>();
Set wwc=new TreeSet<>();
Set sj=new TreeSet<>();
for(int i=0;i <pokerIndexs.size();i++){
int pi=pokerIndexs.get(i);
int mod=i%3;
if(mod0){
ct.add(pi);
}else if(mod1){
wwc.add(pi);
}else{
sj.add(pi);
}
}
System.out.println(ct);
System.out.println(wwc);
System.out.println(sj);
//5.看牌
look(poker,ct);
look(poker,wwc);
look(poker,sj);

}
public static void look(Map<Integer,String> poker,Set<Integer> indexs) {List<String> p = new ArrayList<>();for (Integer i : indexs) {String pai = poker.get(i);p.add(pai);}System.out.println(p);}

}

今天新讲了一个音乐管理系统,首先在数据库里创表,添加变量
添加新的类命名为Test,添加DBUtil 写好后替换Test中的相应内容。
DBUtil的代码如下
public class DBUtil {
public static Connection getConnection() throws SQLException, ClassNotFoundException{
Class.forName(“com.mysql.jdbc.Driver”);
Connection connection= DriverManager.getConnection(“jdbc:mysql://127.0.0.1:3306/zjgm?characterEncoding=utf-8&user=root&password=123456”);
System.out.println(“操作成功!”);
return connection;
}
public static void closeAll(ResultSet resultSet,Statement statement, Connection connection) throws SQLException {
if (resultSet!=null){
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement!=null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
在创建一个命名为Music的文件,代码如下:
public class Music {
private int id;
private String name;
private String author;

    public int getId(int anInt) {return id;}public void setId(int id) {this.id = id;}public String getName(String string) {return name;}public void setName(String name) {this.name = name;}public String getAuthor() {return author;}public void setAuthor(String author) {this.author = author;

}

改好的Test代码为
public class Test {
public List findMusic() throws SQLException {
ResultSet resultSet=null;
PreparedStatement statement=null;
Connection connection=null;
List musics=new ArrayList<>();
try {
connection= DBUtil.getConnection();
String sql=“select * from music”;
statement=connection.prepareStatement(sql);
resultSet=statement.executeQuery();
while(resultSet.next()){
Music music=new Music();
music.setId(resultSet.getInt(1));
music.setName(resultSet.getString(2));
music.setAuthor(resultSet.getString(3));
musics.add(music);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBUtil.closeAll(resultSet,statement,connection);
}
return musics;

}
public static void main(String[] args) throws SQLException {Test test=new Test();List<Music> musics=test.findMusic();System.out.println(musics);}

}
今天还讲了一个知识点
静态方法不可以调用非静态方法

斗地主排序以及音乐管理系统相关推荐

  1. 斗地主排序和音乐系统管理

    9.16 1.斗地主排序 2.音乐系统管理 1.斗地主排序 今天将斗地主拿到的牌进行排序,还是五个步骤: 1.拿到一副牌 2.洗牌 3.留3张牌 4.发牌 5.看牌 代码如下: package com ...

  2. 斗地主改良版及音乐管理系统

    目录 一.斗地主改良版 二.音乐管理系统 一.斗地主改良版 1.拿到一副牌 Map<Integer,String> poker=new HashMap<>();String[] ...

  3. jdbc封装,斗地主和音乐管理系统

    一.用一种新的方式来写斗地主小程序 代码如下 public class DouDiZhu2 {public static void main(String[] args){//1.拿到一张牌Map&l ...

  4. Collections、Set、Map、斗地主排序

    Collections.Set.Map.斗地主排序 今日内容 Collections shuffle sort自然排序 比较器排序 可变参数[重] addall方法 Set接口 hashCode 哈希 ...

  5. 基于Java毕业设计音乐管理系统源码+系统+mysql+lw文档+部署软件

    基于Java毕业设计音乐管理系统源码+系统+mysql+lw文档+部署软件 基于Java毕业设计音乐管理系统源码+系统+mysql+lw文档+部署软件 本源码技术栈: 项目架构:B/S架构 开发语言: ...

  6. Java毕业作品设计:音乐管理系统(网页版)

    音乐管理系统[网页版]功能目录 系统登录 用户注册 首页功能展示 管理全部歌曲 搜索歌曲 添加歌曲 更新歌曲信息 删除歌曲 查看用户信息 更新用户信息 系统登录 该音乐管理系统和其他平台相同,必须使用 ...

  7. java连接数据库代码查询music表和斗地主排序

    斗地主排序代码 package com.zhongruan;import java.util.*;public class DouDiZhu2 {public static void main(Str ...

  8. 基于 SpringBoot + VUE 【爱音乐管理系统】 平台设计与实现

    免费领取源码+参考论文 基于SpringBoot + VUE [爱音乐管理系统] 博主介绍:

  9. c语言课程设计--图书/音乐管理系统

    这个代码因为配置信息的原因不能直接整个拿去用(o゜▽゜)o☆ 这个代码因为配置信息的原因不能直接整个拿去用(o゜▽゜)o☆ 这个代码因为配置信息的原因不能直接整个拿去用(o゜▽゜)o☆ 只能提供一个思 ...

最新文章

  1. python dataframe删除指定行_pandas.DataFrame删除/选取含有特定数值的行或列
  2. nas servers
  3. MyEclipse+JavaEE+jsp+sqlsever实现产品售后服务系统
  4. verp之增加接近传感器(proximity sensor)
  5. 报告漏洞后 马斯克宣布撤回FSD Beta 10.3版本
  6. 计算机制作贺卡教案,制作贺卡教案
  7. 元胞自动机生命游戏C语言并行实现
  8. java取拼音首字母_java取出汉字字符串的拼音首字母
  9. 2020 Jiangsu Collegiate Programming Contest-A.Array
  10. 联想win10专业版64位简体中文原版光盘镜像
  11. 【csdn学习-Python】CSDN技能树-Python语言学习笔记
  12. log4j中配置LOG_HOME无效
  13. 数据结构之B树、B+树、B*树
  14. 小程序源码:全新独立后台修复登录在线答题
  15. 【前端春招】前端春招实习+秋招心路历程
  16. 2021练习题Python的
  17. VC编译选项 /ML /MLd /MT /MTd /MD /MDd之间的区别
  18. .net软件工程师面试
  19. 第11周 oj for循环画三角形
  20. MT3608升压模块原理图

热门文章

  1. android 平台上,AndroidAPP如何在Android平台上架?
  2. window.returnValue和 window.showModalDialog()和window.close()的使用方法
  3. 新版标准日本语中级_第十七课
  4. 迷你版XP,为何不老?
  5. 从零开始学Oracle(一),下载安装Oracle-11g起步
  6. nRF52832学习记录(八、WDT看门狗 )
  7. nvr与dvr的区别
  8. 扩招了!中科大软件学院今年【扩招149人】!
  9. ad元件定位孔放在哪一层_施工现场定位放线、基础施工放线、主体施工放线,图文详解...
  10. 傅里叶变换 ~ FFT概述