Home > Java > javaTutorial > Java makes a simple volleyball game scoring system

Java makes a simple volleyball game scoring system

怪我咯
Release: 2017-06-30 10:27:53
Original
2567 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template