Java——demo之仿ATM操作

java.util.Scanner類,這是一個用于掃描輸入文本的新的實用程序。其中nextInt()獲取String型,而next()獲取int、double型。

這是一個仿ATM的小程序。

實現條件 1.登陸界面,2.三次登陸機會,登陸成功進入登陸菜單,3,進入菜單進行選擇,實現 1,查詢,2,存款,3,取款,4,修改密碼,5退出,再位選擇退出時可一直重復操作。

import java.util.Scanner;
public class TestATM{public static void main(String[] args) {String user = "admin";String password ="123456";double  money = 10000;Scanner sc = new Scanner(System.in);welcome();boolean b = login(user,password);/*login successful come to the menu*/while(b==true){/System.out.println("login successful !");System.out.println("Now You In The Menu And Select Any Operation.");System.out.println("***1.Check the Balance***"+"\n"+ "***2.Withdrawing Money***"+"\n"+ "***3.Deposit Money***"+"\n"+ "***4.Change Password***"+"\n"+ "***5.exit***");while(true){int opt = sc.nextInt();switch (opt){case 1:checkMoney(money);retreate();break;case 2:money = withdrawMoney(money);System.out.println("operate successfully,you remaining sum is "+money);retreate();break;case 3:money = depositMoney(money);System.out.println("operate successfully,you remaining sum is "+money);retreate();break;case 4:password = changePassword(password);retreate();break;case 5:retreate();System.exit(0);default:break;}}}}public static  void welcome(){System.out.println("***********************************************");System.out.println("--------------------------Welcoming------------");System.out.println("--------------------------Version 1 ------------");System.out.println("-----------------------------------------------");}/*Three times to verify login*/public static boolean login(String us,String pw){System.out.println("***Only Thirds Tiems Please Carefully***");int k = 2;for(int i = 1; i<4;i++){	Scanner  sc = new Scanner(System.in);System.out.println("please input your username:");String user_name = sc.next();System.out.println("please input your password:");String user_pw = sc.next();if (us.equals(user_name)&&pw.equals(user_pw))return true;else{ if(k!=0){System.out.println("***Please Again Input Your Name And Password"+" "+"Only"+" "+k-- +" "+"Times***");}elseSystem.out.println("You Have No Time,Please Contact Our Staff Now.");continue;}}return false;}/*check money*/public static void checkMoney(double money){System.out.println("Your Balance is"+" "+money+" RMB ");}public static double withdrawMoney(double money1){Scanner sc =new Scanner(System.in);System.out.println("please input you want to withdraw money ");double wm  = sc.nextInt();money1 = money1 - wm;return money1;}public static double depositMoney(double money2){Scanner sc =new Scanner(System.in);System.out.println("please input you want to set money ");double sm = sc.nextInt();money2 = money2 + sm;return money2;}public static String changePassword(String old_password){System.out.println("please input your old ps");Scanner sc = new Scanner(System.in);String pd = sc.next();if(pd.equals(old_password)){	System.out.println("please input your new pw ");String pw1 = sc.next();System.out.println("please again input your new pw");String pw2 = sc.next();if (pw1.equals(pw2)) {System.out.println("chage password is successful.");return pw1;}else{System.out.println("The two passwords differ.");return pd;}}else{System.out.println("input old password is failed try again.");return old_password;}}public static void retreate(){System.out.println("Continue  OR Not Operation"+"(y/n)");Scanner sc = new Scanner(System.in);String cn = sc.next();if (cn.equals("y")) {return ;}else if (cn.equals("n")) {System.out.println("Exit  successful!1");System.exit(0);}else {while (true) {System.out.println("input is failed again?(y/n))");String temp = sc.next();if (temp.equals("y")) {return;} else if (temp.equals("n")) {System.out.println("Exit  successful!2");System.exit(0);}}}}
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274065.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274065.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274065.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

dpi 、 dip 、分辨率、屏幕尺寸、px、density 關系以及換算

本文轉自&#xff1a;http://www.cnblogs.com/yaozhongxiao/archive/2014/07/14/3842908.html 一、基本概念 dip &#xff1a; Density independent pixels &#xff0c;設備無關像素。 dp &#xff1a;就是dip px &#xff1a; 像素 dpi &#xf…

Ninject使用demo

public class HomeController : Controller{public ActionResult Index(){ //核心對象IKernel ninjectKernel new StandardKernel();ninjectKernel.Bind<IValueCaculator>().To<LinqValueCalcalator>(); //方案1&#xff1a;獲取接口實例IV…

Java 集合中關于Iterator 和ListIterator的詳解

1.Iterator Iterator的定義如下&#xff1a;public interface Iterator<E> {}Iterator是一個接口&#xff0c;它是集合的迭代器。集合可以通過Iterator去遍歷集合中的元素。Iterator提供的API接口如下&#xff1a;forEachRemaining(Consumer<? super E> action)&a…

使用xrandr和cvt命令添加自定義的分辨率模式

可以使用xrandr -q命令查看當前支持的分辨率模式: 如果過沒有你想要的分辨率模式,則需要自己創建新的分辨率模式,例如,我想要創建800x750的分辨率模式,步驟如下: 1.使用cvt命令創建新的分辨率: 2.使用xrandr –newmode modeline信息(CVT命令產生的結果)創建新的mode: $xra…

Java List集合

我們先看一下jdk1.9對其的描述&#xff1a;什么是List&#xff0c;也就是一個有序集合(序列)。1.List接口 List集合代表一個有序集合&#xff0c;集合中每個元素都有其對應的順序索引。List集合允許使用重復元素&#xff0c;可以通過索引來訪問指定位置的集合元素。 List接口繼…

winform錯誤提示 :窗口類名無效(Window class name is not valid)

winfrom 程序在 xp 操作系統上報錯提示 窗口類名無效(Window class name is not valid) 解決方法 注釋 Program類 里 這句 Application.EnableVisualStyles(); 解決轉載于:https://www.cnblogs.com/z_lb/p/3288850.html

如何在linux下通過ssh運行X圖形軟件

服務器端&#xff1a;編輯/etc/ssh/sshd_config中的以下內容 啟用AllowTcpForwarding 啟用X11Forwarding 將X11DisplayOffset設定為10. 啟用X11UseLocalhost 客戶機端&#xff1a;編輯/etc/ssh/ssh_config中的以下內容 啟用X11Forwarding 連接時ssh -X或者ssh -Y就可以了…

Java Set集合

Set接口什么是Set&#xff0c;就是不包含重復元素的集合。Set是一種不包括重復元素的Collection。它維持它自己的內部排序&#xff0c;所以隨機訪問沒有任何意義。與List一樣&#xff0c;它同樣允許null的存在但是僅有一個。由于Set接口的特殊性&#xff0c;所有傳入Set集合中的…

linux下制作win7安裝U盤

轉自:http://blog.csdn.net/pipisorry/article/details/41369821 http://blog.csdn.net/pipisorry/article/details/41369821 已裝Linux&#xff0c;再用U盤安裝win7(網絡安裝應該也可以)&#xff0c; 先要在linux里面制作一個win7安裝U盤&#xff08;windows下用ultraiso制…

Java Map集合

Map集合&#xff1a;Map接口Map與List、Set接口不同&#xff0c;它是由一系列鍵值對組成的集合&#xff0c;提供了key到Value的映射。同時它也沒有繼承Collection。在Map中它保證了key與value之間的一一對應關系。也就是說一個key對應一個value&#xff0c;所以它不能存在相同的…

gsettings命令使用簡介

1.gsettings創建項 應用程序可以使用gsettings來保存配置信息&#xff0c;可以通過代碼在程序中進行設置、修改gsettings的已有的項&#xff0c;但是不能通過程序代碼創建新的gsettings項&#xff0c;gsettings的項的在一個叫做schema的規范文件中創建&#xff0c;schema文檔其…

Collection 和 Collections區別

Collection 和 Collections區別&#xff08;1&#xff09;java.util.Collection 是一個集合接口&#xff08;集合類的一個頂級接口&#xff09;。它提供了對集合對象進行基本操作的通用接口方法。Collection接口在Java 類庫中有很多具體的實現。Collection接口的意義是為各種具…

Http狀態碼完整說明

在網站建設的實際應用中&#xff0c;容易出現很多小小的失誤&#xff0c;就像mysql當初優化不到位&#xff0c;影響整體網站的瀏覽效果一樣&#xff0c;其實&#xff0c;網站的常規http狀態碼的表現也是一樣&#xff0c; 一些常見的狀態碼為&#xff1a; 200 - 服務器成功返回網…

運用xlib進行事件響應(X11 API)的小例子

轉自&#xff1a;http://blog.csdn.net/linuxheik/article/details/7659090 File: x11_test.cxx #include <X11/Xlib.h> 每一個Xlib 程序都必須包含這個頭文件 #include <stdio.h>1. int main(void) {2. Display *display XopenDisplay(NULL);首先打開與server …

Java 之HashSet、LinkedHashSet、TreeSet比較

4.HashSet、LinkedHashSet、TreeSet比較 Set接口Set不允許包含相同的元素&#xff0c;如果試圖把兩個相同元素加入同一個集合中&#xff0c;add方法返回false。Set判斷兩個對象相同不是使用運算符&#xff0c;而是根據equals方法。也就是說&#xff0c;只要兩個對象用equals方法…

jquery1.9學習筆記 之選擇器(基本元素四)

ID選擇器("#id") 描述&#xff1a; 選擇與給出ID屬性匹配的單元標簽。 對于ID選擇器&#xff0c;jquery使用JS的函數document.getElementById()&#xff0c;當一個標簽附加到ID選擇器上時&#xff0c;也是非常有效的。如h2#pageTitle&#xff0c;jquery會在識別元素標…

Java(ArrayList和LinkedList)、(HashTable與HashMap)、(HashMap、Hashtable、LinkedHashMap和TreeMap比較)

1.ArrayList和LinkedList &#xff08;1&#xff09;ArrayList是實現了基于動態數組的數據結構&#xff0c;LinkedList基于鏈表的數據結構。 &#xff08;2&#xff09;對于隨機訪問get和set&#xff0c;ArrayList絕對優于LinkedList&#xff0c;因為LinkedList要移動指針。 &a…

oracle 事務測試

此文章是根據官方改變 模擬帳戶轉賬流程1.JOHN帳戶扣除-DAVID帳戶增加-記錄日志&#xff0d;事務提交三個操作必須全部完成此事務才完成&#xff0c;否則失敗創建帳戶余額表自增字段自增序列&#xff1b;createsequencesaving_seqincrementby1startwith1maxvalue99999999999999…

apt-get 獲取源碼的方法

apt-get source gconf-editor –allow-unauthenticated 注&#xff1a;gconf-editor是一個包名&#xff0c;根據自己的需求相應更改即可

Java 集合之自動打包和解包以及泛型

自動打包與解包&#xff1a;泛型&#xff1a;上栗子&#xff1a; TestMap1.java: package com.zhj.www; import java.util.*;public class TestMap {public static void main(String[] args) {Map m1 new HashMap();Map m2 new TreeMap();//m1.put("one", new Inte…