管理系统:登录成功后可以选择自己的角色,并查看角色的工作任务(使用多态和抽象类来完成)...

  1 练习版:
  1 进步版:
  2 @control
  3 *Group.java
  4 package com.qsy.student.control;
  5 import com.qsy.student.dao.StuDao;
  6 import com.qsy.student.daoImpl.DaoImpl;
  7 import com.qsy.student.entity.Role;
  8 
  9 public class Group extends Role {
 10     @Override
 11     public void work() {
 12         System.out.println("我是组长,负责组内的同学的学习及生活的任务");
 13         StuDao stuDao=new DaoImpl();
 14         stuDao.work2();
 15     }
 16 }
 17 *ManageWork.java
 18 package com.qsy.student.control;
 19 import com.qsy.student.entity.Role;
 20 public class ManageWork   {
 21 
 22     //通过以下方法,能够查看到每种角色的工作任务
 23     public void getWork(Role role){
 24 
 25         role.work();
 26     }
 27 }
 28 *Monitor.java
 29 package com.qsy.student.control;
 30 import com.ccp.pri.Dao;
 31 import com.qsy.student.dao.StuDao;
 32 import com.qsy.student.daoImpl.DaoImpl;
 33 import com.qsy.student.entity.Role;
 34 public class Monitor extends Role {
 35     @Override
 36     public void work() {
 37         System.out.println("我是班长,负责全班同学的学习及生活的任务");
 38         StuDao stuDao=new DaoImpl();
 39         stuDao.work1();
 40     }
 41 }
 42 *StudentClass.java
 43 package com.qsy.student.control;
 44 import com.qsy.student.dao.StuDao;
 45 import com.qsy.student.daoImpl.DaoImpl;
 46 import com.qsy.student.entity.Role;
 47 public class StudentClass extends Role {
 48     @Override
 49     public void work() {
 50         System.out.println("我是最快乐的组员!!!");
 51         StuDao stuDao=new DaoImpl();
 52         stuDao.work3();
 53     }
 54 }
 55 *Work.java
 56 package com.qsy.student.control;
 57 import com.qsy.student.entity.Role;
 58 //查看所有学员的工作任务
 59 public class Work {
 60     public static void main(String[] args) {
 61     }
 62     public void getWork(Role role){
 63         System.out.println(role.role);
 64         role.work();
 65     }
 66 }
 67 @dao
 68 *ChouJangDao.java
 69 package com.qsy.student.dao;
 70 
 71 import com.qsy.student.entity.Sx;
 72 import com.qsy.student.service.StuService;
 73 import com.qsy.student.servicelmpl.StuServicelmpl;
 74 
 75 import java.util.Scanner;
 76 
 77 public class ChouJangDao {
 78     public void workk(){
 79 
 80         Scanner ins=new Scanner(System.in);
 81         System.out.println("开始抽奖么?Y/N");
 82         NNT:
 83         while (true){
 84             String me=ins.next();
 85             if ("Y".equals(me)){
 86             int mon;
 87             mon=((int)(Math.random()*100));
 88                 System.out.println("您抽到的数为:"+mon);
 89                 for (int i=0; i <3 ; i++) {
 90                     int mn=((int)(Math.random()*100));
 91                     if (mn==mon){
 92                         System.out.println("恭喜我们的Luckdog!!!");
 93                         break NNT;
 94                     }else {
 95                         System.out.println("彩票号码为:"+mn);
 96                         System.out.println("抱歉没有中奖!要再来一次么?Y/N");
 97                     }
 98                 }
 99 
100             }else {
101                 break;
102             }
103         }
104     }
105 }
106 *StuDao.java
107 package com.qsy.student.dao;
108 import com.qsy.student.entity.Sx;
109 import com.qsy.student.util.No;
110 import java.text.SimpleDateFormat;
111 import java.util.Calendar;
112 import java.util.Scanner;
113 public interface StuDao {
114     public Sx login();
115     public void zhuce();
116     public void work1();
117     public void work2();
118     public void work3();
119     void getAll();
120     void shan();
121 }
122 *Student_control.java
123 package com.qsy.student.dao;
124 import com.qsy.student.control.Group;
125 import com.qsy.student.control.ManageWork;
126 import com.qsy.student.control.Monitor;
127 import com.qsy.student.control.StudentClass;
128 import com.qsy.student.daoImpl.DaoImpl;
129 import com.qsy.student.entity.Role;
130 import com.qsy.student.util.No;
131 
132 import java.util.Scanner;
133 public class Student_control  {
134     StuDao stuDao=new DaoImpl();
135     Scanner ins=new Scanner(System.in);
136     public static void main(String[] args) {
137 
138     }
139     //对象数组登录注册
140 //    public Sx[] shuzu() {
141 //
142 //    }
143     public void login(){
144 
145     }
146     public void secMenu(){
147         System.out.println("————————欢迎进入登录系统—————————");
148         System.out.println("——————————1.查看学生工作任务——————");
149         System.out.println("——————————2.退出————————————");
150         System.out.println("——————————3.来抽奖啊——————————");
151         System.out.println("——————————4.查看全部信息————————");
152         System.out.println("——————————5.删除信息——————————");
153         System.out.println("——————————请选择您想要做的事情—————");
154         int no=new No().pp();
155         while (true){
156         if(no==1){
157             //调用学生的工作任务
158             ManageWork wk=new ManageWork();
159             System.out.println("请问您要查看谁的角色任务:");
160             String answer=ins.next();
161 
162             Role role = null;
163             if (Role.GROUP.equals(answer)) {
164                 role = new Group();
165             } else if (Role.MONITOR.equals(answer))
166                 role = new Monitor();
167             else  if (Role.STUDENT.equals(answer))
168                 role=new StudentClass();
169             wk.getWork(role);
170         }else if (no==2){
171             System.out.println("谢谢使用!。。。");break;
172         }else if(no==3){
173             System.out.println("欢迎来到天天快乐抽奖活动!^_^");
174             ChouJangDao chouJangDao=new ChouJangDao();
175             chouJangDao.workk();
176         }
177         else if (no==4){
178             System.out.println("查看所有信息");
179             stuDao.getAll();
180         }else if (no==5){
181             stuDao.shan();
182         }
183         else {
184             System.out.println("没有此选项!!!");
185         }
186 
187         }
188     }
189     }
190 @daoIpml
191 *DaoImpl.java
192 package com.qsy.student.daoImpl;
193 
194 import com.qsy.student.dao.StuDao;
195 import com.qsy.student.dao.Student_control;
196 import com.qsy.student.entity.Sx;
197 import com.qsy.student.util.No;
198 
199 import java.text.SimpleDateFormat;
200 import java.util.*;
201 
202 public class DaoImpl implements StuDao {
203     Scanner ins=new Scanner(System.in);
204     static int i=0;
205     static Sx student[];
206     static Sx sx1[];
207     static List list=new ArrayList();
208 
209     static {
210         student = new Sx[5];sx1=new Sx[0];
211         student[0]=new Sx(1,"校花",22,"女","实验小学","班长","2019/9/4");
212         student[1]=new Sx(2,"花",12,"女","实验小学","组长","2018/8/2");
213         student[2]=new Sx(3,"明",22,"男","第三中学","组员","2015/3/2");
214         i+=3;
215 
216         list.add(student[0]);
217         list.add(student[1]);
218         list.add(student[2]);
219     }
220     public Sx login(){
221         Map map = new HashMap() ;
222         Sx stu=null;
223         OUT:
224         while(true){
225             System.out.println("请输入想要查询name:");
226             String rr=ins.next();
227             System.out.println("请输入密碼:");
228             int mm=ins.nextInt();
229             Sx[] sxes=new Sx[list.size()];
230             list.toArray(sxes);
231             for (int j=0; j < sxes.length; j++) {
232             map.put(sxes[j].getName(),sxes[j].toString());
233         }
234             Set set = map.keySet() ;
235             /*Iterator it = set.iterator() ;//迭代
236             while(it.hasNext()){
237                 Object obj = it.next() ;
238                 System.out.println(obj.toString() + " : " + map.get(obj));
239             }*/
240             if (rr!=null){
241                 for (Object o:set) {
242                     //if (sxes[j]!=null){
243                         if (rr.equals(o)&& mm==123){
244                             //stu =sxes[j];
245                             System.out.println("祝贺你!登录成功");
246                             System.out.println(map.get(o));
247                             new Student_control().secMenu();
248                             break OUT;
249                         }
250                    // }
251                 }
252                 System.out.println("查无此人");
253             }
254             else{
255                 System.out.println("还要进行下面操作么?进行Y,不进行N");
256                 String aa=ins.next();
257                 if ("Y".equals(aa))
258                 {System.out.println("请重新输入name与密码");}
259                 else if ("N".equals(aa)){
260                     break OUT;
261                 }else{
262                     System.out.println("输入错误");
263                     break OUT;
264                 }
265             }
266         }
267         return stu;
268     }
269     public void zhuce(){
270 
271         System.out.println("请输入ID,name,age,sex,school,zhiwei,date:");
272         int id=ins.nextInt();
273         String name=ins.next();
274         int age=ins.nextInt();
275         String sex=ins.next();
276         String school=ins.next();
277         String zhiwei=ins.next();
278         Calendar calendar=Calendar.getInstance();
279         No no=new No();
280         System.out.println("请输入年:");
281         int year=no.pp();
282         System.out.println("请输入月:");
283         int month=no.pp();
284         System.out.println("请输入日:");
285         int day=no.pp();
286         calendar.set(year,month-1,day);
287         SimpleDateFormat sfd=new SimpleDateFormat("yyyy/MM/dd");
288         String date1=sfd.format(calendar.getTime());
289 
290         student[i]=new Sx(id,name,age,sex,school,zhiwei,date1);
291         list.add(student[i]);
292         i++;
293     }
294 
295     public void work1(){
296         bianli();
297         System.out.println("需要改么?Y/N");
298         String ss=ins.next();
299         if ("Y".equals(ss)){
300             System.out.println("想要修改那条(-1)数据?");
301             int cc=ins.nextInt();
302             System.out.println(student[cc].toString());
303             System.out.println("请输入修改后的数据:");
304             int zero=ins.nextInt();
305             String one=ins.next();
306             int two=ins.nextInt();
307             String Three=ins.next();
308             String four=ins.next();
309             String five=ins.next();
310             Calendar calendar=Calendar.getInstance();
311             No no=new No();
312             System.out.println("请输入年:");
313             int year=no.pp();
314             System.out.println("请输入月:");
315             int month=no.pp();
316             System.out.println("请输入日:");
317             int day=no.pp();
318             calendar.set(year,month-1,day);
319             SimpleDateFormat sfd=new SimpleDateFormat("yyyy/MM/dd");
320             String date1=sfd.format(calendar.getTime());
321             //student[cc]=new Sx(zero,one,two,Three,four,five,Six);
322             list.set(cc,new Sx(zero,one,two,Three,four,five,date1));
323             //System.out.println(student.toString());
324             bianli();
325             //替换某个元素
326 //            dogs.set(0,"博美");
327 //            it = dogs.iterator() ;
328 //            while (it.hasNext()){
329 //                System.out.println(it.next());
330 //            }
331         }
332     }
333     public void work2 (){
334         Sx[] sx=new Sx[list.size()];
335         list.toArray(sx);
336         for (Sx sx1:sx
337         ) {
338             if (sx1!=null){
339                 if (!sx1.getZhiwei().equals("班长")){
340                     System.out.println(sx1.toString());
341                 }
342             }
343         }
344         System.out.println("需要改么?Y/N");
345         String ss=ins.next();
346         if ("Y".equals(ss)){
347             System.out.println("想要修改那条(-1)数据?");
348             int cc=ins.nextInt()+1;
349             System.out.println(student[cc].toString());
350             System.out.println("请输入修改后的数据:");
351             int zero=ins.nextInt();
352             String one=ins.next();
353             int two=ins.nextInt();
354             String Three=ins.next();
355             String four=ins.next();
356             String five=ins.next();
357             Calendar calendar=Calendar.getInstance();
358             No no=new No();
359             System.out.println("请输入年:");
360             int year=no.pp();
361             System.out.println("请输入月:");
362             int month=no.pp();
363             System.out.println("请输入日:");
364             int day=no.pp();
365             calendar.set(year,month-1,day);
366             SimpleDateFormat sfd=new SimpleDateFormat("yyyy/MM/dd");
367             String date1=sfd.format(calendar.getTime());
368             list.set(cc,new Sx(zero,one,two,Three,four,five,date1));
369         }
370         list.toArray(sx);
371         for (Sx cc:sx
372         ) {
373             if(cc!=null){
374             if (!cc.getZhiwei().equals("班长")){
375                 System.out.println(cc);
376             }
377             }
378         }
379     }
380     public void work3(){
381         Sx[] sxs=new Sx[list.size()];
382         list.toArray(sxs);
383         System.out.println("请输入你的名字:");
384         String name1=ins.next();
385         for (int j=0; j <sxs.length ; j++) {
386             if (sxs[j]!=null){
387                 if (sxs[j].getName().equals(name1)){
388                     System.out.println(sxs[j].toString());
389                 }
390             }
391         }
392         System.out.println("需要改么?Y/N");
393         String ss=ins.next();
394         if ("Y".equals(ss)){
395             System.out.println("想要修改那条(-1)数据?");
396             int cc=ins.nextInt();
397             System.out.println(sxs[cc].toString());
398             System.out.println("请输入修改后的数据:");
399             int zero=ins.nextInt();
400             String one=ins.next();
401             int two=ins.nextInt();
402             String Three=ins.next();
403             String four=ins.next();
404             String five=ins.next();
405             Calendar calendar=Calendar.getInstance();
406             No no=new No();
407             System.out.println("请输入年:");
408             int year=no.pp();
409             System.out.println("请输入月:");
410             int month=no.pp();
411             System.out.println("请输入日:");
412             int day=no.pp();
413             calendar.set(year,month-1,day);
414             SimpleDateFormat sfd=new SimpleDateFormat("yyyy/MM/dd");
415             String date1=sfd.format(calendar.getTime());
416             list.set(cc,new Sx(zero,one,two,Three,four,five,date1));
417         }list.toArray(sxs);
418         for (int j=0; j <sxs.length ; j++) {
419             if (sxs[j].getName().equals(name1)){
420                 System.out.println(sxs[j].toString());
421             }
422         }
423 
424     }
425 
426     @Override
427     public void getAll() {
428         bianli();
429     }
430 
431     @Override
432     public void shan() {
433         System.out.println("请输入想要想删除的第几条信息:");
434         int t=ins.nextInt();
435 //         //删除对象
436 //        dogs.remove(dog[0]);
437 //         it = dogs.iterator() ;
438 //        while (it.hasNext()){
439 //            System.out.println(it.next());
440 //        }
441         list.remove(student[t]);
442         bianli();
443     }
444 
445     public void bianli(){
446         Iterator it = list.iterator() ;
447         while (it.hasNext()){
448             System.out.println(it.next());
449         }
450     }
451 }
452 @entity
453 *Role.java
454 package com.qsy.student.entity;
455 public abstract class Role {
456     public  String role;
457     public static  final String MONITOR = "班长"  ;
458     public static  final String GROUP = "组长" ;
459     public static  final String STUDENT = "组员" ;
460     public abstract void work();
461 }
462 *StudentInterface.java
463 package com.qsy.student.entity;
464 public interface StudentInterface {
465     int MIN=1;
466     int MAX=6;
467 }
468 *Sx.java
469 package com.qsy.student.entity;
470 
471 public class Sx {
472     private int ID;
473     private String name;
474     private int age;
475     private String sex;
476     private String school;
477     private String zhiwei;
478     private String date;
479 
480 
481     public String getDate() {
482         return date;
483     }
484 
485     public void setDate(String date) {
486         this.date=date;
487     }
488 
489 
490 
491     public String getZhiwei() {
492         return zhiwei;
493     }
494 
495     public void setZhiwei(String zhiwei) {
496         this.zhiwei=zhiwei;
497     }
498 
499     public static void main(String[] args) {
500         //Sx iss=new Sx();
501         //System.out.println(iss.getID()+" "+iss.getName()+" "+iss.getAge()+" "+iss.getSex()+" "+iss.getSchool()+" "+iss.zhiwei);
502     }
503     public Sx(int zero, String one, int two, String three, String four, String five, String six, String date1){
504 
505     }
506     @Override
507     public String toString(){
508         return "ID:"+ID+"  姓名:"+name+"  年龄:"+age+"  性别:"+sex+"  学校:"+school+"  职位:"+zhiwei+"  日期:"+date;
509     }
510 
511     public Sx(int ID, String name, int age, String sex, String school,String zhiwei,String date) {
512         this.ID=ID;
513         this.name=name;
514         this.age=age;
515         this.sex=sex;
516         this.school=school;
517         this.zhiwei=zhiwei;
518         this.date=date;
519     }
520 
521     public int getID() {
522         return ID;
523     }
524 
525     public void setID(int ID) {
526         this.ID=ID;
527     }
528 
529     public String getName() {
530         return name;
531     }
532 
533     public void setName(String name) {
534         this.name=name;
535     }
536 
537     public int getAge() {
538         return age;
539     }
540 
541     public void setAge(int age) {
542         this.age=age;
543     }
544 
545     public String getSex() {
546         return sex;
547     }
548 
549     public void setSex(String sex) {
550         this.sex=sex;
551     }
552 
553     public String getSchool() {
554         return school;
555     }
556 
557     public void setSchool(String school) {
558         this.school=school;
559     }
560 }
561 @service
562 *StuService.java
563 package com.qsy.student.service;
564 import com.ccp.pri.Student;
565 import com.qsy.student.entity.Sx;
566 public interface StuService {
567     void zhuce();
568     Sx login();
569 }
570 @serviceImpl
571 *StuServicelmpl.java
572 package com.qsy.student.servicelmpl;
573 import com.ccp.pri.Student;
574 import com.qsy.student.dao.StuDao;
575 import com.qsy.student.daoImpl.DaoImpl;
576 import com.qsy.student.entity.Sx;
577 import com.qsy.student.service.StuService;
578 public class StuServicelmpl implements StuService {
579     StuDao stuDao=new DaoImpl();
580     @Override
581     public void zhuce() {
582         stuDao.zhuce();
583     }
584     @Override
585     public Sx login() {
586         return stuDao.login();
587     }
588 }
589 @ui
590 *Start.java
591 package com.qsy.student.ui;
592 
593 import com.qsy.student.dao.Student_control;
594 import com.qsy.student.entity.StudentInterface;
595 import com.qsy.student.service.StuService;
596 import com.qsy.student.servicelmpl.StuServicelmpl;
597 import com.qsy.student.util.No;
598 import java.util.Scanner;
599 
600 public class Start implements StudentInterface {
601 
602     public static void main(String[] args) {
603         Student_control iss=new Student_control();
604         System.out.println("————————学生信息管理系统—————————");
605         System.out.println("——————————1.注册————————————");
606         System.out.println("——————————2.登录————————————");
607         System.out.println("——————————3.退出————————————");
608         new Start().sta();
609 
610     }
611     public void sta(){
612 
613         StuService nnm=new StuServicelmpl();
614         OUT:
615         while (true){
616         System.out.println("您想要做什么操作...");
617         Scanner ins=new Scanner(System.in);
618         NNT:
619         while(true){
620          int no=new No().pp();
621         if (no>=MIN&&no<=MAX){
622             if (no==1){
623                 System.out.println("注册Y/N");
624                 String fen=ins.next();
625                 while ("Y".equals(fen)){
626                     nnm.zhuce();
627                     System.out.println("您还需要添加学生信息吗?Y/N");
628                     fen = ins.next();
629                 }
630 
631                break;
632             }else if (no==2){
633                 System.out.println("登录");
634                 nnm.login();
635                 break ;
636             }else if (no==3){
637                 System.out.println("谢谢使用...祝您生活愉快!");
638                 break OUT;
639             }else{
640                 System.out.println("无此选项,请重新选择...");
641             }
642         }
643         else {
644             System.out.println("请输入1-3的数字");
645         }
646         }
647         }
648     }
649 }
650 @util
651 *NO.java
652 package com.qsy.student.util;
653 
654 import java.util.Scanner;
655 
656 public class No {
657     public int pp(){
658         Scanner ins=null;
659         int no=0;
660         while (true){
661             ins=new Scanner(System.in);
662         if (ins.hasNextInt()){//判断从控制台输入的是不是数字
663             no=ins.nextInt();
664             break;
665         }System.out.println("输入数字错误,请重新输入数字");
666         }return no;
667     }
668 }
 
  

 

  2 ******************************Classinterface.java**********************************
  3 package com.ccp.pri;
  4 public interface Classinterface {
  5     String BANZHANG="班长";
  6     String ZUZHANG="组长";
  7     String ZUYUANONE="组员1";
  8     String ZUYUANTWO="组员2";
  9 }
 10 ******************************Control.java***************************************
 11 package com.ccp.pri;
 12 import java.util.Scanner;
 13 public class Control implements Classinterface{
 14     GS student[] = new GS[4];
 15     public static void main(String[] args) {
 16         Control con=new Control();
 17         con.zhuce();
 18         con.login();
 19     }
 20     //Scanner ins=new Scanner(System.in);
 21     public  GS[] zhuce(){
 22        Father.nn(student);
 23         /*System.out.println("请输入name,age,sex,like,classB,school,JG:");
 24         String name=ins.next();
 25         int age=ins.nextInt();
 26         String sex=ins.next();
 27         String like=ins.next();
 28         String classB=ins.next();
 29         String school=ins.next();
 30         String JG=ins.next();
 31         student[i+2]=new GS(name,age,sex,like,classB,school,JG);*/
 32         return this.student;
 33     }
 34     public void login(){
 35         Scanner ins=new Scanner(System.in);
 36         String ss;
 37         System.out.println("请选择登录的身份:"+Classinterface.BANZHANG+", "+Classinterface.ZUZHANG+", "+Classinterface.ZUYUANONE+", "+Classinterface.ZUYUANTWO);
 38         for (int i=0;i<this.student.length; i++) {
 39             ss=ins.next();
 40             if (ss!=null){
 41                 if (this.student[i].getName()!=null){
 42                     if (Classinterface.BANZHANG.equals(this.student[i].getName())&&ss.equals(Classinterface.BANZHANG)){
 43                         System.out.println(this.student[0].getName()+"  "+this.student[0].getAge()+"  "+this.student[0].getJG());
 44                         System.out.println(this.student[1].getName()+"  "+this.student[1].getAge()+"  "+this.student[1].getJG());
 45                         System.out.println(this.student[2].getName()+"  "+this.student[2].getAge()+"  "+this.student[2].getJG());
 46                         System.out.println(this.student[3].getName()+"  "+this.student[3].getAge()+"  "+this.student[3].getJG());
 47                         /*for (int j=0; j <student.length; j++) {
 48                             System.out.println(student[j].getName()+"  "+student[j].getAge()+"  "+student[j].getJG());
 49                         }*/
 50                         new Son().change();
 51                         break;
 52                     }else if (Classinterface.ZUZHANG.equals(this.student[1].getName())&&ss.equals(Classinterface.ZUZHANG)){
 53                             //System.out.println(this.student[0].getName()+"  "+this.student[0].getAge()+"  "+this.student[0].getJG());
 54                             System.out.println(this.student[1].getName()+"  "+this.student[1].getAge()+"  "+this.student[1].getJG());
 55                             System.out.println(this.student[2].getName()+"  "+this.student[2].getAge()+"  "+this.student[2].getJG());
 56                             System.out.println(this.student[3].getName()+"  "+this.student[3].getAge()+"  "+this.student[3].getJG());
 57                             new Zuzhang().change();break;
 58                     }else if (Classinterface.ZUYUANONE.equals(this.student[2].getName())&&ss.equals(Classinterface.ZUYUANONE)) {
 59                         System.out.println(this.student[2].getName()+"  "+this.student[2].getAge()+"  "+this.student[2].getJG());
 60                         new Zuyuan().change();
 61                         break;
 62                     }else if (Classinterface.ZUYUANTWO.equals(this.student[3].getName())&&ss.equals(Classinterface.ZUYUANTWO)){
 63                         System.out.println(this.student[2].getName()+"  "+this.student[3].getAge()+"  "+this.student[3].getJG());
 64                         new Zuyuan2().change();
 65                         break;
 66                     }else{
 67                         System.out.println("无此身份,请重新输入");
 68                     }
 69                 }else{
 70                     System.out.println("不能为null,请重新输入");
 71                 }
 72             }break;
 73         }
 74     }
 75 }
 76 ********************************GS.java*****************************************
 77 package com.ccp.pri;
 78 public class GS {
 79     private String name;
 80     private int age;
 81     private String sex;
 82     private String like;
 83     private String classB;
 84     private String school;
 85     private String JG;
 86 
 87     public static void main(String[] args) {
 88         /*GS student=new GS();
 89         GS[] sr=new GS[4];
 90         sr[0]=new GS("班长",42,"内蒙");
 91         sr[1]=new GS("组长",22,"内蒙");
 92         sr[2]=new GS("组员",12,"内蒙");
 93         sr[3]=new GS("组员",32,"内蒙");
 94         System.out.println(sr[0].getName());
 95         System.out.println(sr[1].getName());
 96         System.out.println(sr[2].getName());
 97         System.out.println(sr[3].getName());*/
 98     }
 99     public GS(){
100     }
101     public GS(String name, int age,/* String sex, String like, String classB, String school,*/ String JG) {
102         this.name=name;
103         this.age=age;
104         /*this.sex=sex;
105         this.like=like;
106         this.classB=classB;
107         this.school=school;*/
108         this.JG=JG;
109     }
110     public String getName() {
111         return name;
112     }
113     public void setName(String name) {
114         this.name=name;
115     }
116     public int getAge() {
117         return age;
118     }
119     public void setAge(int age) {
120         this.age=age;
121     }
122     public String getSex() {
123         return sex;
124     }
125     public void setSex(String sex) {
126         this.sex=sex;
127     }
128     public String getLike() {
129         return like;
130     }
131     public void setLike(String like) {
132         this.like=like;
133     }
134     public String getClassB() {
135         return classB;
136     }
137     public void setClassB(String classB) {
138         this.classB=classB;
139     }
140     public String getSchool() {
141         return school;
142     }
143     public void setSchool(String school) {
144         this.school=school;
145     }
146     public String getJG() {
147         return JG;
148     }
149     public void setJG(String JG) {
150         this.JG=JG;
151     }
152 }
153 ***************************************Father.java*******************************
154 
155 package com.ccp.pri;
156 public abstract class Father {
157     GS student[] = new GS[4];
158     //public abstract void Ostudent();
159     public abstract void change();
160     static void nn(GS[] student) {
161         student[0]=new GS("班长",42,"内蒙");
162         student[1]=new GS("组长",22,"内蒙");
163         student[2]=new GS("组员1",12,"内蒙");
164         student[3]=new GS("组员2",32,"内蒙");
165     }
166 }
167 ******************************Son.java******************************************
168 package com.ccp.pri;
169 import com.qsy.student.sx.Sx;
170 import java.util.Scanner;
171 public class Son extends Father {
172     //GS student[] = new GS[4];
173     public static void main(String[] args) {
174     }
175 //    @Override
176 //    public void Ostudent() {
177 //
178 //        nn(student);
179 //    }
180 
181     @Override
182     public void change() {
183         Scanner ins=new Scanner(System.in);
184         System.out.println("班长,是否要确认修改?Y/N");
185         String ss=ins.next();
186 
187         if ("Y".equals(ss)){
188             //Sx isx = new Sx();
189             for (int i=0; i <student.length ; i++) {
190                 System.out.println("修改第"+(i+1)+"数据");
191                 System.out.println("请输入职务,年龄,籍贯");
192                 String zhiwu=ins.next();
193                 int age=ins.nextInt();
194                 String jg=ins.next();
195                 student[i]=new GS(zhiwu,age,jg);
196             }
197             System.out.println("修改后的数据为:");
198             for (int i=0; i <student.length; i++) {
199                 System.out.println(student[i].getName()+"  "+student[i].getAge()+"  "+student[i].getJG());
200             }
201         }else{
202             System.out.println("谢谢惠顾");
203         }
204     }
205 }
206 *********************************Zuzhang.java***********************************
207 package com.ccp.pri;
208 import java.util.Scanner;
209 public class Zuzhang extends Father {
210 //    @Override
211 //    public void Ostudent() {
212 //
213 //    }
214 /*static void nn(GS[] student) {
215     //student[0]=new GS("班长",42,"内蒙");
216     student[0]=new GS("组长",22,"内蒙");
217     student[1]=new GS("组员",12,"内蒙");
218     student[2]=new GS("组员",32,"内蒙");
219 
220 }*/
221 
222     @Override
223     public void change() {
224         Scanner ins=new Scanner(System.in);
225         System.out.println("组长,是否要确认修改?Y/N");
226         String zz=ins.next();
227         if ("Y".equals(zz)){
228             //Sx isx = new Sx();
229             //GS student[] = new GS[4];
230             Son.nn(student);
231             for (int i=0; i <student.length ; i++)
232                 if (student[i].getName().equals("班长")) {
233                     continue;
234                 } else {
235                     System.out.println("修改第" + (i) + "数据");
236                     System.out.println("请输入职务,年龄,籍贯");
237                     String zhiwu=ins.next();
238                     int age=ins.nextInt();
239                     String jg=ins.next();
240                     student[i]=new GS(zhiwu, age, jg);
241                 }
242             System.out.println("修改后的数据为:");
243             for (int i=0; i <student.length; i++) {
244                 if (student[i].getName().equals("班长")){
245                     continue;
246                 }
247                 System.out.println(student[i].getName()+"  "+student[i].getAge()+"  "+student[i].getJG());
248             }
249         }else{
250             System.out.println("谢谢惠顾");
251         }
252     }
253 }
254 ********************************Zuyuan.java*************************************
255 package com.ccp.pri;
256 import java.util.Scanner;
257 public class Zuyuan extends Father {
258     @Override
259     public void change() {
260         Scanner ins=new Scanner(System.in);
261         for (int j=0; j <student.length ; j++) {
262                 System.out.println("组员1,是否要确认修改?Y/N");
263                 String zz=ins.next();
264                 if ("Y".equals(zz)) {
265                     Son.nn(student);
266                     for (int i=0; i < student.length; i++){
267                             System.out.println("请输入职务,年龄,籍贯");
268                             String zhiwu=ins.next();
269                             int age=ins.nextInt();
270                             String jg=ins.next();
271                             student[i]=new GS(zhiwu, age, jg);
272                             System.out.println("修改后的数据为:");
273                             System.out.println(student[i].getName() + "  " + student[i].getAge() + "  " + student[i].getJG());
274                         break;
275                     }
276                 }
277                  else {
278                     System.out.println("谢谢惠顾");
279                 }
280         }
281     }
282 }
283 ********************************Zuyuan2.java************************************
284 package com.ccp.pri;
285 import java.util.Scanner;
286 public class Zuyuan2 extends Father {
287     @Override
288     public void change() {
289         Scanner ins=new Scanner(System.in);
290         System.out.println("组员2,是否要确认修改?Y/N");
291         String cc=ins.next();
292         for (int j=0; j <student.length ; j++)
293             if ("Y".equals(cc)) {
294                 Son.nn(student);
295                 for (int i=0; i < student.length; i++)
296                     if (student[i].getName().equals("组员2")) {
297                         System.out.println("请输入职务,年龄,籍贯");
298                         String zhiwu=ins.next();
299                         int age=ins.nextInt();
300                         String jg=ins.next();
301                         student[i]=new GS(zhiwu, age, jg);
302                         System.out.println("修改后的数据为:");
303                         System.out.println(student[i].getName() + "  " + student[i].getAge() + "  " + student[i].getJG());
304                     break;
305                     }
306             } else {
307                 System.out.println("谢谢惠顾");
308             }
309     }
310 }

 

转载于:https://www.cnblogs.com/qsy0021/p/11291169.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值