0416 Java编程语言

课堂PPT

PPT地址

Java编程语言学习路线

Java编程语言.xmind (156.6 KB)

代码仓库

package com.ceshiren;

public class Hero {
//英雄编号
private int bianHao;
//英雄姓名
private String name;
//英雄的血量
private int xueLiang;
//英雄的攻击力
private int gongjili;

//get方法

public int getBianHao() {
    return bianHao;
}

public void setBianHao(int bianHao) {
    this.bianHao = bianHao;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getXueLiang() {
    return xueLiang;
}

public void setXueLiang(int xueLiang) {
    this.xueLiang = xueLiang;
}

public int getGongjili() {
    return gongjili;
}

public void setGongjili(int gongjili) {
    this.gongjili = gongjili;
}

//set方法
//构造函数 有参构造、无参构造

public Hero() {
}

public Hero(int bianHao, String name, int xueLiang, int gongjili) {
    this.bianHao = bianHao;
    this.name = name;
    this.xueLiang = xueLiang;
    this.gongjili = gongjili;
}
//toString


@Override
public String toString() {
    return "Hero{" +
            "bianHao=" + bianHao +
            ", name='" + name + '\'' +
            ", xueLiang=" + xueLiang +
            ", gongjili=" + gongjili +
            '}';
}

}

package com.ceshiren;

import java.util.Scanner;

//回合制游戏
public class Play {
public static void main(String args) {
while (true){
//主界面:
System.out.println(“--------欢迎来到回合制游戏--------”);
System.out.println(“1 创建英雄”);
System.out.println(“2 查看英雄信息”);
System.out.println(“3 查看英雄血量小于100的英雄名”);
System.out.println(“4 打斗”);
System.out.println(“5 修改英雄信息”);
System.out.println(“6 删除英雄”);
System.out.println(“7 退出系统”);

        //Scanner
        Scanner scanner = new Scanner(System.in);
        //输入选择
        String choice = scanner.nextLine();
        switch (choice){
            case "1":
                System.out.println("创建英雄");
                break;
            case "2":

// …
System.out.println(“查看英雄信息”);
break;
case “3”:
System.out.println(“查看英雄血量小于100的英雄名”);
break;
case “4”:
System.out.println(“打斗”);
break;
case “5”:
System.out.println(“修改英雄信息”);
break;
case “6”:
System.out.println(“删除英雄”);
break;
case “7”:
System.exit(0);

        }
    }


}

}

image

image

image

image
这个地方选错了

private static void findLessThan100(List<Hero> heros) {
    Stream<Hero> stream =heros.stream();
    stream.forEach(x->{
        if(x.getBlood()<100){
            System.out.println("["+x.getName()+"]");
        }
    });
}
private static void findLessThan100(List<Hero> heros) {
    //查看血量小于100的英雄名打印
    //list集合的遍历
    //根据条件获取到英雄对象后,打印英雄对象的姓名
    int size = heros.size();
    for (int i = 0; i < size; i++) {
        if (heros.get(i).getHp() < 100){
            System.out.println("血量小于100的英雄名是:"+heros.get(i).getName());
        }
    }

}
private static void findLessThan100(List<Hero> heros) {
    //查看血量小于100的英雄名打印
    //list集合的遍历
    //根据条件获取到英雄对象后,打印英雄对象的姓名
    List<Hero> lessThan100List = new ArrayList<>();
    int size = heros.size();
    for (int i = 0; i < size; i++) {

// if (heros.get(i).getHp() < 100){
// System.out.println(“血量小于100的英雄名是:”+heros.get(i).getName());
// }
Hero hero = heros.get(i);
if (hero.getHp() < 100){
lessThan100List.add(hero);
}
for (Hero hero1 : lessThan100List) {
//这里比较的时候不知道怎么写了
Integer.compare(hero1,)
}
}
//stream流写法
//攻击力降序排序,姓名输出,比较两个整数:Integer.compare(a,b);

}