search
HomeJavajavaTutorialJava makes a simple volleyball game scoring system

This article mainly introduces Java to implement the volleyball game scoring system in detail, which has certain reference value. Interested friends can refer to it

Preliminary plan:

Perhaps due to personal reasons, the volleyball scoring system was completed during the holiday. I haven’t written a blog yet. I just kept pushing it but didn’t want to write. I also started working after the Chinese New Year. Maybe I just started working as an intern. Tight so I waited until now.

Before writing this system, I briefly conceived it. Because I went to Luoyang to participate in Java training for more than a month before leaving school, so the IDE I used to write the project was a Java environment. At first, I considered using jsp for the interface, and architecture using mvc, but then I thought the workload was too much and the effect was not very good. Finally, pure Java code was written and displayed on the virtual machine.

Requirement analysis:

The volleyball competition is a best-of-five game system. The team that scores 25 points in each game and leads the opponent by more than 2 points will win one game. Victory, the first team to win three rounds will win the game. If the score is 24:24 during the game, one side must lead the other side by 2 points to end the round. If the score of the first four games between the two sides is 2:2, the fifth game will be played. The team that scores 15 points in the fifth game and leads the opponent by more than 2 points will win. If the score is 14:14 during the game, one side must lead the other side by 2 points to end the game.

User example:

Code design:

package ss;
 
import java.util.Scanner;
/**
 * 排球计分系统
 *
 * 使用排球计分系统可以进行简单的排球计分操作以及查询某一局的比分。
 * 1、比赛总共5局,每一局5分,若是有一方领先对方3分,则视为这一方胜利。
 * 5局结束后,统计两方胜利的次数,输出最终胜利的一方。并退出程序
 * 2、使用查询功能可以查询过往的比赛成绩,输出比分和胜利的一方
 */
public class Game {
   
  static Scanner sca = new Scanner(System.in);
  //scoreArr数组,用来存放5局两队的单轮成绩
  static int[][] scoreArr = new int[5][2];
  //result数组,用来存放每一轮的成绩,方便查询
  static String[] result = new String[5];
   
  //用来统计两队胜利的次数
  static int ni1 = 0;
  static int ni2 = 0;
 
  public static void main(String[] args) {
    System.out.println("\n\n  --------欢迎进入ww排球计分系统--------\n\n\n");
    System.out.println("使用说明:使用ww排球计分系统可以进行简单的排球计分操作以及查询某一局的比分。" + "\n1、比赛总共5局,每一局5分,若是有一方领先对方3分,则视为这一方胜利。"
        + "\n 5局结束后,统计两方胜利的次数,输出最终胜利的一方。并退出程序\n" + "2、使用查询功能可以查询过往的比赛成绩,输出比分和胜利的一方");
    for (int i = 0; i < 5;) {
      System.out.println("  请选择您的操作:");
      System.out.println("1、开始计分   2、查询   3、退出系统");
      //用户输入的操作选择
      int choose = sca.nextInt();
      //如果用户输入1
      if (choose == 1) {
        //输出第几局比赛
        System.out.println("现在开始第" + (i + 1) + "局比赛");
        //调用计分方法
        bounds(i);
        i++;
      } else if (choose == 2) {//如果用户输出2
        System.out.println("请输入你要查询的局数:");
        int check = sca.nextInt();
        //判断用户输入的局数是否开始
        if (result[check - 1] == null) {
          System.out.println("这一局比赛还没有开始。");
        } else {
          //从数组中找出结果
          System.out.println(result[check - 1]);
        }
      } else if (choose == 3) {//如果用户输入3,输出当前成绩,并退出程序
         
        System.out.println("本场比赛结束,当前比分为:中国队VS美国队~~~~~" + ni1 + ":" + ni2);
        System.out.println("谢谢使用ww计分系统,欢迎下次使用,再见");
        System.exit(0);
      } else {
        System.out.println("您的输入有误,请重新输入");
      }
    }
     
    //5局比赛结束后,本场比赛结束,输出结果,并退出程序
    System.out.println("本场比赛结束,当前比分为:中国队VS美国队~~~~~" + ni1 + ":" + ni2);
    if (ni1 > ni2) {
      System.out.println("中国队取得最终胜利");
    } else {
      System.out.println("美国队取得最终胜利");
    }
    System.out.println("谢谢使用ww计分系统,欢迎下次使用,再见");
  }
 
  // 计分方法,统计成绩
  public static String[] bounds(int num) {
    int i = 0;
    //如果两队的成绩都小于等于5
    if (scoreArr[num][0] <= 5 && scoreArr[num][1] <= 5) {
      for (;; i++) {
        System.out.println("请输出获胜方的编号,进行加分");
        System.out.println("1、中国队       VS   2、美国队");
        int team = sca.nextInt();
        if (team == 1) {
          //保留每一局的成绩
          scoreArr[num][0] += 1;
          System.out.println("第" + (i + 1) + "轮比赛结束,当前比分为" + scoreArr[num][0] + ":" + scoreArr[num][1]);
        } else if (team == 2) {
          scoreArr[num][1] += 1;
          System.out.println("第" + (i + 1) + "轮比赛结束,当前比分为" + scoreArr[num][0] + ":" + scoreArr[num][1]);
 
        }
 
        if ((scoreArr[num][0] - scoreArr[num][1]) == 3) {
          result[num] = "第" + (num + 1) + "局,比分为" + scoreArr[num][0] + ":" + scoreArr[num][1] + "  中国队胜利";
          System.out.println(result[num]);
          //每轮比赛结束后,使最终成绩累加1,并返回
          ni1 += 1;
          return result;
        } else if ((scoreArr[num][1] - scoreArr[num][0]) == 3) {
          result[num] = "第" + (num + 1) + "局,比分为" + scoreArr[num][0] + ":" + scoreArr[num][1] + "  美国队胜利";
          System.out.println(result[num]);
          ni2 += 1;
          return result;
 
        }
      }
    } else if (scoreArr[num][0] > scoreArr[num][1]) {
      result[num] = "第" + (num + 1) + "局,比分为" + scoreArr[num][0] + ":" + scoreArr[num][1] + "  中国队胜利";
      System.out.println(result[num]);
      ni1 += 1;
      return result;
    } else {
      result[num] = "第" + (num + 1) + "局,比分为" + scoreArr[num][0] + ":" + scoreArr[num][1] + "  美国队胜利";
      System.out.println(result[num]);
      ni2 += 1;
      return result;
    }
  }
 
}

Run interface:

PsP time-consuming:

Summary: Since I didn’t learn Java for a long time, I encountered some problems when writing this project, but they were solved in the end. , because I have learned C#, the basics of the two are relatively similar, and it doesn’t take a lot of time. Since time is tight and the company is working on a project, I may not have enough time as in school, but I will definitely take it seriously.

The above is the detailed content of Java makes a simple volleyball game scoring system. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools