zoukankan      html  css  js  c++  java
  • 暑假日报-15

    今天复习完了,开始尝试练习题
     public class 项目二

     private
     customerlist p=new customerlist(10);
     public
     customer cus;
     public static void main(String[] args)
     {
      狗 b=new 狗();
      b.display();
     } 
      Scanner scan=new Scanner(System.in);
     void display()
     {
      boolean isflag=true;
      while(isflag)
      {
      System.out.println("1:显示客户信息");
      System.out.println("2:添加客户信息");
      System.out.println("3:修改客户信息");
      System.out.println("4:删除客户信息");
      System.out.println("5:退           出 ");
      System.out.print("请选择选项:");
      int i=scan.nextInt();
      switch(i)
      {
      case 1:show();break;
      case 2:add();break;
      case 3:xiugai();break;
      case 4:shanchu();break;
      case 5:System.out.println("是否选择退出?(Y or N)");
      String s=scan.next();
      char c=s.charAt(0);
      if(c=='Y')
       isflag=false;
      else
       break;
      }
      }
     }
    void show()
    {
     System.out.println("***********客户记录***************");
     System.out.println("编号 姓名 年龄 性别 电话 邮箱 ");
     if(p.gettotal()==0)
     {
      System.out.println("没有客户记录! ");
     }
     else
     {
      int id=1;
      customer customer[]=p.getcustomers();
      for(int i=0;i<customer.length;i++){
    System.out.println(id+++" "+customer[i].name+" "+customer[i].age+" "+customer[i].sex+" "+customer[i].phone+" "+customer[i].email);
    }
     }
     System.out.println("****************************"); 
    }
    void add()
    {
     System.out.println("请输入姓名:");
     String name=scan.next();
     System.out.println("请输入年龄:");
     int age=scan.nextInt();
     System.out.println("请输入性别:");
     String sex=scan.next();
     System.out.println("请输入电话:");
     String phone=scan.next();
     System.out.println("请输入邮箱:");
     String email=scan.next();
        cus=new customer(name,age,sex,phone,email);
     boolean s=p.add(cus);
     if(s==true)
     {
      System.out.println("添加成功");
     }
     else
      System.out.println("添加失败");
    }
    void shanchu()
    {
     System.out.print("请输入删除的行数:");
     for(;;)
     {
     int a=scan.nextInt();
     if(a<=0||a>p.gettotal())
     {
      System.out.print("请输入正确的行数:");
     }
     else
     p.delete(a-1);
     break;
     }
    }
    void xiugai()
    {
     System.out.print("请输入修改的行数:");
     for(;;)
     {
     int a=scan.nextInt();
     if(a<=0||a>p.gettotal())
     {
      System.out.print("请输入正确的行数:");
     }
     else
     {
      System.out.println("请输入修改的地方:");
      String m=scan.next();
      switch(m)
      {
      case "姓名":
       System.out.println("请输入姓名:");
      String h=scan.next();
          String f=cus.name;
          cus.name=h;
          h=f;
             break;
      case "性别":
       System.out.println("请输入性别:");
       String j=scan.next();
           String k=cus.sex;
           cus.sex=j;
           j=k;
              break;
      case "年龄":
       System.out.println("请输入年龄:");
       int age=scan.nextInt();
           int p=cus.age;
           cus.age=age;
           age=p;
              break;
      case "电话": System.out.println("请输入电话:");
      String o=scan.next();
          String q=cus.sex;
          cus.sex=q;
          q=o;
       break;
      case "邮箱": 
       System.out.println("请输入邮箱:");
       String n=scan.next();
           String c=cus.sex;
           cus.sex=n;
           n=c;
       break;
      }
     boolean s=p.xiugai(a-1, cus);
     if(s==true)
     {
      System.out.println("修改成功!");
     }
     else 
     {
      System.out.println("修改失败!");
     }
     break;
     } 
        }
    }
    }
    class customer
    {
     public
     String name;
     String sex;
     String phone;
     String email;
      int age;
     public
     customer(String name,int age,String sex,String phone,String email) 
     {
      this.age=age;
      this.email=email;
      this.name=name;
      this.phone=phone;
      this.sex=sex;
     }
    }
    class customerlist
    {
     private
     customer cust[];
     int total;
     public
     customerlist(int index)
     {
       cust=new customer[index];
     } 
     boolean add(customer cus)
     {
      if(total>cust.length)
      {
       return false;
      }
      else
      {
       cust[total++]=cus;
       return true;
      }
     }
     boolean xiugai(int index,customer cus)
     {
      if(index<0||index>=total)
      {
       return false;
      }
      else
      {
       cust[index]=cus;
       return true;
      }
     }
     boolean delete(int index)
     {
      if(index<0||index>=total)
      {
       return false;
      }
      else
       for(int i=index;i<total-1;i++)
       {
        cust[i]=cust[i+1];
       }
      cust[total-1]=null;
      total--;
      return true; 
     }
     int gettotal()
     {
      return total;
     }
     customer[] getcustomers()
     {
      customer stu[]=new customer[total];
      for(int i=0;i<total;i++)
      {
       stu[i]=cust[i];
      }
      return stu;
     }
    }
    虽然是在视频的帮助下完成的,但我自己也修改了代码使得我自己也能看懂。总的来说,这次的代码虽然麻烦,但仔细思考了之后就明白了这之中的逻辑,其中也学到了许多我以前不知道的新知识,比如return返回数组和类的对象,最大的收获在于明白了些一个程序不能只在一个类中定义,要结合其他的类来进行调用,这也是我今天学到的最大的知识,项目二使我明白了这一点。明天我打算继续学习下一章视频,完成更多的作业。
  • 相关阅读:
    内核开发特点
    制作 patch
    sdram flash 区别
    数组名 函数名
    Html标签见解——关于position问题分组总结
    Html标签见解——margin和padding使用过程中所谓的bug问题《一》
    HTML标签见解——img
    关于float和clear
    业内杂谈——你认识“用户体验”吗?
    css控制窗口上下水平居中方案详解
  • 原文地址:https://www.cnblogs.com/L-L-ALICE/p/13357746.html
Copyright © 2011-2022 走看看