package comgreatwallbusinesscontroller;
import javamathBigDecimal;
import javautilScanner;
import javautilregexMatcher;
import javautilregexPattern;
/
@author xysddjyt
@since 2020/6/16 15:06
/
public class BankTest {
public static void main(String[] args) {
Scanner scan = new Scanner(Systemin);
// 余额(单位:分)
Long BALANCE = 10000000L;
// 卡号
String card = "001";
// 密码
String password = "123456";
String inputCard = new String();
String inputPassword = new String();
String quit = new String();
while (true) {
Systemoutprintln("\n欢迎来到网上银行办理存取款业务!");
Systemoutprintln("请输入yhk号和yhk密码进行登录!");
while (true) {
Systemoutprint("请输入yhk号(按q退出): ");
inputCard = scannextLine();
quit = inputCard;
if (inputCardequals("q")) {
break;
}
if (!inputCardequals(card)) {
Systemoutprint("您输入yhk号不正确,请重新输入 ");
continue;
}
break;
}
if (quitequals("q")) {
continue;
}
while (true) {
Systemoutprint("请输入yhk密码(按q退出): ");
inputPassword = scannextLine();
quit = inputPassword;
if (inputPasswordequals("q")) {
break;
}
if (!inputPasswordequals(password)) {
Systemoutprint("您输入yhk密码不正确,请重新输入 ");
continue;
}
break;
}
if (quitequals("q")) {
continue;
}
Systemoutprint("登录成功,当前登录的账户名:" + inputCard);
String type = "4";
while (!typeequals("0")) {
Systemoutprint("\n您当前的余额为:" + money(BALANCE) + "元");
Systemoutprint("\n请选择 *** 作类型。(存款:1;取款:2 ;余额:3;退出:0)\n");
type = scannextLine();
switch (type) {
case "1": {
Systemoutprint("请输入您的存款金额(元):");
String chageNumber = scannextLine();
if (!isPositiveInteger(chageNumber)) {
Systemoutprint("请输入正确的存款金额!");
continue;
}
BALANCE = LongvalueOf(chageNumber) 100 + BALANCE;
continue;
}
case "2": {
Systemoutprint("请输入您的取款金额(元):");
String chageNumber = scannextLine();
if (!isPositiveInteger(chageNumber)) {
Systemoutprint("请输入正确取款金额!");
continue;
}
BALANCE = BALANCE - LongvalueOf(chageNumber) 100;
continue;
}
case "3": {
Systemoutprint("您当前的余额为:" + money(BALANCE) + "元\n");
continue;
}
default: {
continue;
}
}
}
}
}
private static boolean isMatch(String regex, String orginal) {
if (orginal == null || orginaltrim()equals("")) {
return false;
}
Pattern pattern = Patterncompile(regex);
Matcher isNum = patternmatcher(orginal);
return isNummatches();
}
// 判断数据是否为正整数
public static boolean isPositiveInteger(String orginal) {
return isMatch("^\\+{0,1}[1-9]\\d", orginal);
}
// 分转元,转换为bigDecimal在toString
public static String money(Long money) {
return BigDecimalvalueOf(money)divide(new BigDecimal(100))toString();
}
}
关键代码:
for(int i=100;i>0;i=i-5)
Systemoutprint(i+"");
流程图就是:开始-》进入循环-》判断是否满足循环条件-》满足,继续并且打印-》不满足,跳出循环。画成图就行了,建议用visio画图,比较专业
前端是用Javascript *** 作canvas绘出各个元素(因此一些老的浏览器,如IE6、7等,无法使用),这些元素都是预定义的(包括rectangle,teardrop,standardImage等等),因此在浏览器中可以任意缩放而不失真。
保存到后端的时候将整个画布和元素的属性定义用json(具体格式可以看pos文件或者看POST的内容)传到服务器(应该是java实现的),重新绘制成PNG(他们的PDF就是PNG转的,所以无法矢量缩放)提供用户下载
我有源代码:绝对可以通过,不过比较简单而已,对学生而言应该可以了吧,这是以前写的:
一下两个文件放在一个包里就行了
/
This class defines a class that contains some useful
attributions and some methods to set or get these attributions
/
import javaxswingJButton;
public class ExButton extends JButton
{
//if the button is a mine,the isMine will be true
private boolean isMine;
//to check if a button has been visited is useful
//when using the recursion in the Game class
private boolean isVisited;
//the row number of the button
int btnRowNumber;
//the column number of the button
int btnColumnNumber;
//the mines around a button
int minesAround=0;
public void setIndex(int btnRowNumber,int btnColumnNumber)
{
thisbtnRowNumber=btnRowNumber;
thisbtnColumnNumber=btnColumnNumber;
}
public int getRowNumber()
{
return thisbtnRowNumber;
}
public int getColumnNumber()
{
return thisbtnColumnNumber;
}
public void setVisited(boolean isVisited)
{
thisisVisited=isVisited;
}
public boolean getVisited()
{
return thisisVisited;
}
public void setMine(boolean isMine)
{
thisisMine=isMine;
}
public boolean getMine()
{
return thisisMine;
}
//the attribute of minesAround add one each
//time a mine is put down around the button
public void addMinesAround()
{
thisminesAround++;
}
public int getMinesAround()
{
return thisminesAround;
}
}
-------------------------------------------------
/
File Name: Gamejava
Author: Tian Wei Student Number: Email: xiangchensuiyue@163com
Assignment number: #4
Description: In this program ,a frame will be created which contains
ten "mines"When you click a button ,it will present the
number of mines around or a message of losing the game
(if the button is a mine)You can make a right click to
sign a dengerous button as wellWhen all the mines have
been signed ,a message box of winning the game will jump
to the screenAnd the the message of the time you used in
the gameMore over,you can click the button on the bottom
to restart the game
/
import javaxswing;
import javaawt;
import javaawtevent;
import javautil;
import javautilRandom;
import javautilTimer;
public class Game extends JFrame{
//define some menber variables
private long minute=0,second=0;//take down time used int the game
private ExButton[][] btn;//two-dimension array present the buttons
private JLabel label;
private JButton restart;//restart button
private int minesRemained;//remained mines that you have not signed
private boolean thisTry=true;
private JLabel timeUsed=new JLabel ();
private Random rand=new Random();
private final int ROWS,COLUMNS;
private final int MINES;
// the constuctor
public Game(int rows,int columns,int mines)
{
super("Find mines");
thisROWS=rows;
thisCOLUMNS=columns;
thisMINES=mines;
minesRemained=MINES;
Timer timer=new Timer();//Timer's object to timer the game
timerschedule(new MyTimer(), 0, 1000);//do the function every second
Container container=getContentPane();
containersetLayout(new BorderLayout());
//Jpanel in the Container
JPanel jpanel=new JPanel();
jpanelsetLayout(new GridLayout(ROWS,COLUMNS));
restart=new JButton("click me to restart the game");
JPanel jpanel2=new JPanel();
//Another JPanel in the Container
jpanel2setLayout(new FlowLayout());
jpanel2add(timeUsed);
jpanel2add(restart);
ButtonListener restartHandler=new ButtonListener();
restartaddActionListener(restartHandler);
containeradd(jpanel2,BorderLayoutSOUTH);
btn=new ExButton[ROWS+2][COLUMNS+2];
//initialize the buttons
for(int i=0;i<=ROWS+1;i++)
{
for(int j=0;j<=COLUMNS+1;j++)
{
btn[i][j]=new ExButton();
btn[i][j]addMouseListener(new MouseClickHandler());
btn[i][j]setIndex(i,j);
btn[i][j]setVisited(false);
}
}
for(int i=1;i<=ROWS;i++)
for(int j=1;j<=COLUMNS;j++)
jpaneladd(btn[i][j]);
containeradd(jpanel,BorderLayoutCENTER);
JPanel jpanel3=new JPanel ();
label=new JLabel();
labelsetText("Mines remaining "+MINES);
jpanel3add(label);
containeradd(jpanel3,BorderLayoutNORTH );
thisaddMines();
thisaddMinesAround();
}
//randomly put ten mines
private void addMines()
{
for(int i=1;i<=MINES;i++)
{
int raInt1=randnextInt(ROWS);
int raInt2=randnextInt(COLUMNS);
if((raInt1==0)||(raInt2==0)||btn[raInt1][raInt2]getMine())
i--;
else
btn[raInt1][raInt2]setMine(true);
}
}
//take down the mines around a button
private void addMinesAround()
{
for(int i=1;i<=ROWS;i++)
{
for(int j=1;j<=COLUMNS;j++)
{
if(btn[i][j]getMine())
{
btn[i][j-1]addMinesAround();
btn[i][j+1]addMinesAround();
btn[i-1][j-1]addMinesAround();
btn[i-1][j]addMinesAround();
btn[i-1][j+1]addMinesAround();
btn[i+1][j-1]addMinesAround();
btn[i+1][j]addMinesAround();
btn[i+1][j+1]addMinesAround();
}
}
}
}
//if a button clicked is a empty one,then use a recursion
//to find all the empty buttons around
private void checkEmpty(ExButton button)
{
buttonsetVisited(true);
int x=buttongetRowNumber();
int y=buttongetColumnNumber();
buttonsetBackground(Colorwhite);
if((buttongetMinesAround()==0)&&(x>=1)&&(x<=ROWS)
&&(y>=1)&&(y<=COLUMNS))
{
if(!btn[x][y-1]getVisited())
checkEmpty(btn[x][y-1]);
if(!btn[x][y+1]getVisited())
checkEmpty(btn[x][y+1]);
if(!btn[x-1][y]getVisited())
checkEmpty(btn[x-1][y]);
if(!btn[x+1][y]getVisited())
checkEmpty(btn[x+1][y]);
if(!btn[x-1][y-1]getVisited())
checkEmpty(btn[x-1][y-1]);
if(!btn[x-1][y+1]getVisited())
checkEmpty(btn[x-1][y+1]);
if(!btn[x+1][y-1]getVisited())
checkEmpty(btn[x+1][y-1]);
if(!btn[x+1][y+1]getVisited())
checkEmpty(btn[x+1][y+1]);
}
else if(buttongetMinesAround()>0)
buttonsetText(""+buttongetMinesAround());
}
//the main function
public static void main(String args[])
{
String rows,columns,mines;
int rowNumber,columnNumber,mineNumber;
rows=JOptionPaneshowInputDialog("Enter the rows of the game");
columns=JOptionPaneshowInputDialog("Enter the columns of the game");
mines=JOptionPaneshowInputDialog("Enter the mines of the game");
rowNumber=IntegerparseInt(rows);
columnNumber=IntegerparseInt(columns);
mineNumber=IntegerparseInt(mines);
Game frame=new Game(rowNumber,columnNumber,mineNumber);
framesetTitle("Find Mines");
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
framesetLocation(220, 80);
framesetSize(600, 600 );
framesetVisible(true);
}
//there are three inner class below
//The first inner class is used to do the mouse listener's
//functionWhen you click a button ,it will present the
//number of mines around or a message of losing the game
//(if the button is a mine)You can make a right click to
//sign a dengerous button as wellWhen ten mines have been
//signed,it will check whether all the signed ones are mines
private class MouseClickHandler extends MouseAdapter
{
public void mouseClicked(MouseEvent event)
{
//get the button that been clicked
ExButton eventButton=new ExButton();
eventButton=(ExButton)eventgetSource();
eventButtonsetVisited(true);
//when it is a right click
if(eventisMetaDown())
{
if(eventButtongetText()=="#")
{
minesRemained++;
eventButtonsetText("");
}
else
{
if((eventButtongetBackground()==Colorwhite)||
(eventButtongetText()!=""))
{
//do nothing
}
else
{
minesRemained--;
eventButtonsetText("#");
}
}
labelsetText("Mines remaining "+minesRemained);
//check if all the signed buttons are mines
if(minesRemained==0)
{
for(int i=1;i<=ROWS;i++)
for(int j=1;j<=COLUMNS;j++)
{
if(btn[i][j]getMine()&&btn[i][j]getText()!="#")
thisTry=false;
if(!btn[i][j]getMine()&&btn[i][j]getText()=="#")
thisTry=false;
}
if(thisTry)
{
//win the game
JOptionPaneshowMessageDialog(null, "You succeed" +
" in this experience!");
JOptionPaneshowMessageDialog(null, "Time used:"+
timeUsedgetText());
}
else//you have wrongly signed one or more mines
JOptionPaneshowMessageDialog(null, "You have wrongly " +
"signed one or more mines,please check it and go on!");
}
}
else if(eventisAltDown())
{
//do nothing
}
else
{//normally click(left click)
if(eventButtongetText()=="#")
{
//do nothing
}
else if(eventButtongetMine())
{
//lose the game
JOptionPaneshowMessageDialog(null, "What a pity!" +
"You failed!" );
//show all the mines to the loser
for(int i=1;i<=ROWS;i++)
for(int j=1;j<=COLUMNS;j++)
{
if(btn[i][j]getMine())
btn[i][j]setBackground(ColorBLACK);
}
JOptionPaneshowMessageDialog(null, "Time used: 0"+
minute+":"+second);
}
else
{
if(eventButtongetMinesAround()==0)
{
//call the function to find all the empty buttons around
checkEmpty(eventButton);
}
else
eventButtonsetText(""+eventButtongetMinesAround());
}
}
}
}
//The second class is to listen to the button which used to
//restart the gameIn this class,it will dispose the old frame
//and create a new one(Of course,the mines's position have
//been changed)
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
//what to dispose is the object of Game class
Gamethisdispose();
//the same code as in the main function
Game frame=new Game(ROWS,COLUMNS,MINES);
framesetTitle("Find Mines");
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
framesetSize(600, 600 );
//make sure the frame is at the center of the screen
framesetLocation(220, 80);
framesetVisible(true);
}
}
//The last class is the class that will be used in the
//Timer's object timerIt should inherit the class TimerTask
//It is the task that the Timer will do every second
private class MyTimer extends TimerTask
{
public void run()
{
second+=1;
minute+=second/60;
second=second%60;
//change the text of the time used in the game
timeUsedsetText("Time used 0"+minute+":"+second);
}
}
}//end of the class Game
switch好像不行,case后面要的是常量,
参考代码:
import javaio;
public class Demo{
public static void main(String []args){
try{
int score;
String inpt;
Systemoutprintln(" please input the score:");
BufferedReader br=new BufferedReader(new InputStreamReader(Systemin));
inpt=brreadLine();
score=IntegerparseInt(inpt);
if(100==score)
Systemoutprintln("father's promise:buy car");
else{
if(90<=score)
Systemoutprintln("mother's promise:buy computer");
else{
if(60<=score)
Systemoutprintln("mother's promise:buy phone");
else
Systemoutprintln("no gift");
}
}
}
catch(Exception e){
Systemoutprintln("invalid input!");
}
}
}
以上就是关于Java课程设计,模拟银行存取业务,按照这个流程图去做,其实最主要的是求画圈的部分怎么写和它的方法。全部的内容,包括:Java课程设计,模拟银行存取业务,按照这个流程图去做,其实最主要的是求画圈的部分怎么写和它的方法。、java如何使用循环输出:100.95.90.85......... 5 先画出流程图 在编程实现 用while循环编辑、ProcessOn画流程图网站,使用什么技术做的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)