Home > Back-end >  For help, how correlation map collections in another class
For help, how correlation map collections in another class

Time:09-16

The question now is//DBUtil. Main (args); This code doesn't delete
I deleted can't log on, but don't delete, if the program close to open, the original data, the data suggest the modified didn't
Excuse me what method can let the program to open is the last of the modified data
 package project; 

Public class User {
Private String cardID;//card number
Private String cardPwd;//password
Private String userName;//account name
Private String call;//phone number
Private double account;//balance
Public String getCardID () {
Return cardID;
}
Public void setCardID (String cardID) {
Enclosing cardID=cardID;
}
Public String getCardPwd () {
Return cardPwd;
}
Public void setCardPwd (String cardPwd) {
Enclosing cardPwd=cardPwd;
}
Public String getUserName () {
Return the userName.
}
Public void setUserName (String userName) {
this.userName=userName;
}
Public String getCall () {
Return the call;
}
Public void setCall {
(String call)This. Call=call;
}
Public double getAccount () {
Return the account;
}
Public void setAccount (double account) {
This. The account=account;
}

}

 
Package project.

import java.util.HashMap;

Public class DBUtil {
Public static HashMap The users=new HashMap (a);
The static User u1=new User ();
The static User u2=new User ();
Public static void main (String [] args) {
U1. SetCardID (" 123456 ");
U1. SetCardPwd (" 123456 ");
U1. SetUserName (" zhang ");
U1. SetCall (" 12345678911 ");
U1. SetAccount (100);

U2. SetCardID (" 1234 ");
U2. SetCardPwd (" 123 ");
U2. SetUserName (" li si ");
U2. SetCall (" 12345 ");
U2. SetAccount (1000);
Users. The put (u1. GetCardID (), u1);
Users. The put (u2. GetCardID (), u2);
}
Public static String show User (u) {
Return card number: "" + u.g etCardID () +" password: "+ u.g etCardPwd () +" user name: "+ u.g etUserName () +
"The phone:" + u.g etCall () + "balance:" + u.g etAccount ();
}
}

 
Package project.

import java.util.HashMap;
import java.util.Scanner;

Public class Bank {
The static Scanner in=new Scanner (System. In);
The static HashMap The map=DBUtil. Users;
The static User u;

Public static void main (String [] args) {
//DBUtil. Main (args);
Int num=3;
While (true) {
System. The out. Println (" please enter the card number ");
String cardID=in nextLine ();
System. The out. Print (" please enter the bank card password: ");
System.out.println();
String cardPwd=in nextLine ();
U=map. Get (cardID);
If (map. Either containsKey (cardID) & amp; & U.g etCardPwd (.) the equals (cardPwd)) {
System. Out.println (" welcome "+ u.g etUserName () +" Sir/madam! Your personal information is as follows ");
System. The out. Println (DBUtil. Show (u));
Choose (u);
break;
} else {
If (num & gt;=0 & amp; & Num & lt; {
=3)Num -=1;
System. Out.println (" password input error, to come in and go out, you still have "+ num +" chance!" );
}
If (num==0) {
System. Out.println (" you have input error three times, please try later." );
break;
}
}
}
}

Public static void choose User (u) {
While (true) {
Int num, temp=0;
System. The out. Println (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
System. Out.println (" input you want to choose operation!" );
System. The out. Println (" 1. Deposit ");
System. The out. Println (" 2. Balance ");
System. The out. Println (" 3. Quit ");
System. The out. Println (" 4. ");
System. The out. Println (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
Try {
Num=Integer. The parseInt (in nextLine (). The trim ());
} the catch (Exception e) {
System. Out.println (" can only enter an integer, please input again!" );
continue;
}
The switch (num) {
Case 1:
The deposit (u);
break;
Case 2:
The balance ();
break;
Case 3:
System. The out. Println (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
System. Out.println (" please the card away, take away your belongings!" );
Temp=1;
break;
Case 4:
Withdraw (u);
break;
Default:
System. Out.println (" you are the number of input error, please enter 1, any other key to continue!" );
Temp=Integer. The parseInt (in nextLine (). The trim ());
break;
}
If (temp==1) {
break;
}
}

}

Public static User deposit User (u) {//deposit
While (true) {
Double money=0, temp=0;
System. Out.println (u.g etUserName () + "Sir/madam your account balance for"
+ u.g etAccount () + "yuan!" );
System. The out. Println (" please input the you want to deposit amount: ");
Try {
Money=Integer. The parseInt (in nextLine (). The trim ());
} the catch (Exception e) {
System. The out. Println (" you input is wrong, please input again ");
continue;
}
If (money & gt;=0) {
Temp=money + u.g etAccount ();
U.s etAccount (temp);
}
If (money & lt; 0 {
System. Out.println (" the amount of input error, you going to quit!" );
The return of u;
}
}

}

Public static void the balance () {//balance
System. Out.println (u.g etUserName () + "Sir/madam your account balance for"
+ u.g etAccount () + "yuan!" );
}

Public static User withdraw User (u) {//withdrawals
While (true) {
Double money=0, temp=0, account=0;
Account=u.g etAccount ();
If (the account & gt; 0 {
System. Out.println (u.g etUserName () + "Sir/madam your account balance for"
+ u.g etAccount () + "yuan!" );
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related