Declare bank account class, member variables include account number, depositor name, account opening time, ID number, storage balance and other account information

package bank account;
import java.text.SimpleDateFormat; //Common date manipulation tool class
import java.util.Calendar; //Get a calendar using the default time zone and locale
import java.util.Date;
public class Account {
private String acountNumber ; //Account
private String customerName; //Name
private String acctOpenTime; //Account opening time
private String customerIdNum; //ID number
private double balance; //Balance
public String getAcount() //Withdrawal
{
    return acount;
}
public void setAcount(String a) //Deposit
{
acount = a;
}
public String getName() //Enter name
{
   return name;
}
public void setName(String n) //Store name
{
name = n;
}
public String getTime() // input time
{
return time;
}
public void setTime(String t) // storage time
{
time = t;
}
public String getId() { // input ID number
return id;
}
public void setId(String ID) //Store ID number
{
id = ID;
}
public double getNum() //Enter account number
{
return num;
}
public void setNum(double m) //Store account number
{
num = m;
}
public void cunkuan(double m) //declare deposit
{
num=num+m;
}

//Withdrawal method
public void qukuan(double m){
if(m>num){
System.out.println("Insufficient balance, cannot withdraw money");
}else{
num=num-m;
}
}
//Display account opening time method
public String kaiHuTime(){
Date currDate=Calendar.getInstance().getTime();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
this.time=sdf.format(currDate);
return time;
}
//The method of getting the amount on the account
public double GetAcountNum()

{
 return num;
}
}

// main function

package bank account;
import java.util.Scanner;//input source program
public class Zhuhanshu {

public static void main(String[] args) 

{
   Account bank=new Account();
   bank.setAcount("6217 0044 0001 1236 455");
   bank.setId("012345678");
bank.setName("by");
bank.setNum(500000);
Scanner sc= new Scanner(System.in);
System.out.println("Please enter your account number");
String acount=sc.nextLine();
System.out.println("Please enter your password");
String pwd =sc.nextLine();
if(pwd.equals("232323")&& acount.equals(bank.getAcount())){//If the password is correct, the following operations can be performed
while(true){
System.out.println( "The current amount of your account is: "+bank.getNum()+"\nPlease enter the following operation: ");
System.out.println("1: Deposit");
System.out.println("2: Withdraw ");
System.out.println("3: Display account opening time");
System.out.println("4: Get the amount of the account");
System.out.println("5: Exit the current account");
Scanner scan=new Scanner(System.in);//There may be influence between the same variable sc, you can renew a
String option=scan.nextLine();

switch(option){//Select service
case "1" :
System.out.println("Please enter the money you want to deposit");
double num=scan.nextDouble();
bank.cunkuan(num);
System.out.println("The current amount is"+bank.getNum() );
break;
case "2":
System.out.println("Please enter the money you want to withdraw");
double num1=scan.nextDouble();
bank.qukuan(num1);
System.out.println("Currently The balance is "+bank.getNum());
break;
case "3":
System.out.println("The account opening time is: ");
System.out.println(bank.kaiHuTime());
break;

case "4 ":
System.out.println("The current account amount is: "+bank.getNum());
break;

case "5":
System.out.println("Exit the system");
System.exit(0);
break;
default : System.out.println("Sorry, your input is wrong");
break;
}

}
}

else

{
  System.out.println("The password or account is incorrect, please re-enter");

}

}
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325220420&siteId=291194637