今天浏览BC-CN时,看到的一个题目,忘了在那一页看到的了,我在版主回复的程序的基础上完善了一下:
import java.io.*;
abstract class Bank
{
String Name;
int Accout;
int Money;
public abstract void setAccout(String n,int a,int m);
public abstract void getMoney(int m);
public abstract void saveMoney(int m);
public abstract void showMessage();
}
class Brass extends Bank
{
public Brass() {}
public Brass(String n,int a,int m)
{
Name=n;
Accout=a;
Money=m;
}
public void setAccout(String n,int a,int m)
{
Name=n;
Accout=a;
Money=m;
}
public void getMoney(int m)
{
if(m<=0)
System.out.println("getMoney SUM Error!");
else if(m>Money)
System.out.println("Money Not Enough!");
else{
Money-=m;
System.out.println("Money Leave:"+Money);
}
}
public void saveMoney(int m)
{
if(m<=0)
System.out.println("saveMoney SUM Error!");
else{
Money+=m;
System.out.println("Money Leave:"+Money);
}
}
public void showMessage()
{
System.out.println("Name:"+Name);
System.out.println("Accout:"+Accout);
System.out.println("Money Leave:"+Money);
}
}
public class TryBank
{
public static void main(String[] args) throws IOException
{
Brass brass;
String name,s1,s2,s3,s4;
int accout;
int money=0,i=0;
brass=new Brass();
System.out.println("************Menu************");
System.out.println("1.Create A New Accout.");
System.out.println("2.getMoney.");
System.out.println("3.saveMoney.");
System.out.println("4.showMessage.");
System.out.println("5.Exit.");
do{
System.out.print("Choose:");
try{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s1=in.readLine();
i=Integer.parseInt(s1);
}catch(IOException e){}
if(i==1)
{
System.out.println("----- Create A New Accout -----");
System.out.print("input Name:");
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
name=in1.readLine();
System.out.print("input Accout:");
BufferedReader in2=new BufferedReader(new InputStreamReader(System.in));
s1=in2.readLine();
accout=Integer.parseInt(s1);
System.out.print("input Money:");
BufferedReader in3=new BufferedReader(new InputStreamReader(System.in));
s2=in3.readLine();
money=Integer.parseInt(s2);
brass.setAccout(name,accout,money);
System.out.println("You have created a new accout!");
}
if(i==2)
{
System.out.println("------ Get Money ------");
System.out.print("Input getMoney Sum:");
BufferedReader in4=new BufferedReader(new InputStreamReader(System.in));
s3=in4.readLine();
money=Integer.parseInt(s3);
brass.getMoney(money);
}
if(i==3)
{
System.out.println("------ Save Money ------");
System.out.print("Input saveMoney Sum:");
BufferedReader in5=new BufferedReader(new InputStreamReader(System.in));
s4=in5.readLine();
money=Integer.parseInt(s4);
brass.saveMoney(money);
}
if(i==4)
{
System.out.println("----- Show Message -----");
brass.showMessage();
}
if(i==5)
{
System.out.println("I love JAVA.");
System.exit(0);
}
}while(i!=5);
}
}
写完这个程序后发现学到了java中字符界面的输入也切实是不简单~~~~~~
不知道谁可以把这个程序改写成GUI界面