已补充清晰图片
2017-04-26
import java.util.Scanner;
public class Account {
//私有化变量
private double balance;
//get方法
public double getBalance() {
return balance;
}
//set方法
public void setBalance(double balance) {
this.balance = balance;
}
public double deposit(int b){
this.balance=b+this.balance;
return this.balance;
}
public double withdraw(int w){
this.balance=this.balance-w;
return this.balance;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//实例化对象
Account account = new Account();
//对象初始化
account.balance=1000;//初始的余额,1000块
System.out.println("请输入存的钱数目:");
account.deposit(input.nextInt());
System.out.println("请输入取出钱的数目:");
account.withdraw(input.nextInt());
System.out.println("余额为:"+account.balance);
}
}
public void setBalance(double balance) {
this.balance = balance;
}
public double deposit(int b){
this.balance=b+this.balance;
return this.balance;
}
public double withdraw(int w){
this.balance=this.balance-w;
return this.balance;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Account account = new Account();
account.balance=1000;
System.out.println("请输入存的钱数目:");
account.deposit(input.nextInt());
System.out.println("请输入取出钱的数目:");
account.withdraw(input.nextInt());
System.out.println("余额为:"+account.balance);
}
}