题目:       Java基本语法

课程名称:  JAVA语言程序设计

班    级:    信1705-1

姓    名:   刘雨馨     学号:   20173445

指导教师:    王建民

正文部分格式要求:

1、 正文汉子部分要求宋体小四,行间距固定值20磅;首行缩进两个字符。

2、 程序英文部分要求采用Times New Roman字体,行间距固定值20磅,程序缩进采用四个字符,程序部分要求采用必要的注释。

3、 实验报告要求完成以下三项内容:

1) 按照题目内容要求编写程序实现功能。

2) 实验报告中要求包括程序设计思想、程序流程图、源程序、实现结果截图、实验总结(包括调试过程中出现的错误等)。

一、

源程序:

Calculation.java

public class Calculation {

    private int operator;            //操作数
private int operand1; //操作数前面的数
private int operand2; //操作数后面的书
private int result; //运算结果,除法结果取整数部分
private int statistics; //统计正误 public int getResult(){
return result;
} public int getStatistics(){
return statistics;
} public Calculation( int operand1 , int operator , int operand2 ){
this.operand1 = operand1;
this.operator = operator;
this.operand2 = operand2;
} public void manager(){
switch(operator){
case 1:
System.out.println( operand1 +" + " + operand2 +" = " );
result = operand1 + operand2;
break;
case 2:
System.out.println( operand1 +" - " + operand2 +" = " );
result = operand1 - operand2;
break;
case 3:
System.out.println( operand1 +" * " + operand2 +" = " );
result = operand1 * operand2;
break;
case 4:
System.out.println( operand1 +" / " + operand2 +" = " );
result = operand1 / operand2;
break;
}
} public void judge( int result ){ //判断正误
if( this.result == result){
statistics = 1; //正确为1
}
else
statistics = 0; //错误为0
} }

Arithmetic.java

import java.util.Random;
import java.util.Scanner; public class Arithmetic {
@SuppressWarnings("resource")
public static void main( String[] args ){ Random rand = new Random();
Scanner in = new Scanner( System.in ); int operand1 = 0 ;
int operand2 = 0;
int operator;
int result;
int count=0; //统计正确的题目数量
int i;
Calculation[] cal = new Calculation[30]; //30道题目 //随机题目并显示序号与题目
for( i=0; i<30; i++ ){
operator = rand.nextInt(4)+1; switch( operator ){
case 1:
operand1 = rand.nextInt(100);
operand2 = rand.nextInt(100);
break;
case 2: //减法不出现负数
operand1 = rand.nextInt(100);
operand2 = rand.nextInt( operand1 );
break;
case 3: //乘除范围更小
operand1 = rand.nextInt(10);
operand2 = rand.nextInt(10);
break;
case 4:
operand1 = rand.nextInt(20);
operand2 = rand.nextInt(9)+1;
break;
} System.out.print( (i+1) +" ");
cal[i] = new Calculation( operand1, operator, operand2);
cal[i].manager();
result = in.nextInt(); //输入答案并判断正误
cal[i].judge( result);
} //结算
System.out.println("错误的题目及正确答案:");
for( i=0; i<30; i++){
if( cal[i].getStatistics() == 0 ){
System.out.println( i+1 +" "+ cal[i].getResult() );
}
else
count++;
} System.out.println();
System.out.println("题目总数30道,正确"+count+"道,错误"+(30-count)+"道");
}
}

实验结果截图

实验总结:
题目不难但是做的过程中小错误频发,不够细心也缺少练习,思路不确定,经常修改

调试错误:

原因是没有实例化对象,这个错误出现很多次了,需要注意记住

二、

源代码:

Random.java

public class Random {
private String rand; Random(){ //生成验证码
rand = "";
for( int i=0; i<6; i++ ){
int intVal = (int)(Math.random() * 26 + 97);
rand = rand + (char)intVal; //此处+用作连接符
} public void judge( String rand ){
if( this.rand.equals(rand) )
System.out.println("验证码正确");
else
System.out.println("验证码错误");
} public String getRand(){
return rand;
} }

Validate.java

import java.util.Scanner;

public class Validate {
public static void main( String [] args ){
String rand = new String();
@SuppressWarnings("resource")
Scanner in = new Scanner( System.in );
Random ran = new Random();
System.out.println(ran.getRand());
System.out.println("请输入验证码");
rand = in.next();
ran.judge(rand);
}
}

运行结果:

总结:

总的还算顺利,第一次输出的时候在验证码前面带了一个null,需要让rand为空

Java基本语法实验报告的更多相关文章

  1. 20145213《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDEA)

    20145213<Java程序设计>实验报告一:Java开发环境的熟悉(Windows+IDEA) 实验要求 使用JDK编译.运行简单的Java程序. 使用IDEA编辑.编译.运行.调试J ...

  2. 20145206《Java程序设计》实验二Java面向对象程序设计实验报告

    20145206<Java程序设计>实验二Java面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O. ...

  3. 20145233韩昊辰 《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDEA)

    20145233 <Java程序设计>实验报告一:Java开发环境的熟悉 实验要求 使用JDK编译.运行简单的Java程序: 使用IDEA 编辑.编译.运行.调试Java程序. 实验内容 ...

  4. 20145221 《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDEA)

    20145221 <Java程序设计>实验报告一:Java开发环境的熟悉(Windows+IDEA) 实验要求 使用JDK编译.运行简单的Java程序: 使用IDEA 编辑.编译.运行.调 ...

  5. 20145205 《Java程序设计》实验报告五:Java网络编程及安全

    20145205 <Java程序设计>实验报告五:Java网络编程及安全 实验要求 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.客户端中输入明文,利用DES算法加密,D ...

  6. 20145212《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDE)

    20145212<Java程序设计>实验报告一:Java开发环境的熟悉(Windows+IDE) 实验内容及步骤 1.命令行下的JAVA程序开发 建立并进入实验目录: 撰写简单的Hello ...

  7. 20145213《Java程序设计》实验二Java面向对象程序设计实验报告

    20145213<Java程序设计>实验二Java面向对象程序设计实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装,继承,多态 初步掌握UML建模 熟悉S.O. ...

  8. 20145206邹京儒《Java程序设计》实验报告一:Java开发环境的熟悉(Windows+IDEA)

    20145206<Java程序设计>实验报告一:Java开发环境的熟悉(Windows+IDEA) 实验内容及步骤 1.使用JDK编译.运行简单的Java程序: 建立实验目录: 在IDEA ...

  9. 20145308刘昊阳 《Java程序设计》实验二 Java面向对象程序设计 实验报告

    20145308刘昊阳 <Java程序设计>实验二 Java面向对象程序设计 实验报告 实验名称 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面相对象三要素:封 ...

随机推荐

  1. MysqlMd5加密

    MD5加密成功

  2. Python+Selenium学习--上传文件

    场景 文件上传操作也比较常见功能之一,上传功能操作webdriver 并没有提供对应的方法,关键上传文件的思路.上传过程一般要打开一个系统的window 窗口,从窗口选择本地文件添加.所以,一般会卡在 ...

  3. stark组件之分页【模仿Django的admin】

    我们的stark组件用的我们的分页组件,没有重新写 下面直接看下分页的代码 class page_helper(): def __init__(self, count, current_page, p ...

  4. 用户Cookie和会话Session、SessionId的关系

    一.客户端用cookie保存了sessionID 客户端用cookie保存了sessionID,当我们请求服务器的时候,会把这个sessionID一起发给服务器,服务器会到内存中搜索对应的sessio ...

  5. webpack.dev.conf.js

    var utils = require('./utils')var webpack = require('webpack')var config = require('../config') // 一 ...

  6. @params、@PathVariabl和@RequestParam用法与区别

    [1]params params: 指定request中必须包含某些参数值是,才让该方法处理. @RequestMapping(value = "testParamsAndHeaders&q ...

  7. windows7 Cygwin 下安装 YouCompleteMe 插件

    原创文章,欢迎指正!转载请注明~ 从上周就开始想在cygwin上安装YouCompleteMe插件,按照GITHUB上的官方教程安装,由于自己的理解失误,一直搞不清是按照在windows上安装还是按照 ...

  8. sql:inner join,left join,right join,full join用法及区别

    join的语法: select [字段] from [表名1] inner/left/right/full join [表名2] on [表名1.字段1] <关系运算符> [表名2.字段2 ...

  9. python pyMysql 自定义异常 函数重载

    # encoding='utf8'# auth:yanxiatingyu#2018.7.24 import pymysql __all__ = ['Mymysql'] class MyExcept(E ...

  10. oracle 分页 where 三层

    查询[start,start+limit],包含start,包含start+limit,如start=21,limit=10结果就是21到30,包含21和30SELECT * FROM (SELECT ...