Home > Back-end >  Small programs help you a great god, the bank ATM. There are two wrong, don't know how to chang
Small programs help you a great god, the bank ATM. There are two wrong, don't know how to chang

Time:10-01

import java.util.Scanner;
Public class different machine automatically {
Public static void main (String [] args) {
The Account a=new Account (id, password, 0);
The Customer y=new Customer (name1, a);
Java. Util. Scanner inf=new Java. Util. The Scanner System. (in);
System. The out. Println (" -- -- -- -- -- - welcome to use the self-service deposit and withdrawal System -- -- -- -- -- - ");
System. The out. Println (" please create your account ");
System. The out. Println (" please enter your name: ");
String name1=inf. NextLine ();
System. The out. Println (" please enter your bank account: ");
String id=inf. NextLine ();
System. The out. Println (" please enter your bank card password: ");
Double password=inf. NextDouble ();
System. Out.println (" account creation success!" );
System. The out. Println (" the current account balance is zero ");

}
Public static void operate () {
Scanner scanner1=new Scanner (System. In);
While (true) {
System. The out. Println (" please select a service project: ");
System. The out. Println (" 1. Deposit ");
System. The out. Println (" 2. ");
System. The out. Println (" 3. Query ");
System. The out. Println (" 4. Quit ");
Int n=scanner1. NextInt ();
The switch (n) {

Case 1:
System. The out. Println (" please enter the amount of deposit: ");
Double money.=scanner1 nextDouble ();
Y.g etAct (). The deposit (money);
break;
Case 2:
System. The out. Println (" please enter the amount withdrawn: ");
Double money1=scanner1. NextDouble ();
Y.g etAct (), withdraw (money);
break;
Case 3:
System. The out. Println (money);
Case 4:
return;
Default:
System. The out. Println (" input error, please input again, ");
break;
}
}
}
}
The class Customer {
Private String name1.
Private Account act;
The public Customer (String name1, Account act) {
Enclosing name1=name1;
This. Act=act;
}
Public void setName1 (String name1) {
Enclosing name1=name1;
}
Public String getName1 () {
Return name1.
}
Public void setAct Account (act) {
This. Act=act;
}
Public Account getAct () {
Return the act;
}
}
The class Account {
private String id;
Private double password;
Private double balance;
Public Account (String id, double password, double balance) {
this.id=id;
Enclosing the password=password;
Enclosing the balance=the balance;
}
Public void setId (String id) {
this.id=id;
}
Public String getId () {
Return the id;
}
Public void setPassword (double password) {
Enclosing the password=password;
}
Public double setPassword () {
Return the password;
}
Public void setBalance (double balance) {
Enclosing the balance=the balance;
}
Public double the getBalance () {
Return the balance.
}
Public void deposit (double money) {
Enclosing setBalance (enclosing the getBalance () + money);
System. The out. Println (" successful deposit: "+ money);
System. The out. Println (" current your balance as "+ money);
}
Public void withdraw (double money) {
If (money & gt; Enclosing the getBalance ()) {
System. The out. Println (" balance is not enough, take money failed ");
System. The out. Println (" current your balance as "+ money);
return;
}
Enclosing setBalance (enclosing the getBalance () - money);
Removed successfully System. Out. Println (" : "+ money);
}
}

CodePudding user response:

//note that the code format, sequence, statement first, then use the
 
import java.util.Scanner;

Public class different machine automatically {
Public static void main (String [] args) {
Java. Util. Scanner inf=new Java. Util. The Scanner System. (in);
System. The out. Println (" -- -- -- -- -- - welcome to use the self-service deposit and withdrawal System -- -- -- -- -- - ");
System. The out. Println (" please create your account ");
System. The out. Println (" please enter your name: ");
String name1=inf. NextLine ();
System. The out. Println (" please enter your bank account: ");
String id=inf. NextLine ();
System. The out. Println (" please enter your bank card password: ");
Double password=inf. NextDouble ();
System. Out.println (" account creation success!" );
System. The out. Println (" the current account balance is zero ");

The Account a=new Account (id, password, 0);
The Customer y=new Customer (name1, a);

Operate (y);

}
Public static void operate (the Customer) y {
Scanner scanner1=new Scanner (System. In);
While (true) {
System. The out. Println (" please select a service project: ");
System. The out. Println (" 1. Deposit ");
System. The out. Println (" 2. ");
System. The out. Println (" 3. Query ");
System. The out. Println (" 4. Quit ");
Int n=scanner1. NextInt ();
The switch (n) {
Case 1:
System. The out. Println (" please enter the amount of deposit: ");
Double money.=scanner1 nextDouble ();
Y.g etAct (). The deposit (money);
break;
Case 2:
System. The out. Println (" please enter the amount withdrawn: ");
Double money1=scanner1. NextDouble ();
Y.g etAct (), withdraw (money1);
break;
Case 3:
System. The out. Println (y.g etAct (). The getBalance ());
break;
Case 4:
return;
Default:
System. The out. Println (" input error, please input again, ");
break;
}
}
}
}
The class Customer {
Private String name1.
Private Account act;
The public Customer (String name1, Account act) {
Enclosing name1=name1;
This. Act=act;
}
Public void setName1 (String name1) {
Enclosing name1=name1;
}
Public String getName1 () {
Return name1.
}
Public void setAct Account (act) {
This. Act=act;
}
Public Account getAct () {
Return the act;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related