Home Java javaTutorial Java makes a simple volleyball game scoring system

Java makes a simple volleyball game scoring system

Jun 30, 2017 am 10:27 AM
java Contest

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;
    }
  }
 
}
Copy after login

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 of this Website
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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles