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语言).主要 ...
随机推荐
- shell编程-输入/输出重定向(十一)
linux中文件描述符 linux跟踪打开文件,而分配的一个数字,通过这个数字可以实现对文件的读写操作 用户可以自定义文件描述符范围是:3-max,max跟用户的ulimit –n 定义数字有关系,不 ...
- vs添加到附加进程调试(IIS页面调试)
有时候单元测试不是很方便,通过页面调试接口会更直观,也跟容易发现问题(尤其是在页面传参的时候),这时vs添加到附加进程的调试方式就显得尤为重要了! 步骤如下: 1.首先是通过IIS建立网站,(前提是要 ...
- Windows Server 2016-Win Ser 2016新增功能
本来想着整个系列都是与Active Directory相关的内容,上一章节我们应读者要求补充了Window Server 2016标准版与数据中心版的区别,鉴于读者的疑惑,从本章节开始补充三到五章与W ...
- 使用 cmd连接 Oracle,MySql,SQL Server 数据库
1. Oracle cmd连接数据库 语法: sqlplus 用户/口令(密码)@服务器IP/数据库实例名(SID) 1.1 方式一 数据库服务在本机上IP可以用localhost替换 sqlplus ...
- Linux系统中Redis和Tomcat的PID文件路径设置
Tomcat: /bin/catalina.sh 文件头注释下面添加一行:CATALINA_PID=/var/run/tomcat.pid Redis: redis.conf配置文件里面搜索pidfi ...
- 【2018.08.19 C与C++基础】编程语言类型系统简介(草稿)
还是先占坑,等理顺了思路再写,学过的东西总是无法系统化,感觉什么都知道一点,但一深入却是一脸懵逼. 这真的是个问题,看似很努力,却无法成为一个master. 参考链接: 1. 编程语言的类型系统为何如 ...
- TCP三次握手四次挥手过程详解
http://blog.csdn.net/imilli/article/details/50620104 TCP头部: 其中 ACK SYN 序号 这三个部分在以下会用到,它们的介绍也在下面. ...
- 数以亿计运行PHP的网站即将面临严重的安全风险
数以亿计运行PHP的网站即将面临严重的安全风险 根据W3Techs的统计数据,目前所有互联网站点中约有78.9%使用PHP运行.但是2018年12月31日,PHP 5.6.x的安全支持将正式停止,标志 ...
- C++ 参数传值 与 传引用
参数传值 在 C++ 中,函数参数的传递有两种方式:传值和传引用.在函数的形参不是引用的情况下,参数传递方式是传值的.传引用的方式要求函数的形参是引用.“传值”是指,函数的形参是实参的一个拷贝,在函数 ...
- [SHOI2015]脑洞治疗仪
嘟嘟嘟 这题其实就是一个线段树维护最大连续和的水题. 别的操作不说,操作1只要二分找区间前\(k\)个0即可. 需要注意的是,因为操作1两区间可能有交,因此要先清空再二分查询-- 复杂度\(O(n l ...