亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Java實(shí)例項(xiàng)目零錢(qián)通的實(shí)現(xiàn)流程

 更新時(shí)間:2022年03月04日 16:21:07   作者:笑霸final  
本篇文章為你帶來(lái)Java的一個(gè)新手實(shí)戰(zhàn)項(xiàng)目,是一個(gè)零錢(qián)通系統(tǒng),項(xiàng)目來(lái)自于B站韓順平老師,非常適合新手入門(mén)練習(xí),感興趣的朋友快來(lái)看看吧

注意:本項(xiàng)目來(lái)自B站韓順平老師 點(diǎn)此跳轉(zhuǎn)

完整代碼請(qǐng)看這里:gitee

點(diǎn)擊這里 GitHub鏈接

如圖:

老韓思路:

(1)可以把收益入賬和消費(fèi),保存到數(shù)組中(但目前學(xué)到的數(shù)組是定長(zhǎng)的)

(2)可以使用對(duì)象

(3)可以使用String拼接

完成收益入賬,完成功能驅(qū)動(dòng)程序員增加新的變化的代碼

(1)要接收收益入賬的金額,并更新余額

(2)拼接好字符串

(3)找到時(shí)間如何輸出,并且修改其輸出格式

我用的字符串拼接

效果圖

**

一些說(shuō)明

**:創(chuàng)建一個(gè)包 com.project.money.oop

然后創(chuàng)建兩個(gè)類 SmallChangeSys和SmallChangeSysOOP

SmallChangeSys 用來(lái)寫(xiě)main方法代碼如下

package com.project.money.oop;

public class SmallChangeSys {
    public static void main(String[] args) {
        SmallChangeSysOOP p=new SmallChangeSysOOP();
        p.menu();
    }
}

SmallChangeSysOOP用來(lái)實(shí)現(xiàn)具體功能

代碼如下:

package com.project.money.oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SmallChangeSysOOP {
    private  double in_money=0;//當(dāng)前流動(dòng)的錢(qián)
    private double balance=0;//余額
    private String detailed="------------零錢(qián)通明細(xì)--------------";
    private Date date = null;
    //可以用于日期格式化的
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
public void menu(){};
//1 零錢(qián)通明細(xì)
 public void detailed_(){};
 //2 收益入賬"
 public void input(){};
 //3消費(fèi)
    public void output(){};

}

具體說(shuō)明各個(gè)方法的作用:

public void menu()方法

public void menu(){//菜單
        boolean loop=true;
        Scanner scanner = new Scanner(System.in);
        while(loop){//循環(huán)展示菜單
            System.out.println("\n============oop零錢(qián)通菜單==============");
            System.out.println("\t\t1 零錢(qián)通明細(xì)");
            System.out.println("\t\t2 收益入賬");
            System.out.println("\t\t3 消費(fèi)");
            System.out.println("\t\t4 退" + "\t" + "出");
            System.out.print("請(qǐng)選擇1-4:");int key= scanner.nextInt();//選擇;
            switch (key){
                case 1:detailed_();break;
                case 2:input();break;
                case 3:output();break;
                case 4:System.out.println("\t\t程序已經(jīng)退出");loop=false;break;
            }

        }
    }

void detailed_()方法

public void detailed_(){
        System.out.println(detailed);//直接輸出字符
    }

public void input()方法

public void input(){//收益入賬
        Scanner scanner = new Scanner(System.in);
        System.out.println("請(qǐng)輸入金額:");
        this.in_money=scanner.nextDouble();

        while(in_money<0){
            System.out.println("======輸入有誤======");
            System.out.println("是否重新輸入?Y(是)或 N(否) ");//可能點(diǎn)錯(cuò)了不是輸入
            String in=scanner.next();//是否重新輸入
            if(in.equals("n")||in.equals("N")){
                System.out.println("返回主頁(yè)面中....");
                /*****************************************/
                try {
                    Thread.sleep( 1000 );//暫停1秒提升用戶感受
                } catch (Exception e){}
                /*******************************************/
                return;//退出輸入
            }

                System.out.println("請(qǐng)輸入金額:");
                this.in_money=scanner.nextDouble();
        }
        this.balance+=this.in_money;
        String beizhu="";
        date = new Date();
        System.out.println("請(qǐng)輸入備注:");
        beizhu=scanner.next();
        this.detailed+="\n收益入帳\t+" + this.in_money + "\t" + sdf.format(date) +
                "\t余額:" + this.balance+ "  備注:" +beizhu;
    }

**

public void output()方法

**

 public void output(){
        System.out.println("請(qǐng)輸入金額:");
        Scanner scanner = new Scanner(System.in);
        in_money=scanner.nextDouble();
        if(balance<in_money){
            System.out.println("余額不足,請(qǐng)充值");
            return;
        }
        while(in_money<0){
            System.out.println("輸入錯(cuò)誤,請(qǐng)重輸");
            in_money=scanner.nextDouble();
            if(balance<in_money){
                System.out.println("余額不足,請(qǐng)充值");
                return;
            }
        }
        this.balance-=in_money;
        System.out.println("請(qǐng)輸入備注:");
        String beizhu=scanner.next();
        this.detailed+="\n余額支出\t-" + this.in_money + "\t" + sdf.format(date) +
                "\t余額:" + this.balance+ "  備注:" +beizhu;

    }

SmallChangeSysOOP完整代碼

package com.project.money.oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class SmallChangeSysOOP {
    private  double in_money=0;//當(dāng)前流動(dòng)的錢(qián)
    private double balance=0;//余額
    private String detailed="------------零錢(qián)通明細(xì)--------------";
    private Date date = null;
    //可以用于日期格式化的
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    public void menu(){//菜單
        boolean loop=true;
        Scanner scanner = new Scanner(System.in);
        while(loop){//循環(huán)展示菜單
            System.out.println("\n============oop零錢(qián)通菜單==============");
            System.out.println("\t\t1 零錢(qián)通明細(xì)");
            System.out.println("\t\t2 收益入賬");
            System.out.println("\t\t3 消費(fèi)");
            System.out.println("\t\t4 退" + "\t" + "出");
            System.out.print("請(qǐng)選擇1-4:");int key= scanner.nextInt();//選擇;
            switch (key){
                case 1:detailed_();break;
                case 2:input();break;
                case 3:output();break;
                case 4:System.out.println("\t\t程序已經(jīng)退出");loop=false;break;
            }

        }
    }
    //1 零錢(qián)通明細(xì)
    public void detailed_(){
        System.out.println(detailed);
    }
    //2 收益入賬"
    public void input(){//收益入賬
        Scanner scanner = new Scanner(System.in);
        System.out.println("請(qǐng)輸入金額:");
        this.in_money=scanner.nextDouble();

        while(in_money<0){
            System.out.println("======輸入有誤======");
            System.out.println("是否重新輸入?Y(是)或 N(否) ");//可能點(diǎn)錯(cuò)了不是輸入
            String in=scanner.next();//是否重新輸入
            if(in.equals("n")||in.equals("N")){
                System.out.println("返回主頁(yè)面中....");
                /*****************************************/
                try {
                    Thread.sleep( 1000 );//暫停1秒提升用戶感受
                } catch (Exception e){}
                /*******************************************/
                return;//退出輸入
            }

                System.out.println("請(qǐng)輸入金額:");
                this.in_money=scanner.nextDouble();
        }
        this.balance+=this.in_money;
        String beizhu="";
        date = new Date();
        System.out.println("請(qǐng)輸入備注:");
        beizhu=scanner.next();
        this.detailed+="\n收益入帳\t+" + this.in_money + "\t" + sdf.format(date) +
                "\t余額:" + this.balance+ "  備注:" +beizhu;
    }
    //3消費(fèi)
    public void output(){
        System.out.println("請(qǐng)輸入金額:");
        Scanner scanner = new Scanner(System.in);
        in_money=scanner.nextDouble();
        if(balance<in_money){
            System.out.println("余額不足,請(qǐng)充值");
            return;
        }
        while(in_money<0){
            System.out.println("輸入錯(cuò)誤,請(qǐng)重輸");
            in_money=scanner.nextDouble();
            if(balance<in_money){
                System.out.println("余額不足,請(qǐng)充值");
                return;
            }
        }
        this.balance-=in_money;
        System.out.println("請(qǐng)輸入備注:");
        String beizhu=scanner.next();
        this.detailed+="\n余額支出\t-" + this.in_money + "\t" + sdf.format(date) +
                "\t余額:" + this.balance+ "  備注:" +beizhu;

    }


}

一些圖片

到此這篇關(guān)于Java實(shí)例項(xiàng)目零錢(qián)通的實(shí)現(xiàn)流程的文章就介紹到這了,更多相關(guān)Java 零錢(qián)通內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 深入分析Java并發(fā)編程之CAS

    深入分析Java并發(fā)編程之CAS

    這篇文章主要介紹了Java并發(fā)編程之CAS的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)Java并發(fā)編程,感興趣的朋友可以了解下
    2020-08-08
  • 一段眼睛跟著鼠標(biāo)轉(zhuǎn)動(dòng)的跟蹤眼代碼

    一段眼睛跟著鼠標(biāo)轉(zhuǎn)動(dòng)的跟蹤眼代碼

    java實(shí)現(xiàn)的眼睛跟著鼠標(biāo)轉(zhuǎn)動(dòng)的跟蹤眼代碼
    2008-10-10
  • Springboot啟動(dòng)流程詳細(xì)分析

    Springboot啟動(dòng)流程詳細(xì)分析

    這篇文章主要介紹了SpringBoot啟動(dòng)過(guò)程的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-12-12
  • Java實(shí)現(xiàn)航空航班管理系統(tǒng)

    Java實(shí)現(xiàn)航空航班管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)航空航班管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • Java連接數(shù)據(jù)庫(kù)JDBC技術(shù)之prepareStatement的詳細(xì)介紹

    Java連接數(shù)據(jù)庫(kù)JDBC技術(shù)之prepareStatement的詳細(xì)介紹

    這篇文章主要介紹了Java連接數(shù)據(jù)庫(kù)JDBC技術(shù)之prepareStatement的詳細(xì)介紹,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • SpringBoot自定義對(duì)象參數(shù)實(shí)現(xiàn)自動(dòng)類型轉(zhuǎn)換與格式化

    SpringBoot自定義對(duì)象參數(shù)實(shí)現(xiàn)自動(dòng)類型轉(zhuǎn)換與格式化

    SpringBoot 通過(guò)自定義對(duì)象參數(shù),可以實(shí)現(xiàn)自動(dòng)類型轉(zhuǎn)換與格式化,并可以級(jí)聯(lián)封裝,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2022-09-09
  • Mac M1 Java 開(kāi)發(fā)環(huán)境配置詳解

    Mac M1 Java 開(kāi)發(fā)環(huán)境配置詳解

    這篇文章主要介紹了Mac M1 Java 開(kāi)發(fā)環(huán)境配置詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • Servlet實(shí)現(xiàn)簡(jiǎn)單的用戶登錄功能實(shí)例代碼

    Servlet實(shí)現(xiàn)簡(jiǎn)單的用戶登錄功能實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于利用Servlet實(shí)現(xiàn)簡(jiǎn)單的用戶登錄功能的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • Java數(shù)組擴(kuò)容實(shí)例代碼

    Java數(shù)組擴(kuò)容實(shí)例代碼

    這篇文章主要介紹了Java數(shù)組擴(kuò)容實(shí)例代碼,具有一定借鑒價(jià)值,需要的朋友可以參考下
    2017-11-11
  • Java編程簡(jiǎn)單應(yīng)用

    Java編程簡(jiǎn)單應(yīng)用

    本文主要介紹了三個(gè)簡(jiǎn)單Java小程序———1、HelloWorld(HelloWorld的來(lái)源);2、輸出個(gè)人信息3、輸出特殊圖案。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02

最新評(píng)論