资源描述:
《Java实验三实验报告1.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、淮海工学院计算机工程学院实验报告书课程名:《Java语言实验与课程设计指导》题目:实验3——深入面向对象编程班级:学号:姓名:评语:成绩:指导教师:批阅时间:年月日实验题目:1.定义一个学生类,定义一个大学生类和小学生类,这两个类是学生类的子类;定义一个选课接口,由大学生类实现该接口,定义一个年龄异常处理,当小学生年龄小于7岁时,弹出异常。2.定义一个银行卡类,定义一个信用卡类和普通银行卡类,这两个类是银行卡类的子类;定义一个透支的接口,信用卡可以透支,普通银行卡不可以透支。定义一个取款异常和透支异常,当普通银行卡取款超过银行卡余额时,弹出“取款异常”;当信用卡透
2、支超过2万元时弹出“透支异常”。实验代码:题1源代码:importjava.awt.*;classstudent{Stringnumber,name,sex,bj;intage;student(Stringxuehao,Stringxingming,Stringxingbie,intnianling,Stringbanji){number=xuehao;name=xingming;sex=xingbie;age=nianling;bj=banji;}}interfacexuanke{abstractvoidselect(Strings);}interfaceill
3、egal{abstractvoidillegal(ints);}classprimaryextendsstudentimplementsillegal{Stringxx;primary(Stringxuehao,Stringxingming,Stringxingbie,intnianling,Stringbanji,Stringxiaoxue){super(xuehao,xingming,xingbie,nianling,banji);xx=xiaoxue;}publicvoidillegal(ints){age=s;if(age<7)System.out.pri
4、ntln("出错~学生"+name+"的年龄过小!");}}classcollegeextendsstudentimplementsxuanke{Stringdx,xk;college(Stringxuehao,Stringxingming,Stringxingbie,intnianling,Stringbanji,Stringdaxue){super(xuehao,xingming,xingbie,nianling,banji);dx=daxue;}publicvoidselect(Strings){xk=s;}}publicclasstest_1{publ
5、icstaticvoidmain(Stringargs[]){primaryp1=newprimary("1","张三","男",13,"五(1)班","ZZZ小学");System.out.println(p1.number+""+p1.name+""+p1.sex+""+p1.age+""+p1.bj+""+p1.xx);p1.illegal(p1.age);primaryp2=newprimary("2","小红","女",6,"一(1)班","YYY小学");System.out.println(p2.number+""+p2.name+""+p2.s
6、ex+""+p2.age+""+p2.bj+""+p2.xx);p2.illegal(p2.age);collegec1=newcollege("3","小茗","女",20,"软件112","XXX大学");c1.select("现代密码学");System.out.print(""+c1.number+""+c1.name+""+c1.sex+""+c1.age+""+c1.bj+""+c1.dx+""+c1.xk+"");}}实验结果:题2源代码:importjava.util.*;classbankcard{Stringkh,name;double
7、yue;bankcard(Stringkahao,Stringyezhu,doubleshengyu){kh=kahao;name=yezhu;yue=shengyu;}}interfacetouzhi{abstractvoidtz(doubles);abstractvoidtzye(doubles);abstractvoidillegal();}interfaceqkillegal{abstractvoidillegal();}classcommonextendsbankcardimplementsqkillegal{common(Stringkahao,Str
8、ingye