zoukankan      html  css  js  c++  java
  • 软件工程概论课后作业1

    一.程序设计思想

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

    二.源程序代码

    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("=");   
    }   
    }

    三.结果截图

  • 相关阅读:
    ::在c++中的应用
    VS2008工程一些操作
    vs2008添加链接库
    从服务器 (PC 端 ) 发送图片到客户端 (android 手机端 ) [转]
    Android PowerImageView实现,可以播放动画的强大ImageView[转]
    INI文件读写
    关于超链接伪类的使用,:link,:visited,:hover
    关于div的居中显示
    常见公告栏信息效果的实现
    利用ul,li,span,position:relative实现文本的居中显示
  • 原文地址:https://www.cnblogs.com/cxr0711/p/6511537.html
Copyright © 2011-2022 走看看