第一个java项目

对着这个学的

02、项目实战:ATM系统架构搭建、欢迎页面设计_哔哩哔哩_bilibili

学java安全,还是稍微学一点点的java,这次是写了两个小时写的,这辈子第一个jama项目呜呜呜

main

1
2
3
4
5
6
7
8
9
package org.example;
import java.util.ArrayList;
import java.lang.*;
public class Main {
public static void main(String[] args) {
atm test=new atm();
test.start();
}
}

atm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package org.example;
import java.io.*;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;

public class atm {
ArrayList<account> total=new ArrayList<account>();
private int flag=-1;
public void start(){
while(true){
System.out.println("======================请输入您的操作====================");
System.out.println("1.登录 2.注册 3.查询 4.存钱 5,取钱 6.注销账号 7.退出登录 8.退出程序");
Scanner put_in=new Scanner(System.in);
String options=put_in.next();
switch (options){
case "1":login();break;
case "2":register();break;
case "3":select_account();break;
case "4":account_in();break;
case "5":account_out();break;
case "6":account_delete();break;
case "7":flag=-1;
System.out.println("成功退出登录");
break;
case "8":return;
}
}
}
public void login(){
if (flag!=-1){
System.out.println("您已经登录!");
return;
}
System.out.println("请输入您的账号:");
Scanner put_in=new Scanner(System.in);
String account_name=put_in.next();
for(int i=0;i<=total.size();i++){
if (i==total.size()){
System.out.println("输入的账号不存在!");
return;
}
if(Objects.equals(total.get(i).getAccount_name(), account_name)) {
flag=i;
break;
}
}
System.out.println("请输入密码:");
String secret=put_in.next();
if(Objects.equals(total.get(flag).getAccount_secret(), secret)){
System.out.println("登录成功!");
}else System.out.println("密码错误!");
}
public void register(){
System.out.println("请输入您的账号:");
Scanner put_in=new Scanner(System.in);
String account_name=put_in.next();
System.out.println("请输入您的密码:");
String secret=put_in.next();
double money=0;
total.add(new account(account_name,secret,money));
System.out.println("注册成功!");
}
public void select_account(){
if (!status())return;
System.out.println("您的账户如下");
System.out.println("账户名字:"+total.get(flag).getAccount_name());
System.out.println("账户余额"+total.get(flag).getAccount_money());
}
public void account_in(){
if (!status())return;
System.out.println("请输入金额:");
Scanner put_in=new Scanner(System.in);
double money = put_in.nextDouble();
if (money<0){
System.out.println("金额不可以是负数");
return;
}
total.get(flag).setAccount_money(total.get(flag).getAccount_money()+money);
System.out.println("已经存入"+money+"元\n现在账户中存有"+total.get(flag).getAccount_money()+"元");
}
public void account_delete(){
if (!status())return;
System.out.println("你确定要注销当前账户"+total.get(flag).getAccount_name()+"吗");
System.out.println("继续删除 Y/N");
Scanner put_in=new Scanner(System.in);
String choose=put_in.next();
if (choose.equals("Y")){
total.remove(flag);
}else return;
}
public void account_out(){
if (!status())return;
System.out.println("您的账户中有"+total.get(flag).getAccount_money()+"元");
System.out.println("请输入取出金额:");
Scanner put_in=new Scanner(System.in);
double money = put_in.nextDouble();
if (money<0){
System.out.println("金额不可以是负数");
return;
}
if (total.get(flag).getAccount_money()-money<0){
System.out.println("没钱你取牛魔酬宾");
return;
}
total.get(flag).setAccount_money(total.get(flag).getAccount_money()-money);
System.out.println("已经取出"+money+"元\n现在账户中存有"+total.get(flag).getAccount_money()+"元");
}
public boolean status(){
if (flag==-1){
System.out.println("您还没有登录!");
return false;
}
return true;
}

}

account

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.example;

public class account {
private String account_name;
private String account_secret;
private double account_money;


public account(String account_name, String account_secret, double account_money) {
this.account_name = account_name;
this.account_secret = account_secret;
this.account_money = account_money;
}

public String getAccount_name() {
return account_name;
}

public void setAccount_name(String account_name) {
this.account_name = account_name;
}

public String getAccount_secret() {
return account_secret;
}

public void setAccount_secret(String account_secret) {
this.account_secret = account_secret;
}

public double getAccount_money() {
return account_money;
}

public void setAccount_money(double account_money) {
this.account_money = account_money;
}
}

java确实写开发很方便,拿c写我还真不知道怎么搞