您好,欢迎访问三七文档
Java打印程序:Account类importjava.io.*;classAccount{privateStringnumber=null;//卡号privateStringname=null;//客户姓名privateStringpassword=null;//客户密码privatedoublemoney=0.0;//余额publicAccount(Stringnumber,Stringname,Stringpassword,doublemoney)//构造方法,以生成多个储户信息{this.number=number;this.name=name;this.password=password;this.money=money;}protectedStringget_number(){returnnumber;}protectedStringget_Name(){returnname;}protectedStringget_Password(){returnpassword;}protecteddoubleget_Money(){returnmoney;}protectedvoidsub_Balance(doublemon)//余额减少{money-=money;}protectedvoidadd_Balance(doublemon)//余额增加{money+=money;}}importjava.io.*;classATM{Accountact;publicATM(){act=newAccount(000,test,111,5000);}//实例protectedvoidWelcome(){//欢迎界面Stringstr=————————————————————————————————;System.out.println(str);System.out.println(1、取款。);System.out.println(2、查询。);System.out.println(3、存款。);System.out.println(4、退出系统。);System.out.println(str);}protectedvoidLoad_Sys()throwsException{//登录系统Stringcard,pwd;intcounter=0;BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));//创建标准输入输出流do{System.out.println(请输入你的卡号:);card=br.readLine();//读取键盘输入信息System.out.println(请输入你的密码:);pwd=br.readLine();if(!isRight(card,pwd)){System.out.println(你的卡号或密码输入有误);counter++;}elseSysOpter();}while(counter3);System.exit(1);//应用退出}protectedvoidSysOpter()throwsException{//系统操作提示intnum;BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));System.out.println(请选择你要操作的项目(1-4):);num=br.read();//num为Unicode码转换的整数switch(num){case49:GetBalance();break;case50:Inqu_Info();break;case51:AddBalance();break;case52:Exit_Sys();break;}System.exit(1);}protectedvoidInqu_Info()throwsException{//信息查询System.out.println(—————————————————————————);System.out.println(账号:+act.get_number());System.out.println(姓名:+act.get_Name());System.out.println(余额:+act.get_Money());System.out.println(—————————————————————————);SysOpter();}publicvoidGetBalance()throwsException{//取款Stringstr=null,str1;BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));do{System.out.println(请输入取款数目:);str=br.readLine();doublequ=Double.valueOf(str).doubleValue();//将字符串转换为double类型if(quact.get_Money()){System.out.println(余额不足,请重新输入你要取的数目:);}else{act.sub_Balance(qu);System.out.println(取款成功,你的账户余额为:+act.get_Money());Welcome();SysOpter();}}while(true);}publicvoidAddBalance()throwsException//存款{Stringstr=null,str1;BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));do{System.out.println(请输入存款数目:);str=br.readLine();doublequ=Double.valueOf(str).doubleValue();act.add_Balance(qu);System.out.println(存款成功,你的账户余额为:+act.get_Money());Welcome();SysOpter();}while(true);}protectedbooleanisBalance()//判断卡内是否有钱{if(act.get_Money()0)returnfalse;returntrue;}protectedbooleanisRight(Stringcard,Stringpwd)//卡号密码是否正确{if(act.get_number().equals(card)&&act.get_Password().equals(pwd))returntrue;elsereturnfalse;}protectedvoidExit_Sys(){System.out.println(感谢你使用本系统,再见);System.exit(1);}}publicclassTest{//Test类为主类publicstaticvoidmain(String[]args)throwsException{ATMatm=newATM();atm.Welcome();atm.Load_Sys();}}第五章packageTestShape;abstractclassShape//抽象方法取得图形的面积{publicabstractdoublegetArea();}classSquareextendsShape{//通过继承定义正方形子类Squareprivatedoubleheight=0;//正方形的边长publicSquare(doubleheight){this.height=height;}publicdoublegetArea()//重写getArea()方法{return(this.height*this.height);}}classCircleextendsShape{//通过继承定义圆子类Circleprivatedoubler=0;//圆的半径privatefinalstaticdoublePI=3.14;publicCircle(doubler){this.r=0;this.r=r;}publicdoublegetArea()//重写getArea()方法{return(PI*r*r);}}classTriangleextendsShape{privatedoublea=0;//三角形的边1privatedoubleb=0;//三角形的边2privatedoublec=0;//三角形的边3privatedoubleh=0;//三角形的高publicTriangle(doublea,doubleh){this.a=a;this.h=h;}publicTriangle(doublea,doubleb,doublec){this.a=a;this.b=b;this.c=c;}publicdoublegetArea(){if(h==0){//根据海伦公式求三角形的面积doubles=(a+b+c)/2;returnMath.pow(s*(s-a)*(s-b)*(s-c),0.5);}elsereturn(a*h/2);}}publicclassTestShape{//测试类publicstaticvoidmain(String[]args){Shapesquare=newSquare(3);//构造一个边长为3的正方形Shapecircle=newCircle(2);//构造一个半径为2的圆Shapetriangle1=newTriangle(3,4,5);//构造一个边长分别为3、4、5的三角形Shapetriangle2=newTriangle(3,4);//构造一个高和底分别为3、4的三角形System.out.println(square.getArea());System.out.println(circle.getArea());System.out.println(triangle1.getArea());System.out.println(triangle2.getArea());}}6章importjava.util.*;classStudent{//定义学生Student类intid;//学号Stringgender;//性别Stringname;//姓名Datebirth;//出生日期publicStudent(intid,Stringname,Stringgender,Datebirth){this.id=id;this.name=name;this.gender=gender;this.birth=birth;}publicStringtoString(){returnid+-+name+-+gender+-+birth;}}publicclassStuManager{//定义StuManager类intSTU_NUM=10;TreeMapstuList=newTreeMap();voidinitStudents(){//初始化学生信息for(inti=0;iSTU_NUM;i++){intid=i;Stringname=name+(int)(Math.random()*1000);Stringgender=女;if(i%2==0)gender=男;Datebirth=newDate(newDate().getTime()+(long)(Math.random()*1000));//随机生成出生日期Studentstu=newStudent(id,name,gender,birth);stuList.put(id,stu);}}StudentsearchByID(intid){Studentstu=(Student)stuList.get(id);returnstu;}
本文标题:Java打印程序
链接地址:https://www.777doc.com/doc-2881028 .html