• java第二周的作业


    package java第二周学习;
    import javax.swing.JOptionPane;
    public class 数学题 {
    
    	private int a;
    	private int b;
    	private int d;
    	private String c;
        private  boolean e;
    	数学题(int a, int b, String c) {
    		this.a = a;
    		this.b = b;
    		this.c = c;
    	}
    	public void xianshi (int i)
    	{
    		String s;
    		s= JOptionPane.showInputDialog(a+c+b+"=" );
    		 d = Integer.parseInt(s);
    	}
    	public void pan() {
    		switch (c) {
    		case "+":
           if(a+b==d)
           {
        	   e=true;
           }
           else
           {
        	   e=false;
           }
    			break;
    		case "-":
    			 if(a-b==d)
    		       {
    		    	   e=true;
    		       }
    		       else
    		       {
    		    	   e=false;
    		       }
    			break;
    		case "*":
    			 if(a*b==d)
    		       {
    		    	   e=true;
    		       }
    		       else
    		       {
    		    	   e=false;
    		       }
    			break;
    		default:
    			 if(a/b==d)
    		       {
    		    	   e=true;
    		       }
    		       else
    		       {
    		    	   e=false;
    		       }
    			break;
    		}
    	}
    	public boolean isE() {
    		return e;
    	}
    	public void setE(boolean e) {
    		this.e = e;
    	}
    	public int getA() {
    		return a;
    	}
    	public void setA(int a) {
    		this.a = a;
    	}
    	public int getB() {
    		return b;
    	}
    	public void setB(int b) {
    		this.b = b;
    	}
    	public int getD() {
    		return d;
    	}
    	public void setD(int d) {
    		this.d = d;
    	}
    	public String getC() {
    		return c;
    	}
    	public void setC(String c) {
    		this.c = c;
    	}
    	
    	
    }
    

      

    package java第二周学习;
    
    import java.util.LinkedList;
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    
    public class 小学四年学习 {
    
    	@SuppressWarnings({ "unlikely-arg-type", "resource", "unused" })
    	public static void main(String[] args) {
    		LinkedList<数学题> shu = new LinkedList<数学题>();
    		int i = 0;
    		String f;
    		//生成数学题数据
    		while (i < 30) {
    			int a = (int) (Math.random() * 100);
    			int b = (int) (Math.random() * 100);
    			int c = (int) (Math.random() * 4);
    			switch (c) {
    			case 1:
    				f = "+";
    				break;
    
    			case 2:
    				f = "-";
    				break;
    			case 3:
    				f = "*";
    				break;
    			default:
    				f = "/";
    				break;
    			}
    			数学题 add = new 数学题(a, b, f);
    			shu.add(add);
    			i++;
    		}
    		 denglu(shu);
    	    
    		
    	}
    	 
    		
    		
    	// 计算得分和哪道题错误
    	public static void defen(LinkedList<数学题> a) {
    		int j = 0;
    		int m = 0;
    		for (int i = 0; i < a.size(); i++) {
    			if (a.get(i).isE()) {
    				j++;
    
    			} else {
    				m++;
    			}
    			
    		}
    		JOptionPane.showMessageDialog(null, "总分是 " + (j * 10), "您的水平", JOptionPane.PLAIN_MESSAGE);
    		JOptionPane.showMessageDialog(null, "错误了" +m+"道","您的水平", JOptionPane.PLAIN_MESSAGE);
    		for (int i = 0; i < a.size(); i++) {
    			if (!(a.get(i).isE())) {
    				
    				JOptionPane.showMessageDialog(null, (i+1)+"错误了","您的水平", JOptionPane.PLAIN_MESSAGE);
    			}
    		}
    	}
    		
    	// 开始
    	public static void open(LinkedList<数学题> a) {
    		for (int i = 0; i < a.size(); i++) {
    			a.get(i).xianshi(i);
    			a.get(i).pan();
    			JOptionPane.showMessageDialog(null, "您的答案是 " + a.get(i).isE(), "你的水平", JOptionPane.PLAIN_MESSAGE);
    		}
    		defen(a);
    
    	}
    	//账号登录界面
    	 public   static void denglu(LinkedList<数学题> a) 
    		{
    		String Zhanghao, Mima, W;
    		JOptionPane.showConfirmDialog(null, "小学四年级数学题", "数学是个好东西!", JOptionPane.YES_NO_CANCEL_OPTION);
    		Zhanghao = JOptionPane.showInputDialog("输入账号:");
    		if (Zhanghao.equals("555")) {
    			Mima = JOptionPane.showInputDialog("输入密码:");
    			if (Mima.equals("555")) {
    				int yanzhengma = (int) (Math.random() * 10000);
    				W = JOptionPane.showInputDialog("输入验证码:"+yanzhengma);
    				String s=Integer.toString(yanzhengma);
    				if(W.equals(s))
    				{
    					JOptionPane.showMessageDialog(null, "登录成功!");
    					  open(a);
    				}
    				else {
    					JOptionPane.showMessageDialog(null, "验证码错误");
    					}
    				
    				
    		}else {
    				JOptionPane.showMessageDialog(null, "密码错误");
    			}
    		}
    	      else {
    			JOptionPane.showMessageDialog(null, "无此账号记录");
    		}
    }
    }
    

      

  • 相关阅读:
    从零开始搭建系统1.2——Nginx安装及配置
    从零开始搭建系统1.1——CentOs安装
    从零开始搭框架——系统架构
    从零开始搭建系统——前言
    PHP语法入门以及变量
    用PHP写出计算器
    PHP常量以及基本数据类型
    PHP入门了解
    php中搭建Web服务器和服务器配置
    JS中for,for...in,for...of以及foreach循环的用法
  • 原文地址:https://www.cnblogs.com/gonT-iL-evoL-I/p/9752237.html
Copyright © 2020-2023  润新知