我的程序有问题,不是代码问题,而是我要怎么做,这是我一直困惑的部分。只是为了让你知道我是一个基本的Java编码器,我不理解复杂的东西,所以请记住,我的代码不是最好的。

——————————————————————————————————————————————程序说明---

在我向您展示我的问题之前,让我们先来解释一下它是如何工作的,好吧,当您执行程序时,它会提示您一个类似于视频游戏中的菜单,但它是基于文本的,它会向您显示不同的选项,如输入玩家详细信息、玩数学游戏显示分数,然后退出。输入玩家详细信息它告诉玩家1输入他/她姓名,然后告诉另一个输入他/她玩家姓名,然后提示您返回菜单。玩数学游戏是要求玩家1输入他/她数学公式,然后玩家2必须解决它,如果他得到正确的他/她得到10分,如果没有,玩家没有得到任何点。然后重复让另一个玩家输入他/她数学公式,然后提示您返回菜单。显示分数-显示谁在数学游戏中得到的分数最多-计算谁得到的分数最多如果他们两个得到的分数相同,则表示平局,然后提示您返回菜单。最后一件事,退出选项,当你选择该选项,它停止程序。如果玩家选择了一个错误的选项,他会收到一条错误信息,并将您放回菜单

好的,这里是第一个类,叫做menu,另一个类,它与名为game parties的菜单相连接

所以这段代码我自己找不到

import java.util.*;

public class Gamefunctions // this is a core when player choosess one of these options from the menu

{

String[] player =new String[2];

double scorea = 0; // verribles of all the objects

double scoreb = 0;

int i;

Scanner input = new Scanner(System.in);

double answer = 0;

double numA, numB;

char operator;

char operator2;

boolean quit = false;

double sum1;

double sum2;

public void enterDetails(){ // if player select enter details

for ( i=0;i<2;i++) {// tell's player to input he/she's name and stores them

int c=i;

System.out.println("Welcome to the maths quiz game please input player name "+c++);

player[i] = input.next();

}

}

public void mathGame(){ // if player select enter details

System.out.println("Please enter your equation please "+player[0]+" press enter for each number and mathematical symbol"); // tells the player 1 to input

System.out.println("");

System.out.println("such as for ex input a number or how many you like, then hit enter and input such as /*-+^ hit enter, then input any number one or how many you like ");

String s=input.next();

numA = Double.parseDouble(s); // numa and numb and operator is the aera of player to input he/she equation

operator = input.next().charAt(0);

numB = input.nextDouble();

if () {

if (operator == '+') {// this is if operator is one of these like +-*/^ and then it works out the sum

answer = numA + numB;

}

if (operator == '-') {

answer = numA - numB;

}

if (operator == '*') {

answer = numA * numB;

}

if (operator == '/') {

answer = numA / numB;

}

if (operator == '^') {

answer = Math.pow(numA, numB);

}

} else {

System.out.println("error input like for an example '10' enter '+' enter '10'");

}

System.out.println("");

System.out.println(player[1]+"\t solve the equation"); // tells other player to slove the equation

sum2 = input.nextDouble();

if (sum2 == answer){// checks if the answer from the player is good or not if its good he/she gets 10 points if he/she gets it wrong gets no points and shows the right answer so the player learns from his/she mistakes

scoreb = scoreb + 10.00;

System.out.println("correct you got 10 points to your score");

System.out.println("");

} else{

System.out.println("incorrect you got no points the correct answer was:"+"" + answer);

}

你知道当程序要求玩家输入他的数学方程并输出它,然后继续程序并等待用户输入

public void mathGame(){ // if player select enter details

System.out.println("Please enter your equation please "+player[0]+" press enter for each number and mathematical symbol"); // tells the player 1 to input

System.out.println("");

System.out.println("such as for ex input a number or how many you like, then hit enter and input such as /*-+^ hit enter, then input any number one or how many you like ");

String s=input.next();

numA = Double.parseDouble(s); // numa and numb and operator is the aera of player to input he/she equation

operator = input.next().charAt(0);

numB = input.nextDouble();

假设玩家输入的是10+10回车,但由于它们存储在一个int的numa中,所以不能工作,我想发一条错误消息说你不能输入10+10,你必须输入10+10回车,这样它才能工作

如果播放机输入正确,它将继续程序

所以,如果你解释我的文章有任何问题,请允许我编辑它,谢谢你的时间:

java手动输入函数_Java程序如何添加一个函数,如果玩家输入错误,它将返回代码。...相关推荐

  1. java set子集_Java程序来检查一个集合是否是另一个集合的子集

    Java程序来检查一个集合是否是另一个集合的子集 在这个实例中,我们将学习Java中检查一个集合是否是另一个集合的子集. 要理解此示例,您应该了解以下Java编程主题: 示例1:使用HashSet类检 ...

  2. 如何在RCP程序中添加一个banner栏

    前言:这段时间还算比较空闲,我准备把过去做过的有些形形色色,甚至有些奇怪的研究总结一下,也许刚好有人用的着也不一定,不枉为之抓耳挠腮的时光和浪费的电力.以前有个客户提出要在RCP程序中添加一个bann ...

  3. Java黑皮书课后题第4章:*4.8(给出ASCII码对应的字符)编写程序,得到一个ASCII码的输入(0~27之间的一个整数),然后显示该字符

    *4.8(给出ASCII码对应的字符)编写程序,得到一个ASCII码的输入(0~27之间的一个整数),然后显示该字符 题目 题目概述 运行示例 引申 代码 题目 题目概述 *4.8(给出ASCII码对 ...

  4. 对类HelloWorld程序中添加一个MessageBox弹窗

    对类HelloWorld程序中添加一个MessageBox弹窗 分析: 任一程序运行的时候都会加载kernel32.dll的,但MessageBoxA()这个API却是在user32.dll中的.所以 ...

  5. Java IO练习--在程序中写一个“HelloJavaWorld你好世界“输出到操作系统文件Hello.txt文件中

    package com.kj.test;import cn.hutool.core.io.IoUtil;import java.io.File; import java.io.FileOutputSt ...

  6. java内联_JAVA中的内联函数

    在说内联函数之前,先说说函数的调用过程. 调用某个函数实际上将程序执行顺序转移到该函数所存放在内存中某个地址,将函数的程序内容执行完后,再返回到 转去执行该函数前的地方.这种转移操作要求在转去前要保护 ...

  7. 算法训练 加法运算(你的表妹正在学习整数的加法,请编写一个程序来帮助她学习。该程序调用了一个函数GetTwoInts,由它来返回两个从键盘读入的100以内的整数,然后计算这两个整数之和,并把答案显示)

    问题描述 你的表妹正在学习整数的加法,请编写一个程序来帮助她学习.该程序调用了一个函数GetTwoInts,由它来返回两个从键盘读入的100以内的整数,然后计算这两个整数之和,并把答案显示出来.要求: ...

  8. matlab子函数调用变量,matlab中,怎么样用function自定义函数调用另一个函数名为输入?...

    点击查看matlab中,怎么样用function自定义函数调用另一个函数名为输入?具体信息 答:test定义两个参数,一个是函数,一个是函数的变量. function [z]=test11(funna ...

  9. Python---编写一个函数,提示输入两个数字a,b,并进行a与b的除法运算。

    题目: 编写一个函数,提示输入两个数字 a,b ,并进行 a 与 b 的除法运算,把运算结果打印出来.要求对输入和程序进行检测,可以排除所有的错误. 源代码: def devision():try:a ...

最新文章

  1. 动态卷积超进化!通道融合替换注意力,减少75%参数量且性能显著提升 | ICLR 2021
  2. 直接用Win32 API创建对话框Demo
  3. Ubuntu之GCC:GCC编译器的简介、安装、使用方法之详细攻略
  4. 请看:我是如何在SQLServer中处理每天四亿三千万记录的
  5. SpringSpringMVCMybatis框架-张晨光-专题视频课程
  6. 基于php的外卖订餐系统开题报告_订餐系统开题报告.doc
  7. pythonsearch结果_python 查询Elasticsearch的小例子
  8. F5/LVS/Nginx/HAProxy硬软件级网络负载均衡介绍
  9. 阿里影业出品影片《1917》斩获奥斯卡多项大奖 有望国内院线上映
  10. 【Es】es修改mapping报错Validation Failed: 1: mapping type is missing
  11. Flink Parallelism
  12. netsh winsock reset什么意思_IOS14.2rc是什么意思?ios14.2rc怎么样?[多图]-手机资讯...
  13. RabbitMQ基础知识详解
  14. 游戏开发最佳10个工具与技术方案
  15. 神舟飞天,与有荣焉!麒麟信安操作系统筑牢神舟十四号发射软件基石!
  16. 烽火通信 c语言 笔试,C语言嵌入式笔试题目及参考答案-烽火通信.doc
  17. WHMCS V7.60 新增短信宝短信插件
  18. 概率论与数理统计的基本概念
  19. 2021年保育员(中级)考试题及保育员(中级)考试报名
  20. 黑马程序员pink老师前端入门教程,零基础必看的h5(html5)+css3+移动端前端视频教程(HTML)

热门文章

  1. STM32 基础系列教程 30 - 文件系统
  2. Android的系统服务一览
  3. 数字信号处理篇(一) 采样定理
  4. 单片机联网,UIP实现tcp/udp协议
  5. Linux学习记录-11
  6. AI+云 华为开启智能时代新纪元
  7. 图片加载之SDWebImage(上)
  8. Jquery DataTable服务端分页的最佳实现
  9. 键盘样式风格有关设置-iOS开发
  10. c++中构造函数 、析构函数的作用域详解