zoukankan      html  css  js  c++  java
  • 系主任的试卷解答

    package 作业;
    
    import java.util.Scanner;
    
    import com.sun.org.apache.xpath.internal.operations.Equals;
    
    class Student
    {
        private String stunumber ="00000000" ;
        private String name ="***" ; 
        private int age =0;
        private boolean sex ; //男生为 false,女生为 true。
        private double score =0 ;
        Student(String stunumber,String name,int age , boolean sex , double score){
            this.stunumber = stunumber;
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.score = score;
        }
        Student ()
        {
            
        }
        public String getStunumber() {
            return stunumber;
        }
        public void setStunumber(String stunumber) {
            this.stunumber = stunumber;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
        public void getSex() {
            if (this.sex==true)
                System.out.printf("女生");
            else
                System.out.printf("男生");
        }
        public void setSex(boolean sex) {
            this.sex = sex;
        }
        public double getScore() {
            return score;
        }
        public void setScore(double score) {
            this.score = score;
        }
    }
    
    public class 作业 {
    
        public static void main(String[] args) {
            
             Student [] stu = new Student[10];
             stu [0] = new Student ("20170001","王大",18,true,88);
             stu [1] = new Student ("20170002","李二",17,false,68);
             stu [2] = new Student ("20170003","张三",16,true,66);
             stu [3] = new Student ("20170004","李四",16,false,93);
             stu [4] = new Student ("20170005","王五",17,true,83);
             stu [5] = new Student ();
             stu [6] = new Student ();
             stu [7] = new Student ();
             stu [8] = new Student ();
             stu [9] = new Student ();
            
             
                  int key=0 ;
                  System.out.println("    1、 遍历输出学生信息;");
                  System.out.println("    2、 新学生信息录入;");
                  System.out.println("    3、 删除学生信息;");
                  System.out.println("    4、 修改学生信息;");
                  System.out.println("    5、 查询学生信息;");
                  System.out.print("请输入:");
                @SuppressWarnings("resource")
                Scanner scanner = new Scanner (System.in );
                  key = scanner.nextInt();
                    // boolean a = true ; 
                
             switch (key) {
            case 1:
            
                 for (int i=0; i<10; i++)
                 {
                     if( stu[i].getName()!="***")
                     ShowStudent (stu[i]);
                     
                 }
                 break;
    
               case 2:
                   int j;
                      for (j=0;j<10;)
                 {   if( stu[j].getStunumber().equals("00000000"))
                              break;
                              else 
                              j=j+1;
                                 
                 }
                   
                 //  System.out.println(j);
                      System.out.printf("请输入学号 : ");
                     Scanner scanner1 = new Scanner (System.in );
                     String a=scanner1.next();
                     stu[j].setStunumber(a);
                    System.out.printf("请输入姓名 : ");
                    Scanner scanner2 = new Scanner (System.in );
                    String b=scanner2.next();
                    stu[j].setName(b);
                    System.out.printf("请输入年龄 : ");
                    Scanner scanner3 = new Scanner (System.in );
                     int c= scanner3.nextInt();
                     stu[j].setAge(c);
                    System.out.printf("请输入性别  : ");
                    Scanner scanner4 = new Scanner (System.in );
                    String d=scanner4.next();
                    {
                        boolean x ;
                        if(d=="女生")
                        {    x=true;
                            stu [j].setSex(x);
                            }
                        else if(d=="男生")
                        {
                            x = false;
                            stu [j].setSex(x);
                        }
                        else 
                        {
                            System.out.println("秀吉嘛?");
                        }
                    }
                    System.out.printf("请输入成绩 : ");
                    Scanner scanner5 = new Scanner (System.in );
                    double e= scanner5.nextDouble();
                        stu[j].setScore(e);
                       ShowStudent (stu[j]);
                break;
            case 3:
                int y =0;
                int z =0 ; 
                int k=0 ;
                  String f;
                Scanner scanner6 = new Scanner (System.in );
                  f = scanner.next();
                  for(k=0;k<10;k++)
                  {    
                      if(deleteStudent ( stu[k].getStunumber() ,f))
                      {
                          z=z+1 ;
                      }
                  }
                  if (z!=0)
                  {
                      y = 1;
                  }
                  else
                  {
                     
                      System.out.println("不存在 这个数据。");
                  }
                  for (k=0;k<10;k++)
                  {
                   if( deleteStudent ( stu[k].getStunumber() ,f ))
                   {
                       stu[k].setName("???");
                       stu[k].setStunumber("00000000");
                       stu[k].setScore(0);
                       stu[k].setAge(0);
                       break;
                   }
                  }
                  
                for(k=0;k<10;k++)
                {    
                    if(deleteStudent ( stu[k].getStunumber() ,f))
                    {
                        z=z+1 ;
                    }
                }
                if(y==1)
                {
                    System.out.println("删除成功!");
                }
                  break;
            case 4:
        
                break;
            case 5:
        
               break;
            default:
                break;
            }
                
             System.out.println(stu[5].getStunumber());
        
        }
        //第一个方法
        public static  void ShowStudent (Student stu1)
         {
        
                System.out.printf(" 学号 :"+stu1.getStunumber()+"     ");
                System.out.println();
                System.out.printf(" 姓名 :"+stu1.getName()+"     ");
                System.out.println();
                System.out.printf(" 年龄 :"+stu1.getAge()+"     ");
                System.out.println();
                System.out.printf(" 性别 :"+"     ");
                stu1.getSex();
                System.out.printf("     ");
                System.out.println();
                System.out.printf(" 成绩 :"+stu1.getScore()+"     ");
                System.out.println();
                System.out.printf("____________________");
                System.out.println();
    }
        // 第二个方法
        //public static  void addStudent ( String stunumber1, String name1, int age1, boolean sex1, double score1)
        //{
            //        Scanner scanner1 = new Scanner (System.in );
                //       age1=scanner1.nextInt();
        //}
        //第三个方法
        public static boolean     deleteStudent ( String stunumber3 ,String n )
     {       
             boolean n1= false;
              if(stunumber3==n)
              {
                  System.out.println("确定删除?");
                  n1 = true ;
              }
              return  n1;
     }
    }

    虽然这个还没写玩,还差俩个功能和最后实现的重复功能,但是还是发一下下以示兴奋!

  • 相关阅读:
    Windows Driver Mode 1
    一个程序员的奋斗经历 2
    JavaScript判断文件是否存在
    流程图个图标详解
    wget for windows
    软件的开发周期
    Firefox支持activex的插件
    第二次作业
    C/C++字符串使用整理
    c#学习小记录(1)
  • 原文地址:https://www.cnblogs.com/gonT-iL-evoL-I/p/9398075.html
Copyright © 2011-2022 走看看