Java开学测试源代码
Posted ZZKZS
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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开学测试源代码的主要内容,如果未能解决你的问题,请参考以下文章