练习练习练习
人机猜拳import java.util.Scanner;public class Qwe {public static void main(String[] args) {new Game().play();}}class User {private String name;private Scanner scanner new Scanner(System.in);private int choice;public User(String name) {this.name name;}public String getName() {return name;}public void game() {System.out.print(请出拳);choice scanner.nextInt();while (true) {if (choice 1) {System.out.println(你出拳剪刀);break;} else if (choice 2) {System.out.println(你出拳石头);break;} else if (choice 3) {System.out.println(你出拳布);break;} else {System.out.print(输入不合法请重新输入);choice scanner.nextInt();}}}public int getChoice() {return choice;}}class Computer {private int winCount;private int loseCount;private int total;private String fistName(int n) {if (n 1) return 剪刀;else if (n 2) return 石头;else return 布;}private int judge(int userChoice, int computerChoice) {if (userChoice computerChoice) return 0;if ((userChoice 1 computerChoice 3)|| (userChoice 2 computerChoice 1)|| (userChoice 3 computerChoice 2)) return 1;else return -1;}public void computerGame(User user, String role) {winCount 0;loseCount 0;total 0;Scanner scanner new Scanner(System.in);String again;do {total;user.game();int computerChoice (int) (Math.random() * 3) 1;System.out.println(role 出拳 fistName(computerChoice));int result judge(user.getChoice(), computerChoice);if (result 1) {System.out.println(恭喜你赢了);winCount;} else if (result -1) {System.out.println(很遗憾你输了);loseCount;} else {System.out.println(平局);}System.out.print(是否继续 y/n );again scanner.next();} while (y.equals(again));}public int getWinCount() { return winCount; }public int getLoseCount() { return loseCount; }public int getTotal() { return total; }}class Game {private Scanner scanner new Scanner(System.in);public void play() {System.out.println(******************************** 猜拳 ,开始 ********************************);System.out.println(出拳规则1.剪刀 2.石头 3.布);System.out.print(请输入你的名字);String userName scanner.next();User user new User(userName);String roundAgain;do {System.out.print(请选择对方的角色1.刘备 2.孙权 3.曹操);String role null;while (true) {int choice scanner.nextInt();if (choice 1) role 刘备;else if (choice 2) role 孙权;else if (choice 3) role 曹操;if (role ! null) {System.out.println(你选择了 role 对敌);break;}System.out.print(输入错误请重新输入);}System.out.print(要开始吗 y/n );String start scanner.next();if (!y.equals(start)) {System.out.println(已退出);break;}Computer computer new Computer();computer.computerGame(user, role);int userWin computer.getWinCount();int compWin computer.getLoseCount();int total computer.getTotal();if (userWin compWin) {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把 userName 胜利);} else if (compWin userWin) {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把 role 胜利);} else {System.out.println(userName VS role 比分为 userWin : compWin 对战场次 total 把平局);}System.out.print(是否开启下一轮 y/n );roundAgain scanner.next();} while (y.equals(roundAgain));System.out.println(游戏结束);}}怪物模块class Monster {String name;int blood;int attackPower;int defence;public void attack() { System.out.println(攻击); }public void move() { System.out.println(移动); }}class Goblin extends Monster {int rage;Overridepublic void attack() {System.out.println(哥布林正在用石头攻击);}Overridepublic void move() {System.out.println(哥布林缓慢移动);}}class CatDemon extends Monster {Overridepublic void attack() {System.out.println(猫妖正在用爪子攻击你);}Overridepublic void move() {System.out.println(猫妖跳着移动);}}抽象绘制abstract class All {String x;String y;String color;public abstract void draw();}class Line extends All {String finalCoordinate;String originalCoordinate;Overridepublic void draw() { System.out.println(绘制线条); }}class Rectangle extends All {int length;int width;Overridepublic void draw() { System.out.println(绘制矩形); }}class Circle extends All {int r;Overridepublic void draw() { System.out.println(绘制圆形); }}class Test1 {static public void testpage() {All[] a new All[3];a[0] new Line();a[1] new Circle();a[2] new Rectangle();for (int i 0; i a.length; i) {a[i].draw();}}}员工管理abstract class All {String x;String y;String color;public abstract void draw();}class Line extends All {String finalCoordinate;String originalCoordinate;Overridepublic void draw() { System.out.println(绘制线条); }}class Rectangle extends All {int length;int width;Overridepublic void draw() { System.out.println(绘制矩形); }}class Circle extends All {int r;Overridepublic void draw() { System.out.println(绘制圆形); }}class Test1 {static public void testpage() {All[] a new All[3];a[0] new Line();a[1] new Circle();a[2] new Rectangle();for (int i 0; i a.length; i) {a[i].draw();}}}Employees[] employees new Employees[100];for (int i 0; i employees.length; i) {if (Math.random() 0.5) {employees[i] new Manager();} else {employees[i] new Coder();}}for (Employees e : employees) {e.work();}面积形状class Shape {public double area() { return 0; }public void show() { System.out.println(这是一个形状); }}class Circles extends Shape {double radius;public Circles(double radius) { this.radius radius; }Overridepublic double area() { return Math.PI * radius * radius; }Overridepublic void show() { System.out.println(这是一个圆形); }}class Rectangles extends Shape {double length;double width;public Rectangles(double length, double width) {this.length length;this.width width;}Overridepublic void show() { System.out.println(这是一个矩形); }Overridepublic double area() { return length * width; }}class Test2 {static public void test2() {Scanner scanner new Scanner(System.in);System.out.println(请输入半径);double r scanner.nextDouble();System.out.println(请输入长和宽);double a scanner.nextDouble();double b scanner.nextDouble();Shape[] shape new Shape[2];shape[0] new Circles(r);shape[1] new Rectangles(a, b);for (int i 0; i shape.length; i) {System.out.println(shape[i].area());shape[i].show();}}}数组扩容class M {static public void array() {int i 0;Scanner scanner new Scanner(System.in);int[] arr new int[2];System.out.println(请输入数字-1结束);while (true) {int b scanner.nextInt();if (b -1) {System.out.println(结束输入);break;}arr[i] b;i;if (i arr.length) {arr Arrays.copyOf(arr, arr.length * 2);}}// 只打印有效部分for (int j 0; j i; j) {System.out.print(arr[j] );}}}学生管理class Student {private String name;private int age;private int score;public Student(int age, String name, int score) {this.age age;this.name name;if (score 0 || score 100) {System.out.println(成绩不合法);} else {this.score score;}}public int getAge() { return age; }public String getName() { return name; }public int getScore() { return score; }public void setAge(int age) { this.age age; }public void setName(String name) { this.name name; }public void setScore(int score) {if (score 0 || score 100) {System.out.println(成绩不合法);} else {this.score score;}}public void show() {System.out.println(姓名 name 年龄 age 成绩 score);}}

相关新闻

Flask构建残障社区服务平台的技术实践

Flask构建残障社区服务平台的技术实践

1. 项目背景与核心需求社区残障人士服务平台的开发源于一个普遍存在却常被忽视的社会痛点——残障群体在获取社区服务时面临的信息不对称和物理障碍。传统服务模式往往需要残障人士主动到指定地点登记需求,这种"被动等待"的服务机制对行动不便者极不友好。…

2026/11/1 1:40:15 阅读更多 →
11. 类和动态内存分配

11. 类和动态内存分配

类和动态内存分配动态内存和类在类中使用 new 和 delete 来动态管理内存,可以让程序在运行时(而非编译时)决定内存分配。在类构造函数中使用 new,需要额外执行一系列步骤:扩展析构函数、编写额外的类方法来帮助正确完成…

2026/10/24 19:49:23 阅读更多 →
高职统计与大数据分析专业现状与就业前景

高职统计与大数据分析专业现状与就业前景

1. 统计与大数据分析专业现状解析统计与大数据分析作为新兴交叉学科,近年来在高职院校的专业设置中呈现出明显的上升趋势。从行业需求端来看,2023年人社部发布的《新职业在线学习平台发展报告》显示,数据分析师岗位缺口已达150万人&#xff0…

2026/10/31 17:13:26 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年,我大部分时间都在跟浏览器标签页打交道,直到第一次把桌面应用跑起来,才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词,最开始是在某段时间频繁出现在同事的讨论里,一个用HTML…

2026/11/1 0:24:43 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介:亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档,主要面向智能锁安装人员、终端用户及售后维护者,帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件,大小4.37MB,内容结构清晰&#xff…

2026/11/1 10:36:53 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统,整车要求空载跑到8m/s,电机转速已经拉到额定点,驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令,转速纹丝不动,三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/1 10:36:51 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年,用它写过嵌入式驱动、做过游戏服务端,也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词,我其实挺感慨的——这门语言的难点从来不是语法多,而是知识点之间的耦合太深…

2026/11/1 1:06:58 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介:亚太天能T109滑盖智能锁产品说明书以PDF格式发布,适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开,先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能,再给出完整安装步骤&…

2026/11/1 10:35:11 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历:翻开源码注释、论文摘要或者一份专业报告,每个字都认识,连在一起却像天书。想找人聊聊,身边要么没人懂,要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型,几秒钟之后&a…

2026/11/1 9:35:41 阅读更多 →

日新闻

周新闻

月新闻