2022/09/29 22:25 完成第七次课作业 银行系统
This commit is contained in:
parent
df6bc60349
commit
e17519f1c1
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -5,6 +5,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/Week2/Week2.iml" filepath="$PROJECT_DIR$/Week2/Week2.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Week3/Week3.iml" filepath="$PROJECT_DIR$/Week3/Week3.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Week4/Week4.iml" filepath="$PROJECT_DIR$/Week4/Week4.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Week5/Week5.iml" filepath="$PROJECT_DIR$/Week5/Week5.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/java_class.iml" filepath="$PROJECT_DIR$/java_class.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/week1/week1.iml" filepath="$PROJECT_DIR$/week1/week1.iml" />
|
||||
</modules>
|
||||
|
11
Week5/Week5.iml
Normal file
11
Week5/Week5.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
34
Week5/src/Administrator.java
Normal file
34
Week5/src/Administrator.java
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 8:54
|
||||
*/
|
||||
public class Administrator extends Employee{
|
||||
private Double bonus;
|
||||
|
||||
public Administrator(String id, String name, String department, Double baseSalary, Double bonus) {
|
||||
super(id, name, department, baseSalary);
|
||||
this.bonus = bonus;
|
||||
}
|
||||
|
||||
public Double getBonus() {
|
||||
return bonus;
|
||||
}
|
||||
|
||||
public void setBonus(Double bonus) {
|
||||
this.bonus = bonus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSalary() {
|
||||
super.updateSalary();
|
||||
super.setBaseSalary(super.getBaseSalary()+this.bonus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Administrator{" +
|
||||
"bonus=" + bonus +
|
||||
"," + super.toString() +
|
||||
'}';
|
||||
}
|
||||
}
|
74
Week5/src/Employee.java
Normal file
74
Week5/src/Employee.java
Normal file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 8:51
|
||||
*/
|
||||
public class Employee {
|
||||
private String id;
|
||||
private String name;
|
||||
private String department;
|
||||
private Double baseSalary;
|
||||
|
||||
public Employee() {
|
||||
id = "00000";
|
||||
name="未知";
|
||||
department="销售";
|
||||
baseSalary=1000.0;
|
||||
}
|
||||
|
||||
public Employee(String id, String name, String department, Double baseSalary) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.department = department;
|
||||
this.baseSalary = baseSalary;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public Double getBaseSalary() {
|
||||
return baseSalary;
|
||||
}
|
||||
|
||||
public void setBaseSalary(Double baseSalary) {
|
||||
this.baseSalary = baseSalary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Employee{" +
|
||||
"id='" + id + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", department='" + department + '\'' +
|
||||
", baseSalary=" + baseSalary +
|
||||
'}';
|
||||
}
|
||||
|
||||
public void displayEmployee(){
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
public void updateSalary(){
|
||||
this.baseSalary = this.baseSalary*1.0725;
|
||||
}
|
||||
}
|
37
Week5/src/SalesPerson.java
Normal file
37
Week5/src/SalesPerson.java
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:05
|
||||
*/
|
||||
public class SalesPerson extends Employee{
|
||||
private Double yearlySales;
|
||||
|
||||
public SalesPerson() {
|
||||
}
|
||||
|
||||
public SalesPerson(String id, String name, String department, Double baseSalary, Double yearlySales) {
|
||||
super(id, name, department, baseSalary);
|
||||
this.yearlySales = yearlySales;
|
||||
}
|
||||
|
||||
public Double getYearlySales() {
|
||||
return yearlySales;
|
||||
}
|
||||
|
||||
public void setYearlySales(Double yearlySales) {
|
||||
this.yearlySales = yearlySales;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSalary() {
|
||||
super.updateSalary();
|
||||
super.setBaseSalary(super.getBaseSalary()+this.yearlySales*0.1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SalesPerson{" +
|
||||
"yearlySales=" + yearlySales +
|
||||
"," + super.toString() +
|
||||
'}';
|
||||
}
|
||||
}
|
19
Week5/src/TestDriver.java
Normal file
19
Week5/src/TestDriver.java
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:08
|
||||
*/
|
||||
public class TestDriver {
|
||||
public static void main(String[] args) {
|
||||
Administrator administrator = new Administrator("001", "Tom", "董事会", 4000.0, 2000.0);
|
||||
SalesPerson salesPerson = new SalesPerson("002", "Lily", "销售", 5000.0, 20000.0);
|
||||
|
||||
System.out.println(administrator);
|
||||
System.out.println(salesPerson);
|
||||
|
||||
administrator.updateSalary();
|
||||
System.out.println(administrator.getBaseSalary());
|
||||
|
||||
salesPerson.updateSalary();
|
||||
System.out.println(salesPerson.getBaseSalary());
|
||||
}
|
||||
}
|
36
Week5/src/bank/BankAccount.java
Normal file
36
Week5/src/bank/BankAccount.java
Normal file
@ -0,0 +1,36 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:37
|
||||
*/
|
||||
public class BankAccount {
|
||||
private String accountNum;
|
||||
private Double balance;
|
||||
|
||||
public BankAccount(String accountNum, Double balance) {
|
||||
this.accountNum = accountNum;
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
public String getAccountNum() {
|
||||
return accountNum;
|
||||
}
|
||||
|
||||
public void setAccountNum(String accountNum) {
|
||||
this.accountNum = accountNum;
|
||||
}
|
||||
|
||||
public Double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public void setBalance(Double balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "卡号:" + accountNum + ",余额:" + balance;
|
||||
}
|
||||
}
|
27
Week5/src/bank/CheckingAccount.java
Normal file
27
Week5/src/bank/CheckingAccount.java
Normal file
@ -0,0 +1,27 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:39
|
||||
*/
|
||||
public class CheckingAccount extends BankAccount{
|
||||
private Double serviceCharge;
|
||||
|
||||
public CheckingAccount(String accountNum, Double balance, Double serviceCharge) {
|
||||
super(accountNum, balance);
|
||||
this.serviceCharge = serviceCharge;
|
||||
}
|
||||
|
||||
public Double getServiceCharge() {
|
||||
return serviceCharge;
|
||||
}
|
||||
|
||||
public void setServiceCharge(Double serviceCharge) {
|
||||
this.serviceCharge = serviceCharge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + ",服务费:" + this.serviceCharge;
|
||||
}
|
||||
}
|
61
Week5/src/bank/Customer.java
Normal file
61
Week5/src/bank/Customer.java
Normal file
@ -0,0 +1,61 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:36
|
||||
*/
|
||||
public class Customer {
|
||||
private String SSN;//身份证号
|
||||
private String name;
|
||||
private CheckingAccount checkingAccount;
|
||||
private SavingAccount savingAccount;
|
||||
|
||||
public Customer(String SSN, String name) {
|
||||
this.SSN = SSN;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSSN() {
|
||||
return SSN;
|
||||
}
|
||||
|
||||
public void setSSN(String SSN) {
|
||||
this.SSN = SSN;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CheckingAccount getCheckingAccount() {
|
||||
return checkingAccount;
|
||||
}
|
||||
|
||||
public void setCheckingAccount(CheckingAccount checkingAccount) {
|
||||
this.checkingAccount = checkingAccount;
|
||||
}
|
||||
|
||||
public SavingAccount getSavingAccount() {
|
||||
return savingAccount;
|
||||
}
|
||||
|
||||
public void setSavingAccount(SavingAccount savingAccount) {
|
||||
this.savingAccount = savingAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String info = "身份证号:" + this.SSN + ",姓名:" + this.name + "\n";
|
||||
if (savingAccount != null) {
|
||||
info += "存储卡信息:\n" + savingAccount + "\n";
|
||||
}
|
||||
if (checkingAccount != null) {
|
||||
info += "信用卡信息:\n" + checkingAccount + "\n";
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
295
Week5/src/bank/Driver.java
Normal file
295
Week5/src/bank/Driver.java
Normal file
@ -0,0 +1,295 @@
|
||||
package bank;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 10:02
|
||||
*/
|
||||
public class Driver {
|
||||
private static Customer customer = null;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
while (true) {
|
||||
int opt = menu();
|
||||
switch (opt) {
|
||||
case 1:
|
||||
create();
|
||||
break;
|
||||
case 2:
|
||||
save();
|
||||
break;
|
||||
case 3:
|
||||
withDraw();
|
||||
break;
|
||||
case 4:
|
||||
consume();
|
||||
break;
|
||||
case 5:
|
||||
repay();
|
||||
break;
|
||||
case 6:
|
||||
settle();
|
||||
break;
|
||||
case 7:
|
||||
balance();
|
||||
break;
|
||||
case 8:
|
||||
return;
|
||||
}
|
||||
System.out.println("按任意键继续...");
|
||||
System.in.read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查菜单选项输入合法性
|
||||
* @param low 选项下界
|
||||
* @param high 选项上界
|
||||
* @return 合法选项值
|
||||
*/
|
||||
public static int checkInput(int low, int high) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
if (scanner.hasNextInt()) {
|
||||
int opt = scanner.nextInt();
|
||||
if (opt >= low && opt <= high) {
|
||||
return opt;
|
||||
}
|
||||
System.out.println("输入超限,请输入" + low + "-" + high + "的数字");
|
||||
} else {
|
||||
System.out.println("输入数据类型错误,请输入" + low + "-" + high + "的数字");
|
||||
scanner.next();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int menu() {
|
||||
System.out.println("欢迎使用银行系统");
|
||||
System.out.println("1.开户");
|
||||
System.out.println("2.存款");
|
||||
System.out.println("3.取款");
|
||||
System.out.println("4.消费");
|
||||
System.out.println("5.还款");
|
||||
System.out.println("6.银行结算");
|
||||
System.out.println("7.查询余额");
|
||||
System.out.println("8.退出");
|
||||
System.out.print(">>>请选择(1-8):");
|
||||
int opt = -1;
|
||||
while (opt == -1) {
|
||||
opt = checkInput(1,8);
|
||||
}
|
||||
return opt;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项1 子菜单
|
||||
*/
|
||||
public static void create() {
|
||||
if (customer != null && customer.getCheckingAccount() != null && customer.getSavingAccount() != null){
|
||||
System.out.println("用户 " + customer.getName() + "(" + customer.getSSN() + ")" + " 信用卡、存储卡已全部开户!无需再次开户");
|
||||
return;
|
||||
}
|
||||
System.out.println("请选择开卡类型");
|
||||
System.out.println("1.信用卡");
|
||||
System.out.println("2.存储卡");
|
||||
System.out.println("3.返回");
|
||||
System.out.print(">>>请选择(1-3):");
|
||||
int opt = checkInput(1,3);
|
||||
switch (opt){
|
||||
case 1://信用卡开户
|
||||
createCheckingAccount();
|
||||
break;
|
||||
case 2://存储卡开户
|
||||
createSavingAccount();
|
||||
break;
|
||||
case 3://返回上一级
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项1 子菜单1 信用卡开户
|
||||
*/
|
||||
public static void createCheckingAccount() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
if (customer == null){
|
||||
System.out.print("请输入SSN:");
|
||||
String SSN = scanner.nextLine();
|
||||
System.out.print("请输入姓名:");
|
||||
String name = scanner.nextLine();
|
||||
customer = new Customer(SSN, name);
|
||||
}
|
||||
if (customer.getCheckingAccount() == null){
|
||||
System.out.print("请输入卡号:");
|
||||
String accountNum = scanner.nextLine();
|
||||
System.out.print("请输入服务费:");
|
||||
double serviceCharge = scanner.nextDouble();
|
||||
customer.setCheckingAccount(new CheckingAccount(accountNum, 0.0, serviceCharge));
|
||||
System.out.println("成功创建信用卡账户!");
|
||||
System.out.println(customer.getCheckingAccount());
|
||||
} else {
|
||||
System.out.println("信用卡已开户!无需创建");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项1 子菜单2 存储卡开户
|
||||
*/
|
||||
public static void createSavingAccount() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
if (customer == null){
|
||||
System.out.print("请输入SSN:");
|
||||
String SSN = scanner.nextLine();
|
||||
System.out.print("请输入姓名:");
|
||||
String name = scanner.nextLine();
|
||||
customer = new Customer(SSN, name);
|
||||
}
|
||||
if (customer.getSavingAccount() == null) {
|
||||
System.out.print("请输入卡号:");
|
||||
String accountNum = scanner.nextLine();
|
||||
System.out.print("请输入利率:");
|
||||
double interestRate = scanner.nextDouble();
|
||||
customer.setSavingAccount(new SavingAccount(accountNum, 0.0, interestRate));
|
||||
System.out.println("成功创建存储卡账户!");
|
||||
System.out.println(customer.getSavingAccount());
|
||||
} else {
|
||||
System.out.println("存储卡已开户!无需创建");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项2 存款
|
||||
*/
|
||||
public static void save(){
|
||||
if (customer != null) {
|
||||
SavingAccount savingAccount = customer.getSavingAccount();
|
||||
if (savingAccount != null) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入存款金额:");
|
||||
double balance = scanner.nextDouble();
|
||||
savingAccount.setBalance(savingAccount.getBalance()+balance);
|
||||
System.out.println("成功存款 " + balance + " 元");
|
||||
} else {
|
||||
System.out.println("存储卡未开户!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项3 取款
|
||||
*/
|
||||
public static void withDraw(){
|
||||
if (customer != null) {
|
||||
SavingAccount savingAccount = customer.getSavingAccount();
|
||||
if (savingAccount != null) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入取款金额:");
|
||||
double balance = scanner.nextDouble();
|
||||
Double accountBalance = savingAccount.getBalance();
|
||||
if (accountBalance > balance){
|
||||
savingAccount.setBalance(accountBalance - balance);
|
||||
System.out.println("成功取款 " + balance + " 元");
|
||||
} else System.out.println("取款失败,余额不足");
|
||||
} else {
|
||||
System.out.println("存储卡未开户!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项4 消费
|
||||
*/
|
||||
public static void consume(){
|
||||
if (customer != null) {
|
||||
CheckingAccount checkingAccount = customer.getCheckingAccount();
|
||||
if (checkingAccount != null) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入消费刷卡金额:");
|
||||
double consumeMoney = scanner.nextDouble();
|
||||
checkingAccount.setBalance(checkingAccount.getBalance() - consumeMoney);
|
||||
System.out.println("成功消费 " + consumeMoney + " 元");
|
||||
} else {
|
||||
System.out.println("信用卡未开户!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项5 还款
|
||||
*/
|
||||
public static void repay(){
|
||||
if (customer != null) {
|
||||
CheckingAccount checkingAccount = customer.getCheckingAccount();
|
||||
if (checkingAccount != null) {
|
||||
if (checkingAccount.getBalance() >= 0){
|
||||
System.out.println("无需还款!");
|
||||
return;
|
||||
}
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
System.out.print("请输入还款金额:");
|
||||
double repayMoney = scanner.nextDouble();
|
||||
checkingAccount.setBalance(checkingAccount.getBalance() + repayMoney);
|
||||
System.out.println("成功还款 " + repayMoney + " 元");
|
||||
} else {
|
||||
System.out.println("信用卡未开户!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项6 银行结算
|
||||
*/
|
||||
public static void settle(){
|
||||
if (customer != null) {
|
||||
SavingAccount savingAccount = customer.getSavingAccount();
|
||||
if (savingAccount != null) {
|
||||
Double oldBalance = savingAccount.getBalance();
|
||||
double interestBalance = oldBalance * savingAccount.getInterestRate();
|
||||
savingAccount.setBalance(oldBalance + interestBalance);
|
||||
System.out.println("存储卡 " + savingAccount.getAccountNum() + " 结算已完成");
|
||||
System.out.println("根据利率 " + savingAccount.getInterestRate() + " 获得利息 " + interestBalance + " 元");
|
||||
}
|
||||
|
||||
CheckingAccount checkingAccount = customer.getCheckingAccount();
|
||||
if (checkingAccount != null) {
|
||||
checkingAccount.setBalance(checkingAccount.getBalance() - checkingAccount.getServiceCharge());
|
||||
System.out.println("信用卡 " + checkingAccount.getAccountNum() + " 结算已完成");
|
||||
System.out.println("已扣除服务费 " + checkingAccount.getServiceCharge() + " 元");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主菜单选项7 查询信用卡余额,存储卡余额
|
||||
*/
|
||||
public static void balance(){
|
||||
if (customer != null) {
|
||||
CheckingAccount checkingAccount = customer.getCheckingAccount();
|
||||
if (checkingAccount != null) {
|
||||
System.out.println("信用卡 " + checkingAccount.getAccountNum() + " 余额:" + checkingAccount.getBalance() + " 元");
|
||||
} else {
|
||||
System.out.println("信用卡 未开户");
|
||||
}
|
||||
|
||||
SavingAccount savingAccount = customer.getSavingAccount();
|
||||
if (savingAccount != null) {
|
||||
System.out.println("存储卡 " + savingAccount.getAccountNum() + " 余额:" + savingAccount.getBalance() + " 元");
|
||||
} else {
|
||||
System.out.println("存储卡 未开户");
|
||||
}
|
||||
} else {
|
||||
System.out.println("用户未开户!请先执行功能1");
|
||||
}
|
||||
}
|
||||
}
|
27
Week5/src/bank/SavingAccount.java
Normal file
27
Week5/src/bank/SavingAccount.java
Normal file
@ -0,0 +1,27 @@
|
||||
package bank;
|
||||
|
||||
/**
|
||||
* @author : 张宇轩
|
||||
* @createTime : 2022/9/28 - 9:44
|
||||
*/
|
||||
public class SavingAccount extends BankAccount{
|
||||
private Double interestRate;
|
||||
|
||||
public SavingAccount(String accountNum, Double balance, Double interestRate) {
|
||||
super(accountNum, balance);
|
||||
this.interestRate = interestRate;
|
||||
}
|
||||
|
||||
public Double getInterestRate() {
|
||||
return interestRate;
|
||||
}
|
||||
|
||||
public void setInterestRate(Double interestRate) {
|
||||
this.interestRate = interestRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + ",利率:" + this.interestRate;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user