• 软件工程个人作业01


    1、程序设计思想

    程序设计主要运用了随机数的产生,四则运算的的两个数字用随机数产生的函数产生,符号也可以用随机数产生0代表+,1代表-以此类推,将产生数字的功能封装成一个函数,产生符号的功能写成一个函数,然后再有一个输出函数调用产生数字和符号的函数,再到主函数中调用输出函数即可。至于真分数,就是要控制分母的数值要大于分子即可。

    2、源程序代码:

    import java.util.Random;
    import java.util.Scanner;
    public class Size {
    public static void main(String args[])
    {
        boolean p=true;
        while(p)
        {
        Scanner in=new Scanner(System.in);
        System.out.println("1.整式计算 2.真分数计算");
        int ch=in.nextInt();
        if(ch==1)
        {
        System.out.println("请输入要计算的题的数量:");
        int number=in.nextInt();
        int i=0;
        while(i<number)
        {
          output();      
          i++;
        }
        }
        if(ch==2)
        {
        System.out.println("请输入要计算的题的数量:");
        int number=in.nextInt();
        int i=0;
        while(i<number)
        {
        zhenoutput();
          i++;
        }
        }
        }
    }
    public static void shuzi()
        {
            Random random=new Random();
            System.out.print(random.nextInt(100)+1);
        }
    public static void fuhao()
        {
        Random random=new Random();
        int f=random.nextInt(4);
        if(f==0)
            System.out.print('+');
        if(f==1)
            System.out.print('-');
        if(f==2)
            System.out.print('*');
        if(f==3)
            System.out.print('/');
        }
    public static void fenshu()
    {
        Random random=new Random();
        int fenmu=(random.nextInt(100)+1);
        int fenzi=(random.nextInt(100)+1);
        
        if(fenmu<=fenzi)
        {
            fenshu();
        }
        else
        {
            System.out.print(fenzi+"/"+fenmu);
        }    
    }
    public static void output()
    {
        Random random=new Random();
        int a=(random.nextInt(100)+1);
        int b=(random.nextInt(100)+1);
        int f=random.nextInt(4);
        if(f==0)
        {
            System.out.print(a);
            System.out.print('+');
            System.out.print(b);
            System.out.println("="+(a+b));
        }
            
        if(f==1)
        {
            System.out.print(a);
            System.out.print('-');
            System.out.print(b);
            System.out.println("="+(a-b));
        }
        if(f==2)
        {
            System.out.print(a);
            System.out.print('*');
            System.out.print(b);
            System.out.println("="+(a*b));
        }
        if(f==3)
        {
            System.out.print(a);
            System.out.print('/');
            System.out.print(b);
            System.out.println("="+(a/b));
        }
        }
    public static void zhenoutput()
    {
        fenshu();fuhao();fenshu();
        System.out.println("=");    
    }    
    }

    3、结果截图:

    4、未完成原因:

    eclipse运行时运行错误

    程序存在小问题没有使用封装函数的方法,一步步实现程序的功能。

  • 相关阅读:
    django 之(一) --- DjangoRestFormwork
    工具 --- Git理解
    部署 --- Docker使用
    django 之(三) --- 会话|关系|静态*
    flask 之(七) --- 认证|文件|部署
    系统 --- Linux系统环境搭建
    flask 之(六) --- API|RestfulApi
    flask 之(五) --- 对象|钩子|拆分
    数据类型检测
    基本数据类型和引入数据类型
  • 原文地址:https://www.cnblogs.com/hanbook/p/6501877.html
Copyright © 2020-2023  润新知