本文主要是介绍美女选妃完善版和扑克斗地主,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一.知识点
封装:
构造方法Constructor:
extends是继承的意思
Animal是父类
Cat和Dog都是子类
Java类的继承特点:
List 泛型
抽象类的概述及特点:
抽象类和抽象方法必须用abstract关键字修饰
abstract class 类名{}
public abstract void eat();
二.美女选妃
先创建一个新的名为BL的Java文件,里面的代码内容如下:
package com.zhongruan;public class BL {private int height;private int wight;public int getHeight() {return height;}public void setHeight(int height) {if (20<height&&height<300){this.height=height;}else{System.out.println("可能是个外星人");}}public int getWight() {return wight;}public void setWight(int wight) {this.wight = wight;}
}
再在昨天以完成的代码中进行修改,修改结果如下:
package com.zhongruan;import java.util.*;public class Zuoye {public List<BL> getBLs(){List<BL> bls = new ArrayList<>();Scanner input =new Scanner(System.in);for (int i=1;i<4;i++){System.out.println("请输入"+i+ "个美女的身高:");int h=input.nextInt();System.out.println("请输入"+i+ "个美女的体重:");int w=input.nextInt();BL bl=new BL();bl.setHeight(h);bl.setWight(w);bls.add(bl);}return bls;}public Map<String,Integer>getSumHAndSumW(List<BL>bls){int sumH=0;int sumW=0;for (BL bl:bls){sumH=sumH+bl.getHeight();sumW=sumW+bl.getWight();}System.out.println(sumH+"====="+sumW);Map map=new HashMap();map.put("sgh",sumH);map.put("tzh",sumW);return map;}public Map<String,Integer> getAvg(Map<String,Integer>map){int sumH=map.get("sgh");int sumW=map.get("tzh");int avgH=sumH/3;int avgW=sumW/3;Map<String,Integer> avgMap=new HashMap<>();avgMap.put("pjsg",avgH);avgMap.put("pjtz",avgW);return avgMap;}public String getResult(Map<String, Integer> avgM) {int avgH = avgM.get("pjsg");int avgW = avgM.get("pjtz");if (avgH > 150 && avgW < 100) {return "是美女";} else {return "不是美女";}}public static void main(String[] args){Zuoye zuoye=new Zuoye();List<BL> bls=zuoye.getBLs();
// List<Integer> highs=zuoye.getHighs();
// List<Integer> weights=zuoye.getwighs();Map<String, Integer> map = zuoye.getSumHAndSumW(bls);Map<String, Integer> avgM = zuoye.getAvg(map);String s = zuoye.getResult(avgM);System.out.println(s);}}
三.扑克斗地主
//斗地主老师版package com.zhongruan;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;public class Ddz {public static void main(String[] args){//1.准备一副牌List<String> poker=new ArrayList<>();String[] nums={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};String[] colors={"黑桃","红心","梅花","方块"};for (String color:colors){for (String num:nums){String pai=color+num;poker.add(pai);}}poker.add("大王");poker.add("小王");System.out.println("yuanpai"+poker);//2.洗牌Collections.shuffle(poker);System.out.println("xiwanhou"+poker);//3.留3张牌List<String> dipai=new ArrayList<>();Random random=new Random();for (int i=0;i<3;i++){int index=random.nextInt(poker.size());String pai=poker.remove(index);dipai.add(pai);}System.out.println("dipai:"+dipai);System.out.println("fadepai"+poker);//4.发牌List<String> xz=new ArrayList<>();List<String> wyb=new ArrayList<>();List<String> wy=new ArrayList<>();for (int i=0;i<poker.size();i++){String pai=poker.get(i);int mod=i%3;if(mod==0){xz.add(pai);}else if(mod==1){wyb.add(pai);}else {wy.add(pai);}}//5.看牌System.out.println("xz:"+xz);System.out.println("wyb:"+wyb);System.out.println("wy:"+wy);}
}
这篇关于美女选妃完善版和扑克斗地主的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!