Java开学测试源代码
package sample;
import java.io.IOException;
import java.io.Serializable;
import java.util.Scanner;
import java.util.ArrayList;
public class Account
{
private String accountID;
private String accountname;
private String operatedate;
private int operatetype;
private String accountpassword;
private int accountbalance;
private int amount;
public Account(String aaccountID, String aaccountname,String aoperatedate,int aoperatetype,String aaccountpassword,int aaccountbalance,int aamount)
{
accountID=aaccountID;
accountname=aaccountname;
operatedate=aoperatedate;
operatetype=aoperatetype;
accountpassword=aaccountpassword;
accountbalance=aaccountbalance;
amount=aamount;
}
public String getaccountID() {return accountID;}
public void setaccountID(String aaccountID) {accountID=aaccountID;}
public String getaccountname() {return accountname;}
public void setacccountname(String aaccountname) {accountname=aaccountname;}
public String getoperatedate() {return operatedate;}
public void setoperatedate(String aoperatedate) {operatedate=aoperatedate;}
public int getoperatetype() {return operatetype;}
public void setoperatetype(int aoperatetype) {operatetype=aoperatetype;}
public String getaccountpassword() {return accountpassword;}
public void setaccountpassword(String aaccountpassword) {accountpassword=aaccountpassword;}
public int getaccountbalance() {return accountbalance;}
public void setaccountbalance(int aaccountbalance) {accountbalance=aaccountbalance;}
public int getamount() {return amount;}
public void setamount(int aamount) {amount=aamount;}
public static void main(String[] args) {
String user = "zhan";//用户名
String pwd = "123";//密码
float money = 100f ;//初始余额
welcome();
if (login(user,pwd)){
//登录成功
@SuppressWarnings("resource")
Scanner sc = new Scanner(System.in);
while (true){
System.out.println("1、查询 2、存款 3、取款 4、修改密码 5、退出");
switch (sc.nextInt()){
case 1 :
searchMoney(money);
break;
case 2 :
money += saveMoney();
break;
case 3 :
money -= getMoney(money);
break;
case 4 :
pwd = changePwd(pwd);
break;
case 5 : System.exit(0); break;
default :;break;
}
}
}else{
//登录失败
//System.out.println("登录失败,系统退出!");
System.exit(0);
}
}
/**
* 欢迎登陆界面 *
*
* * */
public void FileWiter()
{
File file = null;
FileWriter fw = null;
file = new File("D:\\eclipse\\安装\\accountinformation.txt");
try {
if (!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(file);
for(int i = 1;i <=5;i++){
fw.write("20173528 zhangsan 2018-09-20 0 000000 1000 0");//向文件中写内容
fw.write("20173529 lisi 2018-09-20 0 000000 1000 0");
fw.write("20173530 wangwu 2018-09-20 0 000000 1000 0");
fw.write("20173531 zhaoliu 2018-09-20 0 000000 1000 0");
fw.write("20173532 qinqi 2018-09-20 0 000000 1000 0");
fw.flush();
}
System.out.println("写数据成功!");
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fw != null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void welcome (){
System.out.println("***********************");
System.out.println("——欢迎登陆———");
System.out.println("***********************");
System.out.println("***********************");
System.out.println("***********************");
}
/**
* 登陆--检测用户名和密码
*
* */
public static boolean login (String user ,String pwd){
@SuppressWarnings("resource")
Scanner sc = new Scanner (System.in);
for (int i = 3 ;i>0;i--){
System.out.println("请输入用户名:");
String checkUser = sc.next();//用户输入 用户名
System.out.println("请输入密码:");
String checkPwd = sc.next();//用户输入 密码
// .equals()匹配字符串
if (user.equals (checkUser) && pwd.equals (checkPwd) ){
System.out.println("登陆成功!");
return true ;
}else {
if ( i ==1 ){
System.out.println("你的卡被吞!!找相关人员");
return false ;
}
System.out.println("用户名或密码错误!今日剩余次数:"+ (i-1));
}
}
return false ;
}
/**
*查询余额
*
* */
public static void searchMoney (float money){
System.out.println("你的余额为"+money);
}
/**
*存款
*
* */
public static float saveMoney (){
System.out.println("请输入存款金额:");
@SuppressWarnings("resource")
Scanner sc = new Scanner (System.in);
float saveMoney = sc.nextFloat();
if (saveMoney > 10000){
System.out.println("单次最大存款金额为1000.0元");
saveMoney=0;
}else if (saveMoney < 0){
System.out.println("不能存负数的钱!!");
saveMoney=0;
}else if (saveMoney %100!= 0){
System.out.println("不能存零钱!!");
saveMoney=0;
}else{
System.out.println("存款成功!");
}
return saveMoney ;
}
/**
*取款
*
* */
public static float getMoney (float money){
System.out.println("请输入取款金额:");
@SuppressWarnings("resource")
Scanner sc = new Scanner (System.in);
float getMoney = sc.nextFloat();
if (getMoney > 10000){
System.out.println("单次最大取款金额为1000.0元");
getMoney=0;
}else if (getMoney < 0){
System.out.println("不能取负数的钱!!");
getMoney=0;
}else if (getMoney %100!= 0){
System.out.println("不能取零钱!!");
getMoney=0;
}else if (money <getMoney ){
System.out.println("余额不足!!");
getMoney=0;
}else {
System.out.println("取款成功!");
}
return getMoney ;
}
/**
*修改密码
*
* */
public static String changePwd(String oldPwd) {
System.out.println("请输入旧密码:");
@SuppressWarnings("resource")
Scanner sc = new Scanner (System.in);
String pwd = sc.next();
if (pwd.equals(oldPwd)){
//老密码正确;
System.out.println("请输入新密码:");
String newPwd_1= sc.next();
System.out.println("请再次输入新密码:");
String newPwd_2= sc.next();
if (newPwd_1.equals(newPwd_2)){
System.out.println("密码修改成功!");
return newPwd_1 ;
}else{
System.out.println("两次密码不一致,请重新修改!");
return oldPwd ;
}
}else {
System.out.println("旧密码输入错误,请重新修改!");
}
return oldPwd ;
}
}
Java开学测试源代码的更多相关文章
- Java开学测试
这次开学测试要求做一个信息系统,该系统完成学生成绩录入,修改,计算学分积点和查询学生成绩的简单功能. 下面是我写的代码 //信1805-3班 20183641 赵树琪 package test; im ...
- JAVA 开学测试
package StudentScore; public class ScoreInformation { String stunumber; //学号 String name; //姓名 doubl ...
- Java开学测试感想
开学第一堂课就是测试,测试暑假的自学成果,老师说试卷适当提高了难度,所以允许查书和使用网络查询,经过近三个钟头的努力奋斗和痛苦挣扎,我只完成了一小部分的代码,只有简单的set()get()函数,以及简 ...
- Java开学测试-学生成绩管理系统
题目: 1.定义 ScoreInformation 类,其中包括七个私有变量(stunumber, name, mathematicsscore, englishiscore,networkscore ...
- java开学考试有感以及源码
一.感想 Java开学测试有感 九月二十号,王老师给我们上的第一节java课,测试. 说实话,不能说是十分有自信,但还好,直到看见了开学测试的题目,之前因为已经做过了王老师发的16级的题目,所以当时还 ...
- JAVA语言课堂测试源代码及使用截图
1源代码 第一部分 package 开学测试.java;class ScoreInformation {String stunumber;String name;double mathematicss ...
- Java常用测试工具
第一部分:九款性能测试 Java入门 如果你才刚开始接触Java世界,那么要做的第一件事情是,安装JDK——Java Development Kit(Java开发工具包),它自带有Java Runti ...
- 第一次java程序测试感受
第一次JAVA程序设计测试,检验了一个暑假的成果.显而易见,我做的并不是很好,程序最起码的输入输出以及方法的定义还是没有问题的,但是考到了文件输入输出便看出来了.对于文件的输入输出,虽然我预习到那里, ...
- Java Junit测试框架
Java Junit测试框架 1.相关概念 Ø JUnit:是一个开发源代码的Java测试框架,用于编写和运行可重复的测试.它是用于单元测试框架体系xUnit的一个实例(用于java语言).主要 ...
随机推荐
- sql server 计算两个时间 相差的 几天几时几分几秒
CAST ( CAST ( DATEDIFF ( ss, StartTime, ConcludeTime ) / ( 60 * 60 * 24 ) AS INT ) AS VARCHAR ) + '天 ...
- 在CentOS上配置SAMBA共享目录(转载)
在CentOS上配置SAMBA共享目录 From: https://blog.csdn.net/qiumei1101381170/article/details/53265341 2016年11月21 ...
- 洗礼灵魂,修炼python(63)--爬虫篇—re模块/正则表达式(1)
爬虫篇前面的某一章了,我们要爬取网站页面源代码的数据,要从中获取到我们想要的数据,是不是感觉很费力,确实费力对吧?那么有没有什么有利的工具来解决这个问题呢?那就是这一篇博文的主题—— 正则表达式简介 ...
- Android长时间定时任务实现
在服务的onStartCommand方法里面使用AlarmManager 定时唤醒发送广播,在广播里面启动服务 每次执行startService方法启动服务都会执行onStartCommand 1.服 ...
- nmap参数原理抓包分析
nmap参数原理抓包分析 实验环境: Nmap7.70 实验步骤: 1.主机发现 2.端口扫描 3.服务版本探测 一.主机发现 主机发现,如果主机活跃,扫描1000个常用的tcp端口 1.Nmap i ...
- php中jpgraph库的使用
用Jpgraph,只要了解它的一些内置函数,可以轻松得画出折线图.柱形图.饼状图等图表. 首先要保证PHP打开了Gd2的扩展: 打开PHP.ini,定位到extension=php_gd2.dll,把 ...
- June 18. 2018, Week 25th. Monday
Health and cheerfulness naturally beget each other. 安康喜乐,相生相成. From Joseph Addison. Good health is a ...
- java操作elasticsearch实现query String
1.CommonTersQuery: 指定字段进行模糊查询 //commonTermsQuery @Test public void test35() throws UnknownHostExcept ...
- [福大软工] Z班 软件工程实践总结 作业成绩
作业要求 http://www.cnblogs.com/easteast/p/8081265.html 评分细则 本次作业评分满分为20分,分为五个部分,分别如下: 回望过去(5'):以实际数据总结分 ...
- E. Magic Stones CF 思维题
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...