2019上JAVA第四周实验报告
Java实验报告 班级 计算机科学与技术二班 学号 20188442 姓名 吴怡君 实验内容
(1) 使用构造函数完成各属性的初始赋值 (2) 使用get…()和set…()的形式完成属性的访问及修改 (3) 提供计算面积的getArea()方法和计算周长的getLength()方法
import java.util.Scanner; import java.util.Date; class Handle { private String sign,password,name="none",date; private double balance; public Handle(String password,double balance){ this.setPassword(password); this.setBalance(balance); } public String getsign() { return sign; } public void setsign(String sign) { this.sign = sign; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getBalance() { return balance; } public void setBalance(double balance) { this.balance = balance; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } } public class 银行系统 { static Handle per[]=new Handle[100]; static int i=-1; static int id=0; static String s; public static void main(String[] args) { // TODO Auto-generated method stub for(int j=0;j<100;j++){ per[j]=new Handle("123456",0.0); } zhuyemian(); } public static void yewu(int i) { // TODO Auto-generated method stub System.out.println("1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回"); Scanner input=new Scanner(System.in); switch(input.nextInt()){ case 1:System.out.println("存款金额:"); per[i].setBalance(input.nextDouble()+per[i].getBalance()); System.out.println("存款成功!");yewu(i); case 2:System.out.println("取款金额:"); if(per[i].getBalance()-input.nextDouble()<0){ System.out.println("余额不足!");yewu(i); } else{ per[i].setBalance(per[i].getBalance()-input.nextDouble()); System.out.println("取款成功!");yewu(i); } case 3:System.out.println("请输入新密码:"); per[i].setPassword(input.next()); System.out.println("修改成功!");yewu(i); case 4:System.out.println("您的账户标识为:"+per[i].getsign());yewu(i); case 5:System.out.println("您的姓名为:"+per[i].getName());yewu(i); case 6:System.out.println("您的开户日期为:"+per[i].getDate());yewu(i); case 7:System.out.println("您的余额为:"+per[i].getBalance());yewu(i); case 0:zhuyemian(); } } public static void denglu() { // TODO Auto-generated method stub System.out.println("请输入您的姓名:"); Scanner input=new Scanner(System.in); s=input.next(); i=-1; while(i<99){ i++; if(s.equals(per[i].getName())){ System.out.println("请输入您的密码:"); if(input.next().equals(per[i].getPassword())){ System.out.println("登陆成功!"); yewu(i); } else{ System.out.println("姓名或密码有误,请重新输入"); denglu(); } } } System.out.println("没有此用户!"); zhuyemian(); } public static void kaihu() { // TODO Auto-generated method stub per[id]=new Handle("123456",0.0); if(id>=100){ s="uniqueid"+id; per[id].setsign(s); }else if(id>=10){ s="uniqueid0"+id; per[id].setsign(s); }else{ s="uniqueid00"+id; per[id].setsign(s); } Date date=new Date(); per[id].setDate(date.toString()); System.out.println("请输入您的姓名:"); Scanner input=new Scanner(System.in); per[id].setName(input.next()); System.out.println("开户成功,您的初始密码为123456,请尽快更改!"); id++; denglu(); } public static void zhuyemian() { // TODO Auto-generated method stub System.out.println("1:开户 2:业务办理"); Scanner input =new Scanner(System.in); s=input.next(); if(s.equals("1")){ kaihu(); } if(s.equals("2")){ denglu(); } } } 运行结果 1:开户 2:业务办理 1 请输入您的姓名: 吴怡君 开户成功,您的初始密码为123456,请尽快更改! 请输入您的姓名: 吴怡君 请输入您的密码: 123456 登陆成功! 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 3 请输入新密码: 990903 修改成功! 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 1 存款金额: 10000000 存款成功! 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 4 您的账户标识为:uniqueid000 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 7 您的余额为:1.0E7 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 2 取款金额: 10000000 取款成功! 1:存款 2:取款 3:变更密码 4:查询账户标识 5:查询姓名 6:查询开户日期 7:当前余额 0:返回 实验过程 1. 写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。 package 面对对象Java开发程序设计; public class Rectangle { public static void main(String args[]){ double width=3,height=4; String color="blue"; Rectangle Rec = new Rectangle( width,height,color); Rec.getArea(); Rec.getLength(); Rec.getColor(); System.out.println("面积="+Rec.getArea()+",周长="+Rec.getLength()+",颜色:"+Rec.getColor()); } private double width,height; private String color; public Rectangle(double width,double height,String color){ this.setWidth(width); this.setHeight(height); this.setColor(color); } public void setWidth(double w){ width = w; } public void setHeight(double h){ height = h; } public void setColor(String c){ color = c; } public double getWidth(){ return width; } public double getHeight(){ return height; } public String getColor(){ return color; } public double getArea(){ return width*height; } public double getLength(){ return (width+height)*2; } } 课程总结:通过学习,我感觉学的不错,老师教的很好!李津老师讲课非常有活力,每堂课都自己操作,然后每个知识点讲的也是非常的特撤,JAVA类的基本构造规则啊,一讲就懂。运用起来非常方便,类也讲了不少东西了,基本都学到了。 具体思路:矩形的封装思路比较简单,看看书都知道,很简单的东西。 关于银行系统的思路很清晰:首先要明确题目要求,然后用姓名做密码,用字符控制用银行系统的功能,结合收取的信息完成。 目前只是个简单程序,还有很多问题,比如说开户这里最多达到1010,存钱是double型,所以有限制,所以后续可以继续优化其功能。 总体来说JAVA没有C语言那么多算法,但是调用的方法和有些东西却多得多,所以要持续努力。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |