zoukankan      html  css  js  c++  java
  • 软件工程个人作业01

    1、设计思想

    首先先建立一个类,在类中创建函数,将随机产生数字的功能封装成一个函数,将随机产生符号的功能封装成一个函数,然后调用实现整数的加减。真分数就需要控制分数的分母大于分子。

    2、源程序代码:

    import java.util.Random;
    import java.util.Scanner;
    class jisuan{
        public static double rand(){
            double n = 0;
            Random ra =new Random();    
            int a=ra.nextInt(100)+1;
            {System.out.print(a);
            n=a;}
            return n;
        
        }
        public static char fuhao(){
            char n = 0;
            Random ra =new Random();    
            int c=ra.nextInt(100)+1;
            if(c>=0&&c<25){System.out.print("+"); n = '+';}
            if(c<50&&c>=25){System.out.print("-"); n = '-';}
            if(c>=50&&c<75){System.out.print("*"); n = '*';}
            if(c>=75&&c<100){System.out.print("/"); n = '/';}    
            return n;        
        }  
        public static double zhen(){
            double n = 0;
            Random b =new Random();int b1=b.nextInt(10)+1;
            Random c =new Random();int c1=c.nextInt(10)+1;     
            if(b1>=c1||b1==c1){
                zhen();
            }
            else{
            System.out.print(b1+"/");System.out.print(c1);
            n=b1/c1;
            }
            return n;
        }
        public static double zhengzhen(){
            double n = 0;
            Random a =new Random();int a1=a.nextInt(10)+1;
            Random b =new Random();int b1=b.nextInt(10)+1;
            Random c =new Random();int c1=c.nextInt(10)+1;     
            if(b1>c1){
                zhengzhen();
            }
            else if(b1==c1){
                System.out.print(a1);
                n=a1;
                }
            else{    
                System.out.print(b1+"/");System.out.print(c1);
                n=b1/c1;
            }
            return n;
        }
        public static void zhengshow(){      
            
            rand();fuhao();rand();System.out.println("=");
        }
        public static void zhenshow(){
            
            zhen();fuhao();zhen();System.out.println("=");
            
        }
        public static void zhengzhenshow(){
            
            zhengzhen();fuhao();zhengzhen();System.out.println("=");
            
        }
        public static double daan(){
            double n = 0;
            switch(fuhao()){
            case '+':n=rand()+rand();
            case '-':n=rand()-rand();
            case '*':n=rand()*rand();
            case '/':n=rand()/rand();
            }
            return n;
        }
    
    }
    public class test {
        public static void main(String[] args){
            Scanner in = new Scanner(System.in);
            System.out.println("请输入显示式子的个数:");
            int m = in.nextInt();
            System.out.println("1.式子只有整数");
            System.out.println("2.式子只有真分数");
            System.out.println("3.式子随机产生");
            System.out.println("请输入要执行的操作:");
            String[] strArray=new String[m];
             int type = in.nextInt();
            switch(type){
            case 1:{
                for(int i = 0;i<m;i++){
                jisuan.zhengshow();        
                
                    }
                } break;
            
            case 2:{
                for(int i = 0;i<m;i++){
                jisuan.zhenshow();
                }
                } break;
            
            case 3:{ 
                for(int i = 0;i<m;i++){
                    jisuan.zhengzhenshow();
                    }
                    } break;
            
            }
        }
        }

    3、运行结果截图:

    4、上课未完成原因:

    实验出现错误,没有及时改正。没有封装函数,导致功能混乱。

  • 相关阅读:
    Atitit.隔行换色  变色 css3 结构性伪类选择器
    Atitit.jpg png格式差别以及解决jpg图片不显示的问题
    Atitit.jpg png格式差别以及解决jpg图片不显示的问题
    Atitit.预定义变量与变量预处理器
    Atitit.jpg png格式差别以及解决jpg图片不显示的问题
    Atitit.预定义变量与变量预处理器
    Atitit.增强系统稳定性----虚拟内存的设置
    Atitit.md5 实现原理
    Atitit.增强系统稳定性----虚拟内存的设置
    Atitit.md5 实现原理
  • 原文地址:https://www.cnblogs.com/muxiaozhou/p/6511259.html
Copyright © 2011-2022 走看看