Home > Back-end >  For bosses to solve!
For bosses to solve!

Time:10-10

1, create Account kind Account, the following content
(1) the member variables: account id, real name name, account balance, the account opening Date dateCreated (Date)
(2) construction method, two parameters for id and real name initialise
(3) the member variables of get and set methods
Extract (4) method to withdraw, withdrawal from the account specified amount, the balance is insufficient, can't withdraw, prompt the user
(5) the method of deposit deposit and deposit to the account specified amount
(6) transfer method transfer Account (a), turn to the designated Account specified amount, the balance is insufficient, can't transfer, prompt the user (7) public String toString () method: return a String, the format for "Account: id \ t real name: the name \ t Account balance: the balance \ t Account opening time: dateCreated"
2, create CreditAccount credit accounts, inherit the Account class, the content is as follows:
(1) increase member variables: credit creditLimit (value is 20000, for example, this card can be overdraft 20000, line of credit that can be used for withdrawals/consumption, is not can be used to transfer)
(2) construction method, three parameters, as the id, real name, credit initialise
(3) the credit limit of the get and set methods
Extract (4) method to withdraw, withdrawal from the account specified amount exceeds the credit limit, can't withdraw, prompt the user
(5) the method of deposit deposit and deposit to the account specified amount
(6) transfer method transfer Account (a), turn to the designated Account specified amount, can only use the balance transfer, lack of balance of credit limit shall not transfer, prompt the user
: (7) public String toString () method returns a String, format according to the account deposit/balance state is divided into: if there is a deposit account, return: "account: id \ t real name: the name \ t account deposit: \ t amount available: * * * * * * \ t account opening time: dateCreated" if there is a balance accounts, return: "account: id \ t real name: the name \ t balance account: * * * \ t amount available: * * * \ t account opening time: dateCreated"
3, create a test class AccountTest, contains the main method, test requirements as follows
(1) test create credit accounts, deposits, withdrawals, transfer function
(2) the test credit account to the general account, transfer function of ordinary account to credit accounts,
(3) pay attention to the balance test and the shortage of credit,

CodePudding user response:

You do it can't be someone to help you, this is your homework

CodePudding user response:

 
Package com. Model;

import java.util.Date;

/* *
* Account class Account
* @ author Administrator
* the 2019-03-24
*/

Public class Account {
private String id;

private String name;

Private Integer balance;

Private Date dateCreated;

//constructor
Public Account (String id, String name) {
super();
this.id=id;
this.name=name;
System. The out. Println (" create account success ");
}

Public String getId () {
return id;
}

Public void setId (String id) {
this.id=id;
}

Public String getName () {
return name;
}

Public void elegantly-named setName (String name) {
this.name=name;
}

Public Integer the getBalance () {
Return the balance.
}

Public void setBalance (Integer balance) {
Enclosing the balance=the balance;
}

Public Date getDateCreated () {
Return dateCreated;
}

Public void setDateCreated (Date dateCreated) {
Enclosing dateCreated=dateCreated;
}

@ Override
Public String toString () {
Return "Account (id=" + id + ", name="+ name +", the balance="+ balance +", dateCreated="+ dateCreated +"] ".
}

//method (custom error code)
Public String withdraw (Integer Money) {
If (balance>=Money) {
//do something
Return "OK".
} else {
Return "001";
}
}

//deposit method
Public String deposit (Integer Money) {
//do something
return "";
}

//transfer method
Public String transfer (String id, Integer Money) {
//do something
return "";
}
}

CodePudding user response:

This how to write
  • Related